...
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 const sslRequestNumber = 80877103
12
13 type SSLRequest struct {
14 }
15
16
17 func (*SSLRequest) Frontend() {}
18
19 func (dst *SSLRequest) Decode(src []byte) error {
20 if len(src) < 4 {
21 return errors.New("ssl request too short")
22 }
23
24 requestCode := binary.BigEndian.Uint32(src)
25
26 if requestCode != sslRequestNumber {
27 return errors.New("bad ssl request code")
28 }
29
30 return nil
31 }
32
33
34 func (src *SSLRequest) Encode(dst []byte) ([]byte, error) {
35 dst = pgio.AppendInt32(dst, 8)
36 dst = pgio.AppendInt32(dst, sslRequestNumber)
37 return dst, nil
38 }
39
40
41 func (src SSLRequest) MarshalJSON() ([]byte, error) {
42 return json.Marshal(struct {
43 Type string
44 ProtocolVersion uint32
45 Parameters map[string]string
46 }{
47 Type: "SSLRequest",
48 })
49 }
50
View as plain text