content_encryption_gen.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // this file was auto-generated by internal/cmd/gentypes/main.go: DO NOT EDIT
  2. package jwa
  3. import (
  4. "fmt"
  5. "sort"
  6. "sync"
  7. "github.com/pkg/errors"
  8. )
  9. // ContentEncryptionAlgorithm represents the various encryption algorithms as described in https://tools.ietf.org/html/rfc7518#section-5
  10. type ContentEncryptionAlgorithm string
  11. // Supported values for ContentEncryptionAlgorithm
  12. const (
  13. A128CBC_HS256 ContentEncryptionAlgorithm = "A128CBC-HS256" // AES-CBC + HMAC-SHA256 (128)
  14. A128GCM ContentEncryptionAlgorithm = "A128GCM" // AES-GCM (128)
  15. A192CBC_HS384 ContentEncryptionAlgorithm = "A192CBC-HS384" // AES-CBC + HMAC-SHA384 (192)
  16. A192GCM ContentEncryptionAlgorithm = "A192GCM" // AES-GCM (192)
  17. A256CBC_HS512 ContentEncryptionAlgorithm = "A256CBC-HS512" // AES-CBC + HMAC-SHA512 (256)
  18. A256GCM ContentEncryptionAlgorithm = "A256GCM" // AES-GCM (256)
  19. )
  20. var allContentEncryptionAlgorithms = map[ContentEncryptionAlgorithm]struct{}{
  21. A128CBC_HS256: {},
  22. A128GCM: {},
  23. A192CBC_HS384: {},
  24. A192GCM: {},
  25. A256CBC_HS512: {},
  26. A256GCM: {},
  27. }
  28. var listContentEncryptionAlgorithmOnce sync.Once
  29. var listContentEncryptionAlgorithm []ContentEncryptionAlgorithm
  30. // ContentEncryptionAlgorithms returns a list of all available values for ContentEncryptionAlgorithm
  31. func ContentEncryptionAlgorithms() []ContentEncryptionAlgorithm {
  32. listContentEncryptionAlgorithmOnce.Do(func() {
  33. listContentEncryptionAlgorithm = make([]ContentEncryptionAlgorithm, 0, len(allContentEncryptionAlgorithms))
  34. for v := range allContentEncryptionAlgorithms {
  35. listContentEncryptionAlgorithm = append(listContentEncryptionAlgorithm, v)
  36. }
  37. sort.Slice(listContentEncryptionAlgorithm, func(i, j int) bool {
  38. return string(listContentEncryptionAlgorithm[i]) < string(listContentEncryptionAlgorithm[j])
  39. })
  40. })
  41. return listContentEncryptionAlgorithm
  42. }
  43. // Accept is used when conversion from values given by
  44. // outside sources (such as JSON payloads) is required
  45. func (v *ContentEncryptionAlgorithm) Accept(value interface{}) error {
  46. var tmp ContentEncryptionAlgorithm
  47. if x, ok := value.(ContentEncryptionAlgorithm); ok {
  48. tmp = x
  49. } else {
  50. var s string
  51. switch x := value.(type) {
  52. case fmt.Stringer:
  53. s = x.String()
  54. case string:
  55. s = x
  56. default:
  57. return errors.Errorf(`invalid type for jwa.ContentEncryptionAlgorithm: %T`, value)
  58. }
  59. tmp = ContentEncryptionAlgorithm(s)
  60. }
  61. if _, ok := allContentEncryptionAlgorithms[tmp]; !ok {
  62. return errors.Errorf(`invalid jwa.ContentEncryptionAlgorithm value`)
  63. }
  64. *v = tmp
  65. return nil
  66. }
  67. // String returns the string representation of a ContentEncryptionAlgorithm
  68. func (v ContentEncryptionAlgorithm) String() string {
  69. return string(v)
  70. }