source: code/trunk/vendor/github.com/emersion/go-sasl/anonymous.go@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 1.3 KB
RevLine 
[822]1package sasl
2
3// The ANONYMOUS mechanism name.
4const Anonymous = "ANONYMOUS"
5
6type anonymousClient struct {
7 Trace string
8}
9
10func (c *anonymousClient) Start() (mech string, ir []byte, err error) {
11 mech = Anonymous
12 ir = []byte(c.Trace)
13 return
14}
15
16func (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.
22func NewAnonymousClient(trace string) Client {
23 return &anonymousClient{trace}
24}
25
26// Get trace information from clients logging in anonymously.
27type AnonymousAuthenticator func(trace string) error
28
29type anonymousServer struct {
30 done bool
31 authenticate AnonymousAuthenticator
32}
33
34func (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.
54func NewAnonymousServer(authenticator AnonymousAuthenticator) Server {
55 return &anonymousServer{authenticate: authenticator}
56}
Note: See TracBrowser for help on using the repository browser.