ssl_request.go (1028B)
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 // Frontend identifies this message as sendable by a PostgreSQL frontend. 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 // Encode encodes src into dst. dst will include the 4 byte message length. 34 func (src *SSLRequest) Encode(dst []byte) []byte { 35 dst = pgio.AppendInt32(dst, 8) 36 dst = pgio.AppendInt32(dst, sslRequestNumber) 37 return dst 38 } 39 40 // MarshalJSON implements encoding/json.Marshaler. 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 }