-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal.go
62 lines (49 loc) · 1.55 KB
/
external.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package sasl
import "errors"
var (
errExternalAlreadyCompleted = errors.New("EXTERNAL authentication already completed")
errExternalNotSupported = errors.New("EXTERNAL has no supported QOP")
)
type externalClient struct {
username []byte
completed bool
}
// NewExternalClient creates a SASL External mechanism with optional authorization ID
func NewExternalClient(authorizationID []byte) (Client, error) {
if len(authorizationID) == 0 {
authorizationID = []byte{}
}
return &externalClient{
username: authorizationID,
}, nil
}
// EvaluateChallenge returns the EXTERNAL mechanism's initial response,
// which is the authorization id encoded in UTF-8. This is the optional
// information that is sent along with the SASL command
func (p *externalClient) EvaluateChallenge(challenge []byte) ([]byte, error) {
if p.completed {
return nil, errExternalAlreadyCompleted
}
p.completed = true
return p.username, nil
}
// Wrap wraps the outcoming buffer.
func (p *externalClient) Wrap(data []byte) ([]byte, error) {
return nil, errExternalNotSupported
}
// Unwrap unwraps the incoming buffer.
func (p *externalClient) Unwrap(data []byte) ([]byte, error) {
return nil, errExternalNotSupported
}
// IsComplete returns whether the mechanism is complete
func (p *externalClient) IsComplete() bool {
return p.completed
}
// Mechanism returns this mechanism's name
func (p *externalClient) Mechanism() string {
return EXTERNAL
}
// HasInitialResponse returns whether mechanism has an initial response.
func (p *externalClient) HasInitialResponse() bool {
return true
}