gtsocial-umbx

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

authentication_gss_continue.go (1302B)


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