aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/emersion/go-sasl/anonymous.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/emersion/go-sasl/anonymous.go')
-rw-r--r--vendor/github.com/emersion/go-sasl/anonymous.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/github.com/emersion/go-sasl/anonymous.go b/vendor/github.com/emersion/go-sasl/anonymous.go
new file mode 100644
index 0000000..8ccb817
--- /dev/null
+++ b/vendor/github.com/emersion/go-sasl/anonymous.go
@@ -0,0 +1,56 @@
+package sasl
+
+// The ANONYMOUS mechanism name.
+const Anonymous = "ANONYMOUS"
+
+type anonymousClient struct {
+ Trace string
+}
+
+func (c *anonymousClient) Start() (mech string, ir []byte, err error) {
+ mech = Anonymous
+ ir = []byte(c.Trace)
+ return
+}
+
+func (c *anonymousClient) Next(challenge []byte) (response []byte, err error) {
+ return nil, ErrUnexpectedServerChallenge
+}
+
+// A client implementation of the ANONYMOUS authentication mechanism, as
+// described in RFC 4505.
+func NewAnonymousClient(trace string) Client {
+ return &anonymousClient{trace}
+}
+
+// Get trace information from clients logging in anonymously.
+type AnonymousAuthenticator func(trace string) error
+
+type anonymousServer struct {
+ done bool
+ authenticate AnonymousAuthenticator
+}
+
+func (s *anonymousServer) Next(response []byte) (challenge []byte, done bool, err error) {
+ if s.done {
+ err = ErrUnexpectedClientResponse
+ return
+ }
+
+ // No initial response, send an empty challenge
+ if response == nil {
+ return []byte{}, false, nil
+ }
+
+ s.done = true
+
+ err = s.authenticate(string(response))
+ done = true
+ return
+}
+
+// A server implementation of the ANONYMOUS authentication mechanism, as
+// described in RFC 4505.
+func NewAnonymousServer(authenticator AnonymousAuthenticator) Server {
+ return &anonymousServer{authenticate: authenticator}
+}