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