gtsocial-umbx

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

authentication_gss.go (1097B)


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