key_encryption.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // KeyEncryptionAlgorithm represents the various encryption algorithms as described in https://tools.ietf.org/html/rfc7518#section-4.1
  7. type KeyEncryptionAlgorithm string
  8. // Supported values for KeyEncryptionAlgorithm
  9. const (
  10. A128GCMKW KeyEncryptionAlgorithm = "A128GCMKW" // AES-GCM key wrap (128)
  11. A128KW KeyEncryptionAlgorithm = "A128KW" // AES key wrap (128)
  12. A192GCMKW KeyEncryptionAlgorithm = "A192GCMKW" // AES-GCM key wrap (192)
  13. A192KW KeyEncryptionAlgorithm = "A192KW" // AES key wrap (192)
  14. A256GCMKW KeyEncryptionAlgorithm = "A256GCMKW" // AES-GCM key wrap (256)
  15. A256KW KeyEncryptionAlgorithm = "A256KW" // AES key wrap (256)
  16. DIRECT KeyEncryptionAlgorithm = "dir" // Direct encryption
  17. ECDH_ES KeyEncryptionAlgorithm = "ECDH-ES" // ECDH-ES
  18. ECDH_ES_A128KW KeyEncryptionAlgorithm = "ECDH-ES+A128KW" // ECDH-ES + AES key wrap (128)
  19. ECDH_ES_A192KW KeyEncryptionAlgorithm = "ECDH-ES+A192KW" // ECDH-ES + AES key wrap (192)
  20. ECDH_ES_A256KW KeyEncryptionAlgorithm = "ECDH-ES+A256KW" // ECDH-ES + AES key wrap (256)
  21. PBES2_HS256_A128KW KeyEncryptionAlgorithm = "PBES2-HS256+A128KW" // PBES2 + HMAC-SHA256 + AES key wrap (128)
  22. PBES2_HS384_A192KW KeyEncryptionAlgorithm = "PBES2-HS384+A192KW" // PBES2 + HMAC-SHA384 + AES key wrap (192)
  23. PBES2_HS512_A256KW KeyEncryptionAlgorithm = "PBES2-HS512+A256KW" // PBES2 + HMAC-SHA512 + AES key wrap (256)
  24. RSA1_5 KeyEncryptionAlgorithm = "RSA1_5" // RSA-PKCS1v1.5
  25. RSA_OAEP KeyEncryptionAlgorithm = "RSA-OAEP" // RSA-OAEP-SHA1
  26. RSA_OAEP_256 KeyEncryptionAlgorithm = "RSA-OAEP-256" // RSA-OAEP-SHA256
  27. )
  28. // Accept is used when conversion from values given by
  29. // outside sources (such as JSON payloads) is required
  30. func (v *KeyEncryptionAlgorithm) Accept(value interface{}) error {
  31. var tmp KeyEncryptionAlgorithm
  32. switch x := value.(type) {
  33. case string:
  34. tmp = KeyEncryptionAlgorithm(x)
  35. case KeyEncryptionAlgorithm:
  36. tmp = x
  37. default:
  38. return errors.Errorf(`invalid type for jwa.KeyEncryptionAlgorithm: %T`, value)
  39. }
  40. switch tmp {
  41. case A128GCMKW, A128KW, A192GCMKW, A192KW, A256GCMKW, A256KW, DIRECT, ECDH_ES, ECDH_ES_A128KW, ECDH_ES_A192KW, ECDH_ES_A256KW, PBES2_HS256_A128KW, PBES2_HS384_A192KW, PBES2_HS512_A256KW, RSA1_5, RSA_OAEP, RSA_OAEP_256:
  42. default:
  43. return errors.Errorf(`invalid jwa.KeyEncryptionAlgorithm value`)
  44. }
  45. *v = tmp
  46. return nil
  47. }
  48. // String returns the string representation of a KeyEncryptionAlgorithm
  49. func (v KeyEncryptionAlgorithm) String() string {
  50. return string(v)
  51. }