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