json: fix implementation of json Unmarshalers.
* AuthenticationMD5Password was wrong and is not needed * Bind was wrong * ErrorResponse is not needed * Minor improvements for reliability
This commit is contained in:
committed by
Jack Christensen
parent
ba924e5715
commit
9c2c389e06
@@ -2,7 +2,6 @@ package pgproto3
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgio"
|
||||
@@ -42,24 +41,3 @@ func (src *AuthenticationMD5Password) Encode(dst []byte) []byte {
|
||||
dst = append(dst, src.Salt[:]...)
|
||||
return dst
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements encoding/json.Unmarshaler.
|
||||
func (dst *AuthenticationMD5Password) UnmarshalJSON(data []byte) error {
|
||||
// Ignore null, like in the main JSON package.
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var msg struct {
|
||||
Salt string
|
||||
}
|
||||
if err := json.Unmarshal(data, &msg); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(msg.Salt) != 4 {
|
||||
return errors.New("invalid salt size")
|
||||
}
|
||||
|
||||
copy(dst.Salt[:], []byte(msg.Salt)[:4])
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user