| 1 | package legacyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ |
| 2 | |
| 3 | import ( |
| 4 | "cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/" |
| 5 | "crypto/ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/" |
| 6 | "crypto/randscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rand`/" |
| 7 | "encoding/asn1scip-go gomod github.com/golang/go/src go1.24.0 `encoding/asn1`/" |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 9 | "math/bigscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/" |
| 10 | |
| 11 | "github.com/lestrrat-go/jwx/v3/internal/ecutilscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/ecutil`/" |
| 12 | "github.com/lestrrat-go/jwx/v3/internal/keyconvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/" |
| 13 | "github.com/lestrrat-go/jwx/v3/internal/poolscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/" |
| 14 | "github.com/lestrrat-go/jwx/v3/jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/" |
| 15 | "github.com/lestrrat-go/jwx/v3/jws/internal/keytypescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/internal/keytype`/" |
| 16 | ) |
| 17 | |
| 18 | var ecdsaSignersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigners. = make(map[jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm#]*ecdsaSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#) |
| 19 | var ecdsaVerifiersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifiers. = make(map[jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm#]*ecdsaVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#) |
| 20 | |
| 21 | func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/init().() { |
| 22 | algs := map[jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm#]cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Hashscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#{ |
| 23 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.ES256scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/ES256().(): 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., |
| 24 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.ES384scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/ES384().(): cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.SHA384scip-go gomod github.com/golang/go/src go1.24.0 crypto/SHA384., |
| 25 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.ES512scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/ES512().(): cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.SHA512scip-go gomod github.com/golang/go/src go1.24.0 crypto/SHA512., |
| 26 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.ES256Kscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/ES256K().(): 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., |
| 27 | } |
| 28 | for alg, hash := range algs { |
| 29 | ecdsaSignersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigners.[alg] = &ecdsaSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#{ |
| 30 | algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#alg.: alg, |
| 31 | hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#hash.: hash, |
| 32 | } |
| 33 | ecdsaVerifiersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifiers.[alg] = &ecdsaVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#{ |
| 34 | algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#alg.: alg, |
| 35 | hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#hash.: hash, |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func NewECDSASignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/NewECDSASigner().(alg jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm#) Signerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/Signer# { |
| 41 | return ecdsaSignersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigners.[alg] |
| 42 | } |
| 43 | |
| 44 | // ecdsaSigners are immutable. |
| 45 | type ecdsaSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner# struct { |
| 46 | algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#alg. jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm# |
| 47 | hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#hash. cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Hashscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash# |
| 48 | } |
| 49 | |
| 50 | func (es ecdsaSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#) Algorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#Algorithm().() jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm# { |
| 51 | return es.algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#alg. |
| 52 | } |
| 53 | |
| 54 | func (es *ecdsaSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#) Signscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#Sign().(payload []byte, key any) ([]byte, error) { |
| 55 | if key == nil { |
| 56 | 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().(`missing private key while signing payload`) |
| 57 | } |
| 58 | |
| 59 | h := es.hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#hash..Newscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#New().() |
| 60 | if _, err := h.Writescip-go gomod github.com/golang/go/src go1.24.0 io/Writer#Write().(payload); err != nil { |
| 61 | 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 write payload using ecdsa: %w`, err) |
| 62 | } |
| 63 | |
| 64 | signer, ok := key.(cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Signerscip-go gomod github.com/golang/go/src go1.24.0 crypto/Signer#) |
| 65 | if ok { |
| 66 | if !keytypescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/internal/keytype`/.IsValidECDSAKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/internal/keytype`/IsValidECDSAKey().(key) { |
| 67 | 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().(`cannot use key of type %T to generate ECDSA based signatures`, key) |
| 68 | } |
| 69 | switch key.(type) { |
| 70 | 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#, *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#: |
| 71 | // if it's a ecdsa.PrivateKey, it's more efficient to |
| 72 | // go through the non-crypto.Signer route. Set ok to false |
| 73 | ok = false |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | var r, s *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# |
| 78 | var curveBits int |
| 79 | if ok { |
| 80 | signed, err := signer.Signscip-go gomod github.com/golang/go/src go1.24.0 crypto/Signer#Sign().(randscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rand`/Reader., h.Sumscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#Sum().(nil), es.hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaSigner#hash.) |
| 81 | if err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | |
| 85 | var p struct { |
| 86 | R *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# |
| 87 | S *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# |
| 88 | } |
| 89 | if _, err := asn1scip-go gomod github.com/golang/go/src go1.24.0 `encoding/asn1`/.Unmarshalscip-go gomod github.com/golang/go/src go1.24.0 `encoding/asn1`/Unmarshal().(signed, &p); err != nil { |
| 90 | 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 unmarshal ASN1 encoded signature: %w`, err) |
| 91 | } |
| 92 | |
| 93 | // Okay, this is silly, but hear me out. When we use the |
| 94 | // crypto.Signer interface, the PrivateKey is hidden. |
| 95 | // But we need some information about the key (its bit size). |
| 96 | // |
| 97 | // So while silly, we're going to have to make another call |
| 98 | // here and fetch the Public key. |
| 99 | // This probably means that this should be cached some where. |
| 100 | cpub := signer.Publicscip-go gomod github.com/golang/go/src go1.24.0 crypto/Signer#Public().() |
| 101 | pubkey, ok := cpub.(*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#) |
| 102 | if !ok { |
| 103 | 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().(`expected *ecdsa.PublicKey, got %T`, pubkey) |
| 104 | } |
| 105 | curveBits = pubkey.Curvescip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#Curve..Paramsscip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/Curve#Params().().BitSizescip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/CurveParams#BitSize. |
| 106 | |
| 107 | r = p.R |
| 108 | s = p.S |
| 109 | } else { |
| 110 | var privkey 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# |
| 111 | if err := keyconvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/.ECDSAPrivateKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/ECDSAPrivateKey().(&privkey, key); err != nil { |
| 112 | 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 ecdsa.PrivateKey out of %T: %w`, key, err) |
| 113 | } |
| 114 | curveBits = privkey.Curvescip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#Curve..Paramsscip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/Curve#Params().().BitSizescip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/CurveParams#BitSize. |
| 115 | rtmp, stmp, err := ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/.Signscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/Sign().(randscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.24.0 `crypto/rand`/Reader., &privkey, h.Sumscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#Sum().(nil)) |
| 116 | if err != nil { |
| 117 | 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 sign payload using ecdsa: %w`, err) |
| 118 | } |
| 119 | r = rtmp |
| 120 | s = stmp |
| 121 | } |
| 122 | |
| 123 | keyBytes := curveBits / 8 |
| 124 | // Curve bits do not need to be a multiple of 8. |
| 125 | if curveBits%8 > 0 { |
| 126 | keyBytes++ |
| 127 | } |
| 128 | |
| 129 | rBytes := r.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/Int#Bytes().() |
| 130 | rBytesPadded := make([]byte, keyBytes) |
| 131 | copy(rBytesPadded[keyBytes-len(rBytes):], rBytes) |
| 132 | |
| 133 | sBytes := s.Bytesscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/Int#Bytes().() |
| 134 | sBytesPadded := make([]byte, keyBytes) |
| 135 | copy(sBytesPadded[keyBytes-len(sBytes):], sBytes) |
| 136 | |
| 137 | out := append(rBytesPadded, sBytesPadded...) |
| 138 | |
| 139 | return out, nil |
| 140 | } |
| 141 | |
| 142 | // ecdsaVerifiers are immutable. |
| 143 | type ecdsaVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier# struct { |
| 144 | algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#alg. jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm# |
| 145 | hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#hash. cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Hashscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash# |
| 146 | } |
| 147 | |
| 148 | func NewECDSAVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/NewECDSAVerifier().(alg jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm#) Verifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/Verifier# { |
| 149 | return ecdsaVerifiersscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifiers.[alg] |
| 150 | } |
| 151 | |
| 152 | func (v ecdsaVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#) Algorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#Algorithm().() jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.SignatureAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/SignatureAlgorithm# { |
| 153 | return v.algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#alg. |
| 154 | } |
| 155 | |
| 156 | func (v *ecdsaVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#) Verifyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#Verify().(payload []byte, signature []byte, key any) error { |
| 157 | if key == nil { |
| 158 | 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().(`missing public key while verifying payload`) |
| 159 | } |
| 160 | |
| 161 | var pubkey 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# |
| 162 | if cs, ok := key.(cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/.Signerscip-go gomod github.com/golang/go/src go1.24.0 crypto/Signer#); ok { |
| 163 | cpub := cs.Publicscip-go gomod github.com/golang/go/src go1.24.0 crypto/Signer#Public().() |
| 164 | switch cpub := cpub.(type) { |
| 165 | case 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#: |
| 166 | pubkey = cpub |
| 167 | case *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#: |
| 168 | pubkey = *cpub |
| 169 | default: |
| 170 | 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 ecdsa.PublicKey out of crypto.Signer %T`, key) |
| 171 | } |
| 172 | } else { |
| 173 | if err := keyconvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/.ECDSAPublicKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/ECDSAPublicKey().(&pubkey, key); err != nil { |
| 174 | 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 ecdsa.PublicKey out of %T: %w`, key, err) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | if !pubkey.Curvescip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#Curve..IsOnCurvescip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/Curve#IsOnCurve().(pubkey.Xscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#X., pubkey.Yscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#Y.) { |
| 179 | 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().(`public key used does not contain a point (X,Y) on the curve`) |
| 180 | } |
| 181 | |
| 182 | r := poolscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/.BigIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/BigInt().().Getscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/Pool#Get().() |
| 183 | s := poolscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/.BigIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/BigInt().().Getscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/Pool#Get().() |
| 184 | defer poolscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/.BigIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/BigInt().().Putscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/Pool#Put().(r) |
| 185 | defer poolscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/.BigIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/BigInt().().Putscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/pool`/Pool#Put().(s) |
| 186 | |
| 187 | keySize := ecutilscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/ecutil`/.CalculateKeySizescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/ecutil`/CalculateKeySize().(pubkey.Curvescip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#Curve.) |
| 188 | if len(signature) != keySize*2 { |
| 189 | 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().(`invalid signature length for curve %q`, pubkey.Curvescip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/PublicKey#Curve..Paramsscip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/Curve#Params().().Namescip-go gomod github.com/golang/go/src go1.24.0 `crypto/elliptic`/CurveParams#Name.) |
| 190 | } |
| 191 | |
| 192 | r.SetBytesscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/Int#SetBytes().(signature[:keySize]) |
| 193 | s.SetBytesscip-go gomod github.com/golang/go/src go1.24.0 `math/big`/Int#SetBytes().(signature[keySize:]) |
| 194 | |
| 195 | h := v.hashscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ecdsaVerifier#hash..Newscip-go gomod github.com/golang/go/src go1.24.0 crypto/Hash#New().() |
| 196 | if _, err := h.Writescip-go gomod github.com/golang/go/src go1.24.0 io/Writer#Write().(payload); err != nil { |
| 197 | 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 write payload using ecdsa: %w`, err) |
| 198 | } |
| 199 | |
| 200 | if !ecdsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/.Verifyscip-go gomod github.com/golang/go/src go1.24.0 `crypto/ecdsa`/Verify().(&pubkey, h.Sumscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#Sum().(nil), r, s) { |
| 201 | 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 verify signature using ecdsa`) |
| 202 | } |
| 203 | return nil |
| 204 | } |