signature.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // this file was auto-generated by internal/cmd/gentypes/main.go: DO NOT EDIT
  2. package jwa
  3. import (
  4. "github.com/pkg/errors"
  5. )
  6. // SignatureAlgorithm represents the various signature algorithms as described in https://tools.ietf.org/html/rfc7518#section-3.1
  7. type SignatureAlgorithm string
  8. // Supported values for SignatureAlgorithm
  9. const (
  10. ES256 SignatureAlgorithm = "ES256" // ECDSA using P-256 and SHA-256
  11. ES384 SignatureAlgorithm = "ES384" // ECDSA using P-384 and SHA-384
  12. ES512 SignatureAlgorithm = "ES512" // ECDSA using P-521 and SHA-512
  13. HS256 SignatureAlgorithm = "HS256" // HMAC using SHA-256
  14. HS384 SignatureAlgorithm = "HS384" // HMAC using SHA-384
  15. HS512 SignatureAlgorithm = "HS512" // HMAC using SHA-512
  16. NoSignature SignatureAlgorithm = "none"
  17. PS256 SignatureAlgorithm = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
  18. PS384 SignatureAlgorithm = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
  19. PS512 SignatureAlgorithm = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
  20. RS256 SignatureAlgorithm = "RS256" // RSASSA-PKCS-v1.5 using SHA-256
  21. RS384 SignatureAlgorithm = "RS384" // RSASSA-PKCS-v1.5 using SHA-384
  22. RS512 SignatureAlgorithm = "RS512" // RSASSA-PKCS-v1.5 using SHA-512
  23. )
  24. // Accept is used when conversion from values given by
  25. // outside sources (such as JSON payloads) is required
  26. func (v *SignatureAlgorithm) Accept(value interface{}) error {
  27. var tmp SignatureAlgorithm
  28. switch x := value.(type) {
  29. case string:
  30. tmp = SignatureAlgorithm(x)
  31. case SignatureAlgorithm:
  32. tmp = x
  33. default:
  34. return errors.Errorf(`invalid type for jwa.SignatureAlgorithm: %T`, value)
  35. }
  36. switch tmp {
  37. case ES256, ES384, ES512, HS256, HS384, HS512, NoSignature, PS256, PS384, PS512, RS256, RS384, RS512:
  38. default:
  39. return errors.Errorf(`invalid jwa.SignatureAlgorithm value`)
  40. }
  41. *v = tmp
  42. return nil
  43. }
  44. // String returns the string representation of a SignatureAlgorithm
  45. func (v SignatureAlgorithm) String() string {
  46. return string(v)
  47. }