elliptic.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // EllipticCurveAlgorithm represents the algorithms used for EC keys
  7. type EllipticCurveAlgorithm string
  8. // Supported values for EllipticCurveAlgorithm
  9. const (
  10. P256 EllipticCurveAlgorithm = "P-256"
  11. P384 EllipticCurveAlgorithm = "P-384"
  12. P521 EllipticCurveAlgorithm = "P-521"
  13. )
  14. // Accept is used when conversion from values given by
  15. // outside sources (such as JSON payloads) is required
  16. func (v *EllipticCurveAlgorithm) Accept(value interface{}) error {
  17. var tmp EllipticCurveAlgorithm
  18. switch x := value.(type) {
  19. case string:
  20. tmp = EllipticCurveAlgorithm(x)
  21. case EllipticCurveAlgorithm:
  22. tmp = x
  23. default:
  24. return errors.Errorf(`invalid type for jwa.EllipticCurveAlgorithm: %T`, value)
  25. }
  26. switch tmp {
  27. case P256, P384, P521:
  28. default:
  29. return errors.Errorf(`invalid jwa.EllipticCurveAlgorithm value`)
  30. }
  31. *v = tmp
  32. return nil
  33. }
  34. // String returns the string representation of a EllipticCurveAlgorithm
  35. func (v EllipticCurveAlgorithm) String() string {
  36. return string(v)
  37. }