package pgproto3
import (
)
type AuthenticationSASL struct {
AuthMechanisms []string
}
func (*AuthenticationSASL) () {}
func (*AuthenticationSASL) () {}
func ( *AuthenticationSASL) ( []byte) error {
if len() < 4 {
return errors.New("authentication message too short")
}
:= binary.BigEndian.Uint32()
if != AuthTypeSASL {
return errors.New("bad auth type")
}
.AuthMechanisms = .AuthMechanisms[:0]
:= [4:]
for len() > 1 {
:= bytes.IndexByte(, 0)
if == -1 {
return &invalidMessageFormatErr{messageType: "AuthenticationSASL", details: "unterminated string"}
}
.AuthMechanisms = append(.AuthMechanisms, string([:]))
= [+1:]
}
return nil
}
func ( *AuthenticationSASL) ( []byte) ([]byte, error) {
, := beginMessage(, 'R')
= pgio.AppendUint32(, AuthTypeSASL)
for , := range .AuthMechanisms {
= append(, []byte()...)
= append(, 0)
}
= append(, 0)
return finishMessage(, )
}
func ( AuthenticationSASL) () ([]byte, error) {
return json.Marshal(struct {
string
[]string
}{
: "AuthenticationSASL",
: .AuthMechanisms,
})
}