| 1 | package legacyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/ |
| 2 | |
| 3 | import ( |
| 4 | "crypto/hmacscip-go gomod github.com/golang/go/src go1.24.0 `crypto/hmac`/" |
| 5 | "crypto/sha256scip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha256`/" |
| 6 | "crypto/sha512scip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha512`/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 8 | "hashscip-go gomod github.com/golang/go/src go1.24.0 hash/" |
| 9 | |
| 10 | "github.com/lestrrat-go/jwx/v3/internal/keyconvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/" |
| 11 | "github.com/lestrrat-go/jwx/v3/jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/" |
| 12 | ) |
| 13 | |
| 14 | func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/init().() { |
| 15 | 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#]func() hashscip-go gomod github.com/golang/go/src go1.24.0 hash/.Hashscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#{ |
| 16 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.HS256scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/HS256().(): sha256scip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha256`/.Newscip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha256`/New()., |
| 17 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.HS384scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/HS384().(): sha512scip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha512`/.New384scip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha512`/New384()., |
| 18 | jwascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/.HS512scip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwa`/HS512().(): sha512scip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha512`/.Newscip-go gomod github.com/golang/go/src go1.24.0 `crypto/sha512`/New()., |
| 19 | } |
| 20 | |
| 21 | for alg, h := range algs { |
| 22 | hmacSignFuncsscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFuncs.[alg] = makeHMACSignFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/makeHMACSignFunc().(h) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | // HMACSigner uses crypto/hmac to sign the payloads. |
| 27 | // This is for legacy support only. |
| 28 | type HMACSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner# struct { |
| 29 | algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#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# |
| 30 | signscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#sign. hmacSignFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFunc# |
| 31 | } |
| 32 | |
| 33 | type HMACVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier# struct { |
| 34 | signerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier#signer. Signerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/Signer# |
| 35 | } |
| 36 | |
| 37 | type hmacSignFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFunc# func(payload []byte, key []byte) ([]byte, error) |
| 38 | |
| 39 | var hmacSignFuncsscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFuncs. = 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#]hmacSignFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFunc#) |
| 40 | |
| 41 | func NewHMACSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/NewHMACSigner().(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# { |
| 42 | return &HMACSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#{ |
| 43 | algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#alg.: alg, |
| 44 | signscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#sign.: hmacSignFuncsscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFuncs.[alg], // we know this will succeed |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func makeHMACSignFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/makeHMACSignFunc().(hfunc func() hashscip-go gomod github.com/golang/go/src go1.24.0 hash/.Hashscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#) hmacSignFuncscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/hmacSignFunc# { |
| 49 | return func(payload []byte, key []byte) ([]byte, error) { |
| 50 | h := hmacscip-go gomod github.com/golang/go/src go1.24.0 `crypto/hmac`/.Newscip-go gomod github.com/golang/go/src go1.24.0 `crypto/hmac`/New().(hfunc, key) |
| 51 | if _, err := h.Writescip-go gomod github.com/golang/go/src go1.24.0 io/Writer#Write().(payload); err != nil { |
| 52 | 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 hmac: %w`, err) |
| 53 | } |
| 54 | return h.Sumscip-go gomod github.com/golang/go/src go1.24.0 hash/Hash#Sum().(nil), nil |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (s HMACSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#) Algorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#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# { |
| 59 | return s.algscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#alg. |
| 60 | } |
| 61 | |
| 62 | func (s HMACSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#) Signscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#Sign().(payload []byte, key any) ([]byte, error) { |
| 63 | var hmackey []byte |
| 64 | if err := keyconvscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/.ByteSliceKeyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/keyconv`/ByteSliceKey().(&hmackey, key); err != nil { |
| 65 | 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 type %T. []byte is required: %w`, key, err) |
| 66 | } |
| 67 | |
| 68 | if len(hmackey) == 0 { |
| 69 | 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 key while signing payload`) |
| 70 | } |
| 71 | |
| 72 | return s.signscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACSigner#sign.(payload, hmackey) |
| 73 | } |
| 74 | |
| 75 | func NewHMACVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/NewHMACVerifier().(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# { |
| 76 | s := NewHMACSignerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/NewHMACSigner().(alg) |
| 77 | return &HMACVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier#{signerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier#signer.: s} |
| 78 | } |
| 79 | |
| 80 | func (v HMACVerifierscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier#) Verifyscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier#Verify().(payload, signature []byte, key any) (err error) { |
| 81 | expected, err := v.signerscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/HMACVerifier#signer..Signscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/legacy`/Signer#Sign.(payload, key) |
| 82 | if err != nil { |
| 83 | 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 generated signature: %w`, err) |
| 84 | } |
| 85 | |
| 86 | if !hmacscip-go gomod github.com/golang/go/src go1.24.0 `crypto/hmac`/.Equalscip-go gomod github.com/golang/go/src go1.24.0 `crypto/hmac`/Equal().(signature, expected) { |
| 87 | 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 match hmac signature`) |
| 88 | } |
| 89 | return nil |
| 90 | } |