Debian Codegraph @

jwk/jwk.go

raw symbols SCIP
1 //go:generate ../tools/cmd/genjwk.sh
2
3 package jwkscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/
4
5 import (
6 "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/"
7 "cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/"
8 "crypto/ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/"
9 "crypto/x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/"
10 "encoding/pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/"
11 "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/"
12 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
13 "ioscip-go gomod github.com/golang/go/src go1.24.0 io/"
14 "math/bigscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/"
15 "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/"
16 "slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/"
17
18 "github.com/lestrrat-go/jwx/v3/internal/base64scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/"
19 "github.com/lestrrat-go/jwx/v3/internal/jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/"
20 )
21
22 var registryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/registry. = jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.NewRegistryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/NewRegistry().()
23
24 func bigIntToBytesscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/bigIntToBytes().(n *bigscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/Int#) ([]byte, error) {
25 if n == nil {
26 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid *big.Int value`)
27 }
28 return n.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/Int#Bytes().(), nil
29 }
30
31 func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/init().() {
32 if err := RegisterProbeFieldscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RegisterProbeField().(reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.StructFieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#{
33 Namescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Name.: "Kty",
34 Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Type.: reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeFor().[string](),
35 Tagscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Tag.: `json:"kty"`,
36 }); err != nil {
37 panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to register mandatory probe for 'kty' field: %w", err))
38 }
39 if err := RegisterProbeFieldscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RegisterProbeField().(reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.StructFieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#{
40 Namescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Name.: "D",
41 Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Type.: reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeFor().[jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.RawMessagescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/RawMessage#](),
42 Tagscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Tag.: `json:"d,omitempty"`,
43 }); err != nil {
44 panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to register mandatory probe for 'kty' field: %w", err))
45 }
46 }
47
48 // Import creates a jwk.Key from the given key (RSA/ECDSA/symmetric keys).
49 //
50 // The constructor auto-detects the type of key to be instantiated
51 // based on the input type:
52 //
53 // - "crypto/rsa".PrivateKey and "crypto/rsa".PublicKey creates an RSA based key
54 // - "crypto/ecdsa".PrivateKey and "crypto/ecdsa".PublicKey creates an EC based key
55 // - "crypto/ed25519".PrivateKey and "crypto/ed25519".PublicKey creates an OKP based key
56 // - "crypto/ecdh".PrivateKey and "crypto/ecdh".PublicKey creates an OKP based key
57 // - []byte creates a symmetric key
58 func Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Import().(raw any) (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) {
59 if raw == nil {
60 return nil, importerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/importerr().(`a non-nil key is required`)
61 }
62
63 muKeyImportersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muKeyImporters..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().()
64 conv, ok := keyImportersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyImporters.[reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/TypeOf().(raw)]
65 muKeyImportersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muKeyImporters..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().()
66 if !ok {
67 return nil, importerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/importerr().(`failed to convert %T to jwk.Key: no converters were able to convert`, raw)
68 }
69
70 return conv.Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyImporter#Import.(raw)
71 }
72
73 // PublicSetOf returns a new jwk.Set consisting of
74 // public keys of the keys contained in the set.
75 //
76 // This is useful when you are generating a set of private keys, and
77 // you want to generate the corresponding public versions for the
78 // users to verify with.
79 //
80 // Be aware that all fields will be copied onto the new public key. It is the caller's
81 // responsibility to remove any fields, if necessary.
82 func PublicSetOfscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicSetOf().(v Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#) (Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#, error) {
83 newSet := NewSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewSet().()
84
85 n := v.Lenscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#Len.()
86 for i := range n {
87 k, ok := v.Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#Key.(i)
88 if !ok {
89 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`key not found`)
90 }
91 pubKey, err := PublicKeyOfscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyOf().(k)
92 if err != nil {
93 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to get public key of %T: %w`, k, err)
94 }
95 if err := newSet.AddKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#AddKey.(pubKey); err != nil {
96 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to add key to public key set: %w`, err)
97 }
98 }
99
100 return newSet, nil
101 }
102
103 // PublicKeyOf returns the corresponding public version of the jwk.Key.
104 // If `v` is a SymmetricKey, then the same value is returned.
105 // If `v` is already a public key, the key itself is returned.
106 //
107 // If `v` is a private key type that has a `PublicKey()` method, be aware
108 // that all fields will be copied onto the new public key. It is the caller's
109 // responsibility to remove any fields, if necessary
110 //
111 // If `v` is a raw key, the key is first converted to a `jwk.Key`
112 func PublicKeyOfscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyOf().(v any) (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) {
113 // This should catch all jwk.Key instances
114 if pk, ok := v.(PublicKeyerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyer#); ok {
115 return pk.PublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyer#PublicKey.()
116 }
117
118 jk, err := Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Import().(v)
119 if err != nil {
120 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.PublicKeyOf: failed to convert key into JWK: %w`, err)
121 }
122
123 return jk.PublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#PublicKey.()
124 }
125
126 // PublicRawKeyOf returns the corresponding public key of the given
127 // value `v` (e.g. given *rsa.PrivateKey, *rsa.PublicKey is returned)
128 // If `v` is already a public key, the key itself is returned.
129 //
130 // The returned value will always be a pointer to the public key,
131 // except when a []byte (e.g. symmetric key, ed25519 key) is passed to `v`.
132 // In this case, the same []byte value is returned.
133 //
134 // This function must go through converting the object once to a jwk.Key,
135 // then back to a raw key, so it's not exactly efficient.
136 func PublicRawKeyOfscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicRawKeyOf().(v any) (any, error) {
137 pk, ok := v.(PublicKeyerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyer#)
138 if !ok {
139 k, err := Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Import().(v)
140 if err != nil {
141 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.PublicRawKeyOf: failed to convert key to jwk.Key: %w`, err)
142 }
143
144 pk, ok = k.(PublicKeyerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyer#)
145 if !ok {
146 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.PublicRawKeyOf: failed to convert key to jwk.PublicKeyer: %w`, err)
147 }
148 }
149
150 pubk, err := pk.PublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PublicKeyer#PublicKey.()
151 if err != nil {
152 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.PublicRawKeyOf: failed to obtain public key from %T: %w`, v, err)
153 }
154
155 var raw any
156 if err := Exportscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Export().(pubk, &raw); err != nil {
157 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.PublicRawKeyOf: failed to obtain raw key from %T: %w`, pubk, err)
158 }
159 return raw, nil
160 }
161
162 // ParseRawKey is a combination of ParseKey and Raw. It parses a single JWK key,
163 // and assigns the "raw" key to the given parameter. The key must either be
164 // a pointer to an empty interface, or a pointer to the actual raw key type
165 // such as *rsa.PrivateKey, *ecdsa.PublicKey, *[]byte, etc.
166 func ParseRawKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseRawKey().(data []byte, rawkey any) error {
167 key, err := ParseKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseKey().(data)
168 if err != nil {
169 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to parse key: %w`, err)
170 }
171
172 if err := Exportscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Export().(key, rawkey); err != nil {
173 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to assign to raw key variable: %w`, err)
174 }
175
176 return nil
177 }
178
179 type setDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx# struct {
180 jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.DecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#DecodeCtx.
181
182 ignoreParseErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#ignoreParseError. bool
183 }
184
185 func (ctx *setDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#) IgnoreParseErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#IgnoreParseError().() bool {
186 return ctx.ignoreParseErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#ignoreParseError.
187 }
188
189 // ParseKey parses a single key JWK. Unlike `jwk.Parse` this method will
190 // report failure if you attempt to pass a JWK set. Only use this function
191 // when you know that the data is a single JWK.
192 //
193 // Given a WithPEM(true) option, this function assumes that the given input
194 // is PEM encoded ASN.1 DER format key.
195 //
196 // Note that a successful parsing of any type of key does NOT necessarily
197 // guarantee a valid key. For example, no checks against expiration dates
198 // are performed for certificate expiration, no checks against missing
199 // parameters are performed, etc.
200 func ParseKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseKey().(data []byte, options ...ParseOptionscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseOption#) (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) {
201 var parsePEM bool
202 var localReg *jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.Registryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Registry#
203 var pemDecoder PEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder#
204 for _, option := range options {
205 switch option.Identscip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Ident().() {
206 case identPEMscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identPEM#{}:
207 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&parsePEM); err != nil {
208 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to retrieve PEM option value: %w`, err)
209 }
210 case identPEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identPEMDecoder#{}:
211 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&pemDecoder); err != nil {
212 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to retrieve PEMDecoder option value: %w`, err)
213 }
214 case identLocalRegistryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identLocalRegistry#{}:
215 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&localReg); err != nil {
216 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to retrieve local registry option value: %w`, err)
217 }
218 case identTypedFieldscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identTypedField#{}:
219 var pair typedFieldPairscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/typedFieldPair# // temporary var needed for typed field
220 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&pair); err != nil {
221 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to retrieve typed field option value: %w`, err)
222 }
223 if localReg == nil {
224 localReg = jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.NewRegistryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/NewRegistry().()
225 }
226 localReg.Registerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Registry#Register().(pair.Namescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/typedFieldPair#Name., pair.Valuescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/typedFieldPair#Value.)
227 case identIgnoreParseErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identIgnoreParseError#{}:
228 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.WithIgnoreParseError() cannot be used for ParseKey()`)
229 }
230 }
231
232 if parsePEM {
233 var raw any
234
235 // PEMDecoder should probably be deprecated, because of being a misnomer.
236 if pemDecoder != nil {
237 if err := decodeX509WithPEMDEcoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/decodeX509WithPEMDEcoder().(&raw, data, pemDecoder); err != nil {
238 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to decode PEM encoded key: %w`, err)
239 }
240 } else {
241 // This version takes into account the various X509 decoders that are
242 // pre-registered.
243 if err := decodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/decodeX509().(&raw, data); err != nil {
244 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to decode X.509 encoded key: %w`, err)
245 }
246 }
247 return Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Import().(raw)
248 }
249
250 probe, err := keyProbescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyProbe..Probescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyProber#Probe().(data)
251 if err != nil {
252 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.Parse: failed to probe data: %w`, err)
253 }
254
255 unmarshaler := keyUnmarshalerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyUnmarshaler#{localRegscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyUnmarshaler#localReg.: localReg}
256
257 muKeyParserscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muKeyParser..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().()
258 parsers := make([]KeyParserscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyParser#, len(keyParsersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyParsers.))
259 copy(parsers, keyParsersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyParsers.)
260 muKeyParserscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muKeyParser..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().()
261
262 for i := len(parsers) - 1; i >= 0; i-- {
263 parser := parsers[i]
264 key, err := parser.ParseKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyParser#ParseKey.(probe, &unmarshaler, data)
265 if err == nil {
266 return key, nil
267 }
268
269 if errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Isscip-go gomod github.com/golang/go/src go1.24.0 errors/Is().(err, ContinueErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ContinueError().()) {
270 continue
271 }
272
273 return nil, err
274 }
275 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.Parse: no parser was able to parse the key`)
276 }
277
278 // Parse parses JWK from the incoming []byte.
279 //
280 // For JWK sets, this is a convenience function. You could just as well
281 // call `json.Unmarshal` against an empty set created by `jwk.NewSet()`
282 // to parse a JSON buffer into a `jwk.Set`.
283 //
284 // This function exists because many times the user does not know before hand
285 // if a JWK(s) resource at a remote location contains a single JWK key or
286 // a JWK set, and `jwk.Parse()` can handle either case, returning a JWK Set
287 // even if the data only contains a single JWK key
288 //
289 // If you are looking for more information on how JWKs are parsed, or if
290 // you know for sure that you have a single key, please see the documentation
291 // for `jwk.ParseKey()`.
292 func Parsescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Parse().(src []byte, options ...ParseOptionscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseOption#) (Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#, error) {
293 var parsePEM bool
294 var parseX509 bool
295 var localReg *jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.Registryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Registry#
296 var ignoreParseError bool
297 var pemDecoder PEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder#
298 for _, option := range options {
299 switch option.Identscip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Ident().() {
300 case identPEMscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identPEM#{}:
301 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&parsePEM); err != nil {
302 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to retrieve PEM option value: %w`, err)
303 }
304 case identX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identX509#{}:
305 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&parseX509); err != nil {
306 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to retrieve X509 option value: %w`, err)
307 }
308 case identPEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identPEMDecoder#{}:
309 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&pemDecoder); err != nil {
310 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to retrieve PEMDecoder option value: %w`, err)
311 }
312 case identIgnoreParseErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identIgnoreParseError#{}:
313 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&ignoreParseError); err != nil {
314 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to retrieve IgnoreParseError option value: %w`, err)
315 }
316 case identTypedFieldscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identTypedField#{}:
317 var pair typedFieldPairscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/typedFieldPair# // temporary var needed for typed field
318 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&pair); err != nil {
319 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to retrieve typed field option value: %w`, err)
320 }
321 if localReg == nil {
322 localReg = jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.NewRegistryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/NewRegistry().()
323 }
324 localReg.Registerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Registry#Register().(pair.Namescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/typedFieldPair#Name., pair.Valuescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/typedFieldPair#Value.)
325 }
326 }
327
328 s := NewSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewSet().()
329
330 if parsePEM || parseX509 {
331 if pemDecoder == nil {
332 pemDecoder = NewPEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewPEMDecoder().()
333 }
334 src = bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 bytes/TrimSpace().(src)
335 for len(src) > 0 {
336 raw, rest, err := pemDecoder.Decodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder#Decode.(src)
337 if err != nil {
338 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to parse PEM encoded key: %w`, err)
339 }
340 key, err := Importscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Import().(raw)
341 if err != nil {
342 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to create jwk.Key from %T: %w`, raw, err)
343 }
344 if err := s.AddKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#AddKey.(key); err != nil {
345 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to add jwk.Key to set: %w`, err)
346 }
347 src = bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 bytes/TrimSpace().(rest)
348 }
349 return s, nil
350 }
351
352 if localReg != nil || ignoreParseError {
353 dcKs, ok := s.(KeyWithDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyWithDecodeCtx#)
354 if !ok {
355 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`typed field was requested, but the key set (%T) does not support DecodeCtx`, s)
356 }
357 dc := &setDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#{
358 DecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#DecodeCtx.: jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.NewDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/NewDecodeCtx().(localReg),
359 ignoreParseErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/setDecodeCtx#ignoreParseError.: ignoreParseError,
360 }
361 dcKs.SetDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyWithDecodeCtx#SetDecodeCtx.(dc)
362 defer func() { dcKs.SetDecodeCtxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyWithDecodeCtx#SetDecodeCtx.(nil) }()
363 }
364
365 if err := jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.Unmarshalscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Unmarshal().(src, s); err != nil {
366 return nil, parseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/parseerr().(`failed to unmarshal JWK set: %w`, err)
367 }
368
369 return s, nil
370 }
371
372 // ParseReader parses a JWK set from the incoming byte buffer.
373 func ParseReaderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseReader().(src ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Readerscip-go gomod github.com/golang/go/src go1.24.0 io/Reader#, options ...ParseOptionscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseOption#) (Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#, error) {
374 // meh, there's no way to tell if a stream has "ended" a single
375 // JWKs except when we encounter an EOF, so just... ReadAll
376 buf, err := ioscip-go gomod github.com/golang/go/src go1.24.0 io/.ReadAllscip-go gomod github.com/golang/go/src go1.24.0 io/ReadAll().(src)
377 if err != nil {
378 return nil, rparseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rparseerr().(`failed to read from io.Reader: %w`, err)
379 }
380
381 set, err := Parsescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Parse().(buf, options...)
382 if err != nil {
383 return nil, rparseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/rparseerr().(`failed to parse reader: %w`, err)
384 }
385 return set, nil
386 }
387
388 // ParseString parses a JWK set from the incoming string.
389 func ParseStringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseString().(s string, options ...ParseOptionscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ParseOption#) (Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#, error) {
390 set, err := Parsescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Parse().([]byte(s), options...)
391 if err != nil {
392 return nil, sparseerrscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/sparseerr().(`failed to parse string: %w`, err)
393 }
394 return set, nil
395 }
396
397 // AssignKeyID is a convenience function to automatically assign the "kid"
398 // section of the key, if it already doesn't have one. It uses Key.Thumbprint
399 // method with crypto.SHA256 as the default hashing algorithm
400 func AssignKeyIDscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/AssignKeyID().(key Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, options ...AssignKeyIDOptionscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/AssignKeyIDOption#) error {
401 if key.Hasscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Has.(KeyIDKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyIDKey.) {
402 return nil
403 }
404
405 hash := cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.SHA256scip-go gomod github.com/golang/go/src go1.24.0 crypto/SHA256.
406 for _, option := range options {
407 switch option.Identscip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Ident().() {
408 case identThumbprintHashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identThumbprintHash#{}:
409 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&hash); err != nil {
410 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to retrieve thumbprint hash option value: %w`, err)
411 }
412 }
413 }
414
415 h, err := key.Thumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Thumbprint.(hash)
416 if err != nil {
417 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to generate thumbprint: %w`, err)
418 }
419
420 if err := key.Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Set.(KeyIDKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/KeyIDKey., base64scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/.EncodeToStringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/base64`/EncodeToString().(h)); err != nil {
421 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to set "kid": %w`, err)
422 }
423
424 return nil
425 }
426
427 // NOTE: may need to remove this to allow pluggale key types
428 func cloneKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/cloneKey().(src Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#) (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) {
429 var dst Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#
430 switch src.(type) {
431 case RSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RSAPrivateKey#:
432 dst = newRSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newRSAPrivateKey().()
433 case RSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RSAPublicKey#:
434 dst = newRSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newRSAPublicKey().()
435 case ECDSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ECDSAPrivateKey#:
436 dst = newECDSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newECDSAPrivateKey().()
437 case ECDSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ECDSAPublicKey#:
438 dst = newECDSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newECDSAPublicKey().()
439 case OKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#:
440 dst = newOKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newOKPPrivateKey().()
441 case OKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPublicKey#:
442 dst = newOKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newOKPPublicKey().()
443 case SymmetricKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/SymmetricKey#:
444 dst = newSymmetricKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/newSymmetricKey().()
445 default:
446 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.cloneKey: unknown key type %T`, src)
447 }
448
449 for _, k := range src.Keysscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Keys.() {
450 // It's absolutely
451 var v any
452 if err := src.Getscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Get.(k, &v); err != nil {
453 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.cloneKey: failed to get %q: %w`, k, err)
454 }
455 if err := dst.Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Set.(k, v); err != nil {
456 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`jwk.cloneKey: failed to set %q: %w`, k, err)
457 }
458 }
459 return dst, nil
460 }
461
462 // Pem serializes the given jwk.Key in PEM encoded ASN.1 DER format,
463 // using either PKCS8 for private keys and PKIX for public keys.
464 // If you need to encode using PKCS1 or SEC1, you must do it yourself.
465 //
466 // # Argument must be of type jwk.Key or jwk.Set
467 //
468 // Currently only EC (including Ed25519) and RSA keys (and jwk.Set
469 // comprised of these key types) are supported.
470 func Pemscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Pem().(v any) ([]byte, error) {
471 var set Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#
472 switch v := v.(type) {
473 case Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#:
474 set = NewSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewSet().()
475 if err := set.AddKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#AddKey.(v); err != nil {
476 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to add key to set: %w`, err)
477 }
478 case Setscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#:
479 set = v
480 default:
481 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`argument to Pem must be either jwk.Key or jwk.Set: %T`, v)
482 }
483
484 var ret []byte
485 for i := range set.Lenscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#Len.() {
486 key, _ := set.Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Set#Key.(i)
487 typ, buf, err := asnEncodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/asnEncode().(key)
488 if err != nil {
489 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to encode content for key #%d: %w`, i, err)
490 }
491
492 var block pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/.Blockscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Block#
493 block.Typescip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Block#Type. = typ
494 block.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Block#Bytes. = buf
495 ret = append(ret, pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/.EncodeToMemoryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/EncodeToMemory().(&block)...)
496 }
497 return ret, nil
498 }
499
500 func asnEncodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/asnEncode().(key Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#) (string, []byte, error) {
501 switch key := key.(type) {
502 case ECDSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ECDSAPrivateKey#:
503 var rawkey ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PrivateKey#
504 if err := Exportscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Export().(key, &rawkey); err != nil {
505 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to get raw key from jwk.Key: %w`, err)
506 }
507 buf, err := x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/.MarshalECPrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/MarshalECPrivateKey().(&rawkey)
508 if err != nil {
509 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to marshal PKCS8: %w`, err)
510 }
511 return pmECPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmECPrivateKey., buf, nil
512 case RSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RSAPrivateKey#, OKPPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPrivateKey#:
513 var rawkey any
514 if err := Exportscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Export().(key, &rawkey); err != nil {
515 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to get raw key from jwk.Key: %w`, err)
516 }
517 buf, err := x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/.MarshalPKCS8PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/MarshalPKCS8PrivateKey().(rawkey)
518 if err != nil {
519 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to marshal PKCS8: %w`, err)
520 }
521 return pmPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmPrivateKey., buf, nil
522 case RSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RSAPublicKey#, ECDSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ECDSAPublicKey#, OKPPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/OKPPublicKey#:
523 var rawkey any
524 if err := Exportscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Export().(key, &rawkey); err != nil {
525 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to get raw key from jwk.Key: %w`, err)
526 }
527 buf, err := x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/.MarshalPKIXPublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/MarshalPKIXPublicKey().(rawkey)
528 if err != nil {
529 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to marshal PKIX: %w`, err)
530 }
531 return pmPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmPublicKey., buf, nil
532 default:
533 return "", nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`unsupported key type %T`, key)
534 }
535 }
536
537 type CustomDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/CustomDecoder# = jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.CustomDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/CustomDecoder#
538 type CustomDecodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/CustomDecodeFunc# = jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.CustomDecodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/CustomDecodeFunc#
539
540 // RegisterCustomField allows users to specify that a private field
541 // be decoded as an instance of the specified type. This option has
542 // a global effect.
543 //
544 // For example, suppose you have a custom field `x-birthday`, which
545 // you want to represent as a string formatted in RFC3339 in JSON,
546 // but want it back as `time.Time`.
547 //
548 // In such case you would register a custom field as follows
549 //
550 // jwk.RegisterCustomField(`x-birthday`, time.Time{})
551 //
552 // Then you can use a `time.Time` variable to extract the value
553 // of `x-birthday` field, instead of having to use `any`
554 // and later convert it to `time.Time`
555 //
556 // var bday time.Time
557 // _ = key.Get(`x-birthday`, &bday)
558 //
559 // If you need a more fine-tuned control over the decoding process,
560 // you can register a `CustomDecoder`. For example, below shows
561 // how to register a decoder that can parse RFC1123 format string:
562 //
563 // jwk.RegisterCustomField(`x-birthday`, jwk.CustomDecodeFunc(func(data []byte) (any, error) {
564 // return time.Parse(time.RFC1123, string(data))
565 // }))
566 //
567 // Please note that use of custom fields can be problematic if you
568 // are using a library that does not implement MarshalJSON/UnmarshalJSON
569 // and you try to roundtrip from an object to JSON, and then back to an object.
570 // For example, in the above example, you can _parse_ time values formatted
571 // in the format specified in RFC822, but when you convert an object into
572 // JSON, it will be formatted in RFC3339, because that's what `time.Time`
573 // likes to do. To avoid this, it's always better to use a custom type
574 // that wraps your desired type (in this case `time.Time`) and implement
575 // MarshalJSON and UnmashalJSON.
576 func RegisterCustomFieldscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RegisterCustomField().(name string, object any) {
577 registryscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/registry..Registerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Registry#Register().(name, object)
578 }
579
580 // Equal compares two keys and returns true if they are equal. The comparison
581 // is solely done against the thumbprints of k1 and k2. It is possible for keys
582 // that have, for example, different key IDs, key usage, etc, to be considered equal.
583 func Equalscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Equal().(k1, k2 Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#) bool {
584 h := cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.SHA256scip-go gomod github.com/golang/go/src go1.24.0 crypto/SHA256.
585 tp1, err := k1.Thumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Thumbprint.(h)
586 if err != nil {
587 return false // can't report error
588 }
589 tp2, err := k2.Thumbprintscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#Thumbprint.(h)
590 if err != nil {
591 return false // can't report error
592 }
593
594 return bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.24.0 bytes/Equal().(tp1, tp2)
595 }
596
597 // IsPrivateKey returns true if the supplied key is a private key of an
598 // asymmetric key pair. The argument `k` must implement the `AsymmetricKey`
599 // interface.
600 //
601 // An error is returned if the supplied key is not an `AsymmetricKey`.
602 func IsPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/IsPrivateKey().(k Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#) (bool, error) {
603 asymmetric, ok := k.(AsymmetricKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/AsymmetricKey#)
604 if ok {
605 return asymmetric.IsPrivatescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/AsymmetricKey#IsPrivate.(), nil
606 }
607 return false, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("jwk.IsPrivateKey: %T is not an asymmetric key", k)
608 }
609
610 type keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError# struct {
611 errscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#err. error
612 }
613
614 func (e *keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#) Errorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#Error().() string {
615 return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(`key validation failed: %s`, e.errscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#err.)
616 }
617
618 func (e *keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#) Unwrapscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#Unwrap().() error {
619 return e.errscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#err.
620 }
621
622 func (e *keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#) Isscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#Is().(target error) bool {
623 _, ok := target.(*keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#)
624 return ok
625 }
626
627 // NewKeyValidationError wraps the given error with an error that denotes
628 // `key.Validate()` has failed. This error type should ONLY be used as
629 // return value from the `Validate()` method.
630 func NewKeyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewKeyValidationError().(err error) error {
631 return &keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#{errscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#err.: err}
632 }
633
634 func IsKeyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/IsKeyValidationError().(err error) bool {
635 var kve keyValidationErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyValidationError#
636 return errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Isscip-go gomod github.com/golang/go/src go1.24.0 errors/Is().(err, &kve)
637 }
638
639 // Configure is used to configure global behavior of the jwk package.
640 func Configurescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Configure().(options ...GlobalOptionscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/GlobalOption#) {
641 var strictKeyUsagePtr *bool
642 for _, option := range options {
643 switch option.Identscip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Ident().() {
644 case identStrictKeyUsagescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identStrictKeyUsage#{}:
645 var v bool
646 if err := option.Valuescip-go gomod github.com/lestrrat-go/option/v2 v2.0.0 `github.com/lestrrat-go/option/v2`/Interface#Value().(&v); err != nil {
647 continue
648 }
649 strictKeyUsagePtr = &v
650 }
651 }
652
653 if strictKeyUsagePtr != nil {
654 strictKeyUsagescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/strictKeyUsage..Storescip-go gomod github.com/golang/go/src go1.24.0 `sync/atomic`/Bool#Store().(*strictKeyUsagePtr)
655 }
656 }
657
658 // These are used when validating keys.
659 type keyWithDscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyWithD# interface {
660 Dscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyWithD#D.() ([]byte, bool)
661 }
662
663 var _ keyWithDscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/keyWithD# = &okpPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/okpPrivateKey#{}
664
665 func extractEmbeddedKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/extractEmbeddedKey().(keyif Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, concretTypes []reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#) (Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#, error) {
666 rv := reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.24.0 reflect/ValueOf().(keyif)
667
668 // If the value can be converted to one of the concrete types, then we're done
669 if slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/.ContainsFuncscip-go gomod github.com/golang/go/src go1.24.0 slices/ContainsFunc().(concretTypes, func(t reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#) bool {
670 return rv.Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Type().().ConvertibleToscip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#ConvertibleTo().(t)
671 }) {
672 return keyif, nil
673 }
674
675 // When a struct implements the Key interface via embedding, you unfortunately
676 // cannot use a type switch to determine the concrete type, because
677 if rv.Kindscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.24.0 reflect/Ptr. {
678 if rv.IsNilscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#IsNil().() {
679 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid key value (0): %w`, ContinueErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ContinueError().())
680 }
681 rv = rv.Elemscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Elem().()
682 }
683
684 if rv.Kindscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.Structscip-go gomod github.com/golang/go/src go1.24.0 reflect/Struct. {
685 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid key value type %T (1): %w`, keyif, ContinueErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ContinueError().())
686 }
687 if rv.NumFieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#NumField().() == 0 {
688 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid key value type %T (2): %w`, keyif, ContinueErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ContinueError().())
689 }
690 // Iterate through the fields of the struct to find the first field that
691 // implements the Key interface
692 rt := rv.Typescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Type().()
693 for i := range rv.NumFieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#NumField().() {
694 field := rv.Fieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Field().(i)
695 ft := rt.Fieldscip-go gomod github.com/golang/go/src go1.24.0 reflect/Type#Field().(i)
696 if !ft.Anonymousscip-go gomod github.com/golang/go/src go1.24.0 reflect/StructField#Anonymous. {
697 // We can only salvage this object if the object implements jwk.Key
698 // via embedding, so we skip fields that are not anonymous
699 continue
700 }
701
702 if field.CanInterfacescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#CanInterface().() {
703 if k, ok := field.Interfacescip-go gomod github.com/golang/go/src go1.24.0 reflect/Value#Interface().().(Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#); ok {
704 return extractEmbeddedKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/extractEmbeddedKey().(k, concretTypes)
705 }
706 }
707 }
708
709 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid key value type %T (3): %w`, keyif, ContinueErrorscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ContinueError().())
710 }