github.com/lestrrat-go/jwx/v2@v2.0.21/jwk/interface_gen.go (about) 1 // Code generated by tools/cmd/genjwk/main.go. DO NOT EDIT. 2 3 package jwk 4 5 import ( 6 "context" 7 "crypto" 8 9 "github.com/lestrrat-go/jwx/v2/cert" 10 "github.com/lestrrat-go/jwx/v2/jwa" 11 ) 12 13 const ( 14 KeyTypeKey = "kty" 15 KeyUsageKey = "use" 16 KeyOpsKey = "key_ops" 17 AlgorithmKey = "alg" 18 KeyIDKey = "kid" 19 X509URLKey = "x5u" 20 X509CertChainKey = "x5c" 21 X509CertThumbprintKey = "x5t" 22 X509CertThumbprintS256Key = "x5t#S256" 23 ) 24 25 // Key defines the minimal interface for each of the 26 // key types. Their use and implementation differ significantly 27 // between each key types, so you should use type assertions 28 // to perform more specific tasks with each key 29 type Key interface { 30 // Get returns the value of a single field. The second boolean return value 31 // will be false if the field is not stored in the source 32 // 33 // This method, which returns an `interface{}`, exists because 34 // these objects can contain extra _arbitrary_ fields that users can 35 // specify, and there is no way of knowing what type they could be 36 Get(string) (interface{}, bool) 37 38 // Set sets the value of a single field. Note that certain fields, 39 // notably "kty", cannot be altered, but will not return an error 40 // 41 // This method, which takes an `interface{}`, exists because 42 // these objects can contain extra _arbitrary_ fields that users can 43 // specify, and there is no way of knowing what type they could be 44 Set(string, interface{}) error 45 46 // Remove removes the field associated with the specified key. 47 // There is no way to remove the `kty` (key type). You will ALWAYS be left with one field in a jwk.Key. 48 Remove(string) error 49 // Validate performs _minimal_ checks if the data stored in the key are valid. 50 // By minimal, we mean that it does not check if the key is valid for use in 51 // cryptographic operations. For example, it does not check if an RSA key's 52 // `e` field is a valid exponent, or if the `n` field is a valid modulus. 53 // Instead, it checks for things such as the _presence_ of some required fields, 54 // or if certain keys' values are of particular length. 55 // 56 // Note that depending on th underlying key type, use of this method requires 57 // that multiple fields in the key are properly populated. For example, an EC 58 // key's "x", "y" fields cannot be validated unless the "crv" field is populated first. 59 // 60 // Validate is never called by `UnmarshalJSON()` or `Set`. It must explicitly be 61 // called by the user 62 Validate() error 63 64 // Raw creates the corresponding raw key. For example, 65 // EC types would create *ecdsa.PublicKey or *ecdsa.PrivateKey, 66 // and OctetSeq types create a []byte key. 67 // 68 // If you do not know the exact type of a jwk.Key before attempting 69 // to obtain the raw key, you can simply pass a pointer to an 70 // empty interface as the first argument. 71 // 72 // If you already know the exact type, it is recommended that you 73 // pass a pointer to the zero value of the actual key type (e.g. &rsa.PrivateKey) 74 // for efficiency. 75 Raw(interface{}) error 76 77 // Thumbprint returns the JWK thumbprint using the indicated 78 // hashing algorithm, according to RFC 7638 79 Thumbprint(crypto.Hash) ([]byte, error) 80 81 // Iterate returns an iterator that returns all keys and values. 82 // See github.com/lestrrat-go/iter for a description of the iterator. 83 Iterate(ctx context.Context) HeaderIterator 84 85 // Walk is a utility tool that allows a visitor to iterate all keys and values 86 Walk(context.Context, HeaderVisitor) error 87 88 // AsMap is a utility tool that returns a new map that contains the same fields as the source 89 AsMap(context.Context) (map[string]interface{}, error) 90 91 // PrivateParams returns the non-standard elements in the source structure 92 // WARNING: DO NOT USE PrivateParams() IF YOU HAVE CONCURRENT CODE ACCESSING THEM. 93 // Use `AsMap()` to get a copy of the entire header, or use `Iterate()` instead 94 PrivateParams() map[string]interface{} 95 96 // Clone creates a new instance of the same type 97 Clone() (Key, error) 98 99 // PublicKey creates the corresponding PublicKey type for this object. 100 // All fields are copied onto the new public key, except for those that are not allowed. 101 // 102 // If the key is already a public key, it returns a new copy minus the disallowed fields as above. 103 PublicKey() (Key, error) 104 105 // KeyType returns the `kty` of a JWK 106 KeyType() jwa.KeyType 107 // KeyUsage returns `use` of a JWK 108 KeyUsage() string 109 // KeyOps returns `key_ops` of a JWK 110 KeyOps() KeyOperationList 111 // Algorithm returns `alg` of a JWK 112 113 // Algorithm returns the value of the `alg` field 114 // 115 // This field may contain either `jwk.SignatureAlgorithm` or `jwk.KeyEncryptionAlgorithm`. 116 // This is why there exists a `jwa.KeyAlgorithm` type that encompases both types. 117 Algorithm() jwa.KeyAlgorithm 118 // KeyID returns `kid` of a JWK 119 KeyID() string 120 // X509URL returns `x5u` of a JWK 121 X509URL() string 122 // X509CertChain returns `x5c` of a JWK 123 X509CertChain() *cert.Chain 124 // X509CertThumbprint returns `x5t` of a JWK 125 X509CertThumbprint() string 126 // X509CertThumbprintS256 returns `x5t#S256` of a JWK 127 X509CertThumbprintS256() string 128 129 makePairs() []*HeaderPair 130 }