gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

authentication_gss.go (1114B)


      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 type AuthenticationGSS struct{}
     12 
     13 func (a *AuthenticationGSS) Backend() {}
     14 
     15 func (a *AuthenticationGSS) AuthenticationResponse() {}
     16 
     17 func (a *AuthenticationGSS) Decode(src []byte) error {
     18 	if len(src) < 4 {
     19 		return errors.New("authentication message too short")
     20 	}
     21 
     22 	authType := binary.BigEndian.Uint32(src)
     23 
     24 	if authType != AuthTypeGSS {
     25 		return errors.New("bad auth type")
     26 	}
     27 	return nil
     28 }
     29 
     30 func (a *AuthenticationGSS) Encode(dst []byte) []byte {
     31 	dst = append(dst, 'R')
     32 	dst = pgio.AppendInt32(dst, 4)
     33 	dst = pgio.AppendUint32(dst, AuthTypeGSS)
     34 	return dst
     35 }
     36 
     37 func (a *AuthenticationGSS) MarshalJSON() ([]byte, error) {
     38 	return json.Marshal(struct {
     39 		Type string
     40 		Data []byte
     41 	}{
     42 		Type: "AuthenticationGSS",
     43 	})
     44 }
     45 
     46 func (a *AuthenticationGSS) UnmarshalJSON(data []byte) error {
     47 	// Ignore null, like in the main JSON package.
     48 	if string(data) == "null" {
     49 		return nil
     50 	}
     51 
     52 	var msg struct {
     53 		Type string
     54 	}
     55 	if err := json.Unmarshal(data, &msg); err != nil {
     56 		return err
     57 	}
     58 	return nil
     59 }