forked from coyim/coyim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mechanism.go
49 lines (39 loc) · 1.03 KB
/
mechanism.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
// Package scram implements the Salted Challenge Response Authentication Mechanism
// according to RFC 5802.
package scram
import "github.com/twstrike/coyim/sasl"
var (
// Mechanism is the SCRAM-SHA1 SASL mechanism
Mechanism sasl.Mechanism = &scramSHA1Mechanism{}
)
const (
// Name is the authentication type associated with the SASL mechanism
Name = "SCRAM-SHA-1"
)
// Register the SASL mechanism
func Register() {
sasl.RegisterMechanism(Name, Mechanism)
}
type scramSHA1Mechanism struct{}
func (m *scramSHA1Mechanism) NewClient() sasl.Session {
return &scramSHA1{
state: firstMessage{},
props: make(sasl.Properties),
}
}
type scramSHA1 struct {
state
props sasl.Properties
}
func (p *scramSHA1) SetProperty(prop sasl.Property, v string) error {
p.props[prop] = v
return nil
}
func (p *scramSHA1) Step(t sasl.Token) (ret sasl.Token, err error) {
pairs := sasl.ParseAttributeValuePairs(t)
p.state, ret, err = p.state.challenge(t, p.props, pairs)
return
}
func (p *scramSHA1) NeedsMore() bool {
return p.state != finished{}
}