interface.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package keygen
  2. import (
  3. "crypto/ecdsa"
  4. "github.com/lestrrat-go/jwx/jwa"
  5. "github.com/lestrrat-go/jwx/x25519"
  6. )
  7. type Generator interface {
  8. Size() int
  9. Generate() (ByteSource, error)
  10. }
  11. // StaticKeyGenerate uses a static byte buffer to provide keys.
  12. type Static []byte
  13. // RandomKeyGenerate generates random keys
  14. type Random struct {
  15. keysize int
  16. }
  17. // EcdhesKeyGenerate generates keys using ECDH-ES algorithm / EC-DSA curve
  18. type Ecdhes struct {
  19. pubkey *ecdsa.PublicKey
  20. keysize int
  21. algorithm jwa.KeyEncryptionAlgorithm
  22. enc jwa.ContentEncryptionAlgorithm
  23. }
  24. // X25519KeyGenerate generates keys using ECDH-ES algorithm / X25519 curve
  25. type X25519 struct {
  26. algorithm jwa.KeyEncryptionAlgorithm
  27. enc jwa.ContentEncryptionAlgorithm
  28. keysize int
  29. pubkey x25519.PublicKey
  30. }
  31. // ByteKey is a generated key that only has the key's byte buffer
  32. // as its instance data. If a key needs to do more, such as providing
  33. // values to be set in a JWE header, that key type wraps a ByteKey
  34. type ByteKey []byte
  35. // ByteWithECPublicKey holds the EC private key that generated
  36. // the key along with the key itself. This is required to set the
  37. // proper values in the JWE headers
  38. type ByteWithECPublicKey struct {
  39. ByteKey
  40. PublicKey interface{}
  41. }
  42. type ByteWithIVAndTag struct {
  43. ByteKey
  44. IV []byte
  45. Tag []byte
  46. }
  47. type ByteWithSaltAndCount struct {
  48. ByteKey
  49. Salt []byte
  50. Count int
  51. }
  52. // ByteSource is an interface for things that return a byte sequence.
  53. // This is used for KeyGenerator so that the result of computations can
  54. // carry more than just the generate byte sequence.
  55. type ByteSource interface {
  56. Bytes() []byte
  57. }
  58. type Setter interface {
  59. Set(string, interface{}) error
  60. }