| 1 | package jwsbbscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/jwsbb`/ |
| 2 | |
| 3 | import ( |
| 4 | "cryptoscip-go gomod github.com/golang/go/src go1.24.0 crypto/" |
| 5 | "crypto/rsascip-go gomod github.com/golang/go/src go1.24.0 `crypto/rsa`/" |
| 6 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 7 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 8 | |
| 9 | "github.com/lestrrat-go/dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/" |
| 10 | ) |
| 11 | |
| 12 | // rsaHashToDsigAlgorithm maps RSA hash functions to dsig algorithm constants |
| 13 | func rsaHashToDsigAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/jwsbb`/rsaHashToDsigAlgorithm().(h 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#, pss bool) (string, error) { |
| 14 | if pss { |
| 15 | switch h { |
| 16 | case 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.: |
| 17 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.RSAPSSWithSHA256scip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/RSAPSSWithSHA256., nil |
| 18 | case 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.: |
| 19 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.RSAPSSWithSHA384scip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/RSAPSSWithSHA384., nil |
| 20 | case 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.: |
| 21 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.RSAPSSWithSHA512scip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/RSAPSSWithSHA512., nil |
| 22 | default: |
| 23 | 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().("unsupported hash algorithm for RSA-PSS: %v", h) |
| 24 | } |
| 25 | } else { |
| 26 | switch h { |
| 27 | case 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.: |
| 28 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.RSAPKCS1v15WithSHA256scip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/RSAPKCS1v15WithSHA256., nil |
| 29 | case 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.: |
| 30 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.RSAPKCS1v15WithSHA384scip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/RSAPKCS1v15WithSHA384., nil |
| 31 | case 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.: |
| 32 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.RSAPKCS1v15WithSHA512scip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/RSAPKCS1v15WithSHA512., nil |
| 33 | default: |
| 34 | 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().("unsupported hash algorithm for RSA PKCS#1 v1.5: %v", h) |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // SignRSA generates an RSA signature for the given payload using the specified private key and options. |
| 40 | // The raw parameter should be the pre-computed signing input (typically header.payload). |
| 41 | // If pss is true, RSA-PSS is used; otherwise, PKCS#1 v1.5 is used. |
| 42 | // |
| 43 | // The rr parameter is an optional io.Reader that can be used to provide randomness for signing. |
| 44 | // If rr is nil, it defaults to rand.Reader. |
| 45 | // |
| 46 | // This function is now a thin wrapper around dsig.SignRSA. For new projects, you should |
| 47 | // consider using dsig instead of this function. |
| 48 | func SignRSAscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/jwsbb`/SignRSA().(key *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#, payload []byte, h 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#, pss bool, rr 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#) ([]byte, error) { |
| 49 | dsigAlg, err := rsaHashToDsigAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/jwsbb`/rsaHashToDsigAlgorithm().(h, pss) |
| 50 | if err != nil { |
| 51 | 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().("jwsbb.SignRSA: %w", err) |
| 52 | } |
| 53 | |
| 54 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.Signscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/Sign().(key, dsigAlg, payload, rr) |
| 55 | } |
| 56 | |
| 57 | // VerifyRSA verifies an RSA signature for the given payload and header. |
| 58 | // This function constructs the signing input by encoding the header and payload according to JWS specification, |
| 59 | // then verifies the signature using the specified public key and hash algorithm. |
| 60 | // If pss is true, RSA-PSS verification is used; otherwise, PKCS#1 v1.5 verification is used. |
| 61 | // |
| 62 | // This function is now a thin wrapper around dsig.VerifyRSA. For new projects, you should |
| 63 | // consider using dsig instead of this function. |
| 64 | func VerifyRSAscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/jwsbb`/VerifyRSA().(key *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#, payload, signature []byte, h 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#, pss bool) error { |
| 65 | dsigAlg, err := rsaHashToDsigAlgorithmscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jws/jwsbb`/rsaHashToDsigAlgorithm().(h, pss) |
| 66 | if err != nil { |
| 67 | 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().("jwsbb.VerifyRSA: %w", err) |
| 68 | } |
| 69 | |
| 70 | return dsigscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/.Verifyscip-go gomod github.com/lestrrat-go/dsig v1.0.0 `github.com/lestrrat-go/dsig`/Verify().(key, dsigAlg, payload, signature) |
| 71 | } |