1 // Library for Simple Authentication and Security Layer (SASL) defined in RFC 4422.
2 package sasl
3 4 // Note:
5 // Most of this code was copied, with some modifications, from net/smtp. It
6 // would be better if Go provided a standard package (e.g. crypto/sasl) that
7 // could be shared by SMTP, IMAP, and other packages.
8 9 import (
10 "errors"
11 )
12 13 // Common SASL errors.
14 var (
15 ErrUnexpectedClientResponse = errors.New("sasl: unexpected client response")
16 ErrUnexpectedServerChallenge = errors.New("sasl: unexpected server challenge")
17 )
18 19 // Client interface to perform challenge-response authentication.
20 type Client interface {
21 // Begins SASL authentication with the server. It returns the
22 // authentication mechanism name and "initial response" data (if required by
23 // the selected mechanism). A non-nil error causes the client to abort the
24 // authentication attempt.
25 //
26 // A nil ir value is different from a zero-length value. The nil value
27 // indicates that the selected mechanism does not use an initial response,
28 // while a zero-length value indicates an empty initial response, which must
29 // be sent to the server.
30 Start() (mech string, ir []byte, err error)
31 32 // Continues challenge-response authentication. A non-nil error causes
33 // the client to abort the authentication attempt.
34 Next(challenge []byte) (response []byte, err error)
35 }
36 37 // Server interface to perform challenge-response authentication.
38 type Server interface {
39 // Begins or continues challenge-response authentication. If the client
40 // supplies an initial response, response is non-nil.
41 //
42 // If the authentication is finished, done is set to true. If the
43 // authentication has failed, an error is returned.
44 Next(response []byte) (challenge []byte, done bool, err error)
45 }
46