authentication_gss.go 1.1 KB

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