authentication_gss_continue.go 1.3 KB

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