anonymous.go raw
1 package sasl
2
3 // The ANONYMOUS mechanism name.
4 const Anonymous = "ANONYMOUS"
5
6 type anonymousClient struct {
7 Trace string
8 }
9
10 func (c *anonymousClient) Start() (mech string, ir []byte, err error) {
11 mech = Anonymous
12 ir = []byte(c.Trace)
13 return
14 }
15
16 func (c *anonymousClient) Next(challenge []byte) (response []byte, err error) {
17 return nil, ErrUnexpectedServerChallenge
18 }
19
20 // A client implementation of the ANONYMOUS authentication mechanism, as
21 // described in RFC 4505.
22 func NewAnonymousClient(trace string) Client {
23 return &anonymousClient{trace}
24 }
25
26 // Get trace information from clients logging in anonymously.
27 type AnonymousAuthenticator func(trace string) error
28
29 type anonymousServer struct {
30 done bool
31 authenticate AnonymousAuthenticator
32 }
33
34 func (s *anonymousServer) Next(response []byte) (challenge []byte, done bool, err error) {
35 if s.done {
36 err = ErrUnexpectedClientResponse
37 return
38 }
39
40 // No initial response, send an empty challenge
41 if response == nil {
42 return []byte{}, false, nil
43 }
44
45 s.done = true
46
47 err = s.authenticate(string(response))
48 done = true
49 return
50 }
51
52 // A server implementation of the ANONYMOUS authentication mechanism, as
53 // described in RFC 4505.
54 func NewAnonymousServer(authenticator AnonymousAuthenticator) Server {
55 return &anonymousServer{authenticate: authenticator}
56 }
57