forked from coyim/coyim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sasl.go
72 lines (59 loc) · 2.25 KB
/
sasl.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
63
64
65
66
67
68
69
70
71
72
package data
import (
"encoding/xml"
"fmt"
)
// SaslMechanisms contains information about SASL mechanisms
// RFC 3920 C.4 SASL name space
//TODO RFC 6120 obsoletes RFC 3920
type SaslMechanisms struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
Mechanism []string `xml:"mechanism"`
}
type saslAuth struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl auth"`
Mechanism string `xml:"mechanism,attr"`
}
type saslChallenge string
type saslResponse string
// SaslAbort signifies a SASL abort
type SaslAbort struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl abort"`
}
// SaslSuccess signifies a SASL Success
type SaslSuccess struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl success"`
Content []byte `xml:",innerxml"`
}
// SaslFailure signifies a SASL Failure
type SaslFailure struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"`
Text string `xml:"text,omitempty"`
DefinedCondition Any `xml:",any"`
}
// Condition returns a SASL-related error condition
func (f SaslFailure) Condition() SASLErrorCondition {
return SASLErrorCondition(f.DefinedCondition.XMLName.Local)
}
func (f SaslFailure) String() string {
if f.Text != "" {
return fmt.Sprintf("%s: %q", f.Condition(), f.Text)
}
return string(f.Condition())
}
// SASLErrorCondition represents a defined SASL-related error conditions as defined in RFC 6120, section 6.5
type SASLErrorCondition string
// SASL error conditions as defined in RFC 6120, section 6.5
const (
SASLAborted SASLErrorCondition = "aborted"
SASLAccountDisabled = "account-disabled"
SASLCredentialsExpired = "credentials-expired"
SASLEncryptionRequired = "encryption-required"
SASLIncorrectEncoding = "incorrect-encoding"
SASLInvalidAuthzid = "invalid-authzid"
SASLInvalidMechanism = "invalid-mechanism"
SASLMalformedRequest = "malformed-request"
SASLMechanismTooWeak = "mechanism-too-weak"
SASLNotAuthorized = "not-authorized"
SASLTemporaryAuthFailure = "temporary-auth-failure"
)