...
1 package pgproto3
2
3 import (
4 "encoding/binary"
5 "encoding/json"
6 "errors"
7
8 "github.com/jackc/pgio"
9 )
10
11 type AuthenticationGSSContinue struct {
12 Data []byte
13 }
14
15 func (a *AuthenticationGSSContinue) Backend() {}
16
17 func (a *AuthenticationGSSContinue) AuthenticationResponse() {}
18
19 func (a *AuthenticationGSSContinue) Decode(src []byte) error {
20 if len(src) < 4 {
21 return errors.New("authentication message too short")
22 }
23
24 authType := binary.BigEndian.Uint32(src)
25
26 if authType != AuthTypeGSSCont {
27 return errors.New("bad auth type")
28 }
29
30 a.Data = src[4:]
31 return nil
32 }
33
34 func (a *AuthenticationGSSContinue) Encode(dst []byte) ([]byte, error) {
35 dst, sp := beginMessage(dst, 'R')
36 dst = pgio.AppendUint32(dst, AuthTypeGSSCont)
37 dst = append(dst, a.Data...)
38 return finishMessage(dst, sp)
39 }
40
41 func (a *AuthenticationGSSContinue) MarshalJSON() ([]byte, error) {
42 return json.Marshal(struct {
43 Type string
44 Data []byte
45 }{
46 Type: "AuthenticationGSSContinue",
47 Data: a.Data,
48 })
49 }
50
51 func (a *AuthenticationGSSContinue) UnmarshalJSON(data []byte) error {
52
53 if string(data) == "null" {
54 return nil
55 }
56
57 var msg struct {
58 Type string
59 Data []byte
60 }
61 if err := json.Unmarshal(data, &msg); err != nil {
62 return err
63 }
64
65 a.Data = msg.Data
66 return nil
67 }
68
View as plain text