| 1 | package jwkscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/" |
| 5 | "crypto/ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/" |
| 6 | "crypto/rsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/rsa`/" |
| 7 | "crypto/x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/" |
| 8 | "encoding/pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/" |
| 9 | "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/" |
| 10 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 11 | "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/" |
| 12 | |
| 13 | "github.com/lestrrat-go/blackmagicscip-go gomod github.com/lestrrat-go/blackmagic v1.0.4 `github.com/lestrrat-go/blackmagic`/" |
| 14 | "github.com/lestrrat-go/jwx/v3/jwk/jwkbbscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk/jwkbb`/" |
| 15 | ) |
| 16 | |
| 17 | // PEMDecoder is an interface to describe an object that can decode |
| 18 | // a key from PEM encoded ASN.1 DER format. |
| 19 | // |
| 20 | // A PEMDecoder can be specified as an option to `jwk.Parse()` or `jwk.ParseKey()` |
| 21 | // along with the `jwk.WithPEM()` option. |
| 22 | type PEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder# interface { |
| 23 | Decodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder#Decode.([]byte) (any, []byte, error) |
| 24 | } |
| 25 | |
| 26 | // PEMEncoder is an interface to describe an object that can encode |
| 27 | // a key into PEM encoded ASN.1 DER format. |
| 28 | // |
| 29 | // `jwk.Key` instances do not implement a way to encode themselves into |
| 30 | // PEM format. Normally you can just use `jwk.EncodePEM()` to do this, but |
| 31 | // this interface allows you to generalize the encoding process by |
| 32 | // abstracting the `jwk.EncodePEM()` function using `jwk.PEMEncodeFunc` |
| 33 | // along with alternate implementations, should you need them. |
| 34 | type PEMEncoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMEncoder# interface { |
| 35 | Encodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMEncoder#Encode.(any) (string, []byte, error) |
| 36 | } |
| 37 | |
| 38 | type PEMEncodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMEncodeFunc# func(any) (string, []byte, error) |
| 39 | |
| 40 | func (f PEMEncodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMEncodeFunc#) Encodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMEncodeFunc#Encode().(v any) (string, []byte, error) { |
| 41 | return f(v) |
| 42 | } |
| 43 | |
| 44 | func encodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/encodeX509().(v any) (string, []byte, error) { |
| 45 | // we can't import jwk, so just use the interface |
| 46 | if key, ok := v.(Keyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Key#); ok { |
| 47 | var raw any |
| 48 | if err := Exportscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/Export().(key, &raw); err != nil { |
| 49 | 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 out of %T: %w`, key, err) |
| 50 | } |
| 51 | |
| 52 | v = raw |
| 53 | } |
| 54 | |
| 55 | // Try to convert it into a certificate |
| 56 | switch v := v.(type) { |
| 57 | case *rsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/rsa`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rsa`/PrivateKey#: |
| 58 | return pmRSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmRSAPrivateKey., x509scip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/.MarshalPKCS1PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/x509`/MarshalPKCS1PrivateKey().(v), nil |
| 59 | case *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#: |
| 60 | marshaled, 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().(v) |
| 61 | if err != nil { |
| 62 | return "", nil, err |
| 63 | } |
| 64 | return pmECPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmECPrivateKey., marshaled, nil |
| 65 | case ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PrivateKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PrivateKey#: |
| 66 | marshaled, 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().(v) |
| 67 | if err != nil { |
| 68 | return "", nil, err |
| 69 | } |
| 70 | return pmPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmPrivateKey., marshaled, nil |
| 71 | case *rsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/rsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rsa`/PublicKey#, *ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#, ed25519scip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/.PublicKeyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ed25519`/PublicKey#: |
| 72 | marshaled, 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().(v) |
| 73 | if err != nil { |
| 74 | return "", nil, err |
| 75 | } |
| 76 | return pmPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmPublicKey., marshaled, nil |
| 77 | default: |
| 78 | 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 type %T for ASN.1 DER encoding`, v) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // EncodePEM encodes the key into a PEM encoded ASN.1 DER format. |
| 83 | // The key can be a jwk.Key or a raw key instance, but it must be one of |
| 84 | // the types supported by `x509` package. |
| 85 | // |
| 86 | // Internally, it uses the same routine as `jwk.EncodeX509()`, and therefore |
| 87 | // the same caveats apply |
| 88 | func EncodePEMscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/EncodePEM().(v any) ([]byte, error) { |
| 89 | typ, marshaled, err := encodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/encodeX509().(v) |
| 90 | if err != nil { |
| 91 | 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 key in x509: %w`, err) |
| 92 | } |
| 93 | |
| 94 | 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#{ |
| 95 | Typescip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Block#Type.: typ, |
| 96 | Bytesscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Block#Bytes.: marshaled, |
| 97 | } |
| 98 | return 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), nil |
| 99 | } |
| 100 | |
| 101 | const ( |
| 102 | pmPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmPrivateKey. = `PRIVATE KEY` |
| 103 | pmPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmPublicKey. = `PUBLIC KEY` |
| 104 | pmECPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmECPrivateKey. = `EC PRIVATE KEY` |
| 105 | pmRSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmRSAPublicKey. = `RSA PUBLIC KEY` |
| 106 | pmRSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pmRSAPrivateKey. = `RSA PRIVATE KEY` |
| 107 | ) |
| 108 | |
| 109 | // NewPEMDecoder returns a PEMDecoder that decodes keys in PEM encoded ASN.1 DER format. |
| 110 | // You can use it as argument to `jwk.WithPEMDecoder()` option. |
| 111 | // |
| 112 | // The use of this function is planned to be deprecated. The plan is to replace the |
| 113 | // `jwk.WithPEMDecoder()` option with globally available custom X509 decoders which |
| 114 | // can be registered via `jwk.RegisterX509Decoder()` function. |
| 115 | func NewPEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/NewPEMDecoder().() PEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder# { |
| 116 | return pemDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pemDecoder#{} |
| 117 | } |
| 118 | |
| 119 | type pemDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pemDecoder# struct{} |
| 120 | |
| 121 | // Decode decodes a key in PEM encoded ASN.1 DER format. |
| 122 | // and returns a raw key. |
| 123 | func (pemDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pemDecoder#) Decodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/pemDecoder#Decode().(src []byte) (any, []byte, error) { |
| 124 | block, rest := pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Decode().(src) |
| 125 | if block == nil { |
| 126 | return nil, rest, 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 data`) |
| 127 | } |
| 128 | var ret any |
| 129 | if err := jwkbbscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk/jwkbb`/.DecodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk/jwkbb`/DecodeX509().(&ret, block); err != nil { |
| 130 | return nil, rest, err |
| 131 | } |
| 132 | return ret, rest, nil |
| 133 | } |
| 134 | |
| 135 | // X509Decoder is an interface that describes an object that can decode |
| 136 | // a PEM encoded ASN.1 DER format into a specific type of key. |
| 137 | // |
| 138 | // This interface is experimental, and may change in the future. |
| 139 | type X509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509Decoder# interface { |
| 140 | // DecodeX509 decodes the given PEM block into the destination object. |
| 141 | // The destination object must be a pointer to a type that can hold the |
| 142 | // decoded key, such as *rsa.PrivateKey, *ecdsa.PrivateKey, etc. |
| 143 | DecodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509Decoder#DecodeX509.(dst any, 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#) error |
| 144 | } |
| 145 | |
| 146 | // X509DecodeFunc is a function type that implements the X509Decoder interface. |
| 147 | // It allows you to create a custom X509Decoder by providing a function |
| 148 | // that takes a destination and a PEM block, and returns an error if the decoding fails. |
| 149 | // |
| 150 | // This interface is experimental, and may change in the future. |
| 151 | type X509DecodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509DecodeFunc# func(dst any, 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#) error |
| 152 | |
| 153 | func (f X509DecodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509DecodeFunc#) DecodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509DecodeFunc#DecodeX509().(dst any, 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#) error { |
| 154 | return f(dst, block) |
| 155 | } |
| 156 | |
| 157 | var muX509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muX509Decoders. syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex# |
| 158 | var x509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509Decoders. = map[any]int{} |
| 159 | var x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList. = []X509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509Decoder#{} |
| 160 | |
| 161 | type identDefaultX509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identDefaultX509Decoder# struct{} |
| 162 | |
| 163 | func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/init().() { |
| 164 | RegisterX509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RegisterX509Decoder().(identDefaultX509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/identDefaultX509Decoder#{}, X509DecodeFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509DecodeFunc#(jwkbbscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk/jwkbb`/.DecodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk/jwkbb`/DecodeX509().)) |
| 165 | } |
| 166 | |
| 167 | // RegisterX509Decoder registers a new X509Decoder that can decode PEM encoded ASN.1 DER format. |
| 168 | // Because the decoder could be non-comparable, you must provide an identifier that can be used |
| 169 | // as a map key to identify the decoder. |
| 170 | // |
| 171 | // This function is experimental, and may change in the future. |
| 172 | func RegisterX509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/RegisterX509Decoder().(ident any, decoder X509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509Decoder#) { |
| 173 | if decoder == nil { |
| 174 | panic(`jwk.RegisterX509Decoder: decoder cannot be nil`) |
| 175 | } |
| 176 | |
| 177 | muX509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muX509Decoders..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 178 | defer muX509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muX509Decoders..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 179 | if _, ok := x509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509Decoders.[ident]; ok { |
| 180 | return // already registered |
| 181 | } |
| 182 | |
| 183 | x509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509Decoders.[ident] = len(x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList.) |
| 184 | x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList. = append(x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList., decoder) |
| 185 | } |
| 186 | |
| 187 | // UnregisterX509Decoder unregisters the X509Decoder identified by the given identifier. |
| 188 | // If the identifier is not registered, it does nothing. |
| 189 | // |
| 190 | // This function is experimental, and may change in the future. |
| 191 | func UnregisterX509Decoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/UnregisterX509Decoder().(ident any) { |
| 192 | muX509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muX509Decoders..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 193 | defer muX509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/muX509Decoders..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 194 | idx, ok := x509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509Decoders.[ident] |
| 195 | if !ok { |
| 196 | return // not registered |
| 197 | } |
| 198 | |
| 199 | delete(x509Decodersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509Decoders., ident) |
| 200 | |
| 201 | l := len(x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList.) |
| 202 | switch idx { |
| 203 | case l - 1: |
| 204 | // if the last element, just truncate the slice |
| 205 | x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList. = x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList.[:l-1] |
| 206 | case 0: |
| 207 | // if the first element, just shift the slice |
| 208 | x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList. = x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList.[1:] |
| 209 | default: |
| 210 | // if the element is in the middle, remove it by slicing |
| 211 | // and appending the two slices together |
| 212 | x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList. = append(x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList.[:idx], x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList.[idx+1:]...) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // decodeX509 decodes a PEM encoded ASN.1 DER format into the given destination. |
| 217 | // It tries all registered X509 decoders until one of them succeeds. |
| 218 | // If no decoder can handle the PEM block, it returns an error. |
| 219 | func decodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/decodeX509().(dst any, src []byte) error { |
| 220 | block, _ := pemscip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/.Decodescip-go gomod github.com/golang/go/src go1.24.0 `encoding/pem`/Decode().(src) |
| 221 | if block == nil { |
| 222 | 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 decode PEM data`) |
| 223 | } |
| 224 | |
| 225 | var errs []error |
| 226 | for _, d := range x509DecoderListscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/x509DecoderList. { |
| 227 | if err := d.DecodeX509scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/X509Decoder#DecodeX509.(dst, block); err != nil { |
| 228 | errs = append(errs, err) |
| 229 | continue |
| 230 | } |
| 231 | // successfully decoded |
| 232 | return nil |
| 233 | } |
| 234 | |
| 235 | 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 decode X509 data using any of the decoders: %w`, errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Joinscip-go gomod github.com/golang/go/src go1.24.0 errors/Join().(errs...)) |
| 236 | } |
| 237 | |
| 238 | func decodeX509WithPEMDEcoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/decodeX509WithPEMDEcoder().(dst any, src []byte, decoder PEMDecoderscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder#) error { |
| 239 | ret, _, err := decoder.Decodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwk`/PEMDecoder#Decode.(src) |
| 240 | if err != nil { |
| 241 | 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 decode PEM data: %w`, err) |
| 242 | } |
| 243 | |
| 244 | if err := blackmagicscip-go gomod github.com/lestrrat-go/blackmagic v1.0.4 `github.com/lestrrat-go/blackmagic`/.AssignIfCompatiblescip-go gomod github.com/lestrrat-go/blackmagic v1.0.4 `github.com/lestrrat-go/blackmagic`/AssignIfCompatible().(dst, ret); err != nil { |
| 245 | 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 decoded key to destination: %w`, err) |
| 246 | } |
| 247 | |
| 248 | return nil |
| 249 | } |