package pgproto3
import (
)
type AuthenticationMD5Password struct {
Salt [4]byte
}
func (*AuthenticationMD5Password) () {}
func (*AuthenticationMD5Password) () {}
func ( *AuthenticationMD5Password) ( []byte) error {
if len() != 8 {
return errors.New("bad authentication message size")
}
:= binary.BigEndian.Uint32()
if != AuthTypeMD5Password {
return errors.New("bad auth type")
}
copy(.Salt[:], [4:8])
return nil
}
func ( *AuthenticationMD5Password) ( []byte) ([]byte, error) {
, := beginMessage(, 'R')
= pgio.AppendUint32(, AuthTypeMD5Password)
= append(, .Salt[:]...)
return finishMessage(, )
}
func ( AuthenticationMD5Password) () ([]byte, error) {
return json.Marshal(struct {
string
[4]byte
}{
: "AuthenticationMD5Password",
: .Salt,
})
}
func ( *AuthenticationMD5Password) ( []byte) error {
if string() == "null" {
return nil
}
var struct {
string
[4]byte
}
if := json.Unmarshal(, &); != nil {
return
}
.Salt = .
return nil
}