Skip to content

Commit

Permalink
[v2] Fixes to work with go1.24 (#1298)
Browse files Browse the repository at this point in the history
* Update go versions

* Update go versions

* Work with Go 1.24

* tweak

* Rename examples so go1.24 doesn't complain

* tweak test

---------

Co-authored-by: Daisuke Maki <[email protected]>
  • Loading branch information
lestrrat and Daisuke Maki authored Feb 24, 2025
1 parent dc437b4 commit a3cd476
Show file tree
Hide file tree
Showing 59 changed files with 83 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
go_tags: [ 'stdlib', 'goccy', 'es256k', 'secp256k1-pem', 'asmbase64', 'alltags']
go: [ '1.23', '1.22', '1.21' ]
go: [ '1.24', '1.23', '1.22' ]
name: "Test [ Go ${{ matrix.go }} / Tags ${{ matrix.go_tags }} ]"
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
go_tags: [ 'stdlib', 'goccy', 'es256k', 'alltags' ]
go: [ '1.23', '1.22', '1.21' ]
go: [ '1.24', '1.23', '1.22' ]
name: "Smoke [ Go ${{ matrix.go }} / Tags ${{ matrix.go_tags }} ]"
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion examples/jwe_decrypt_with_key_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwe"
)

func ExampleJWE_VerifyWithKey() {
func Example_jwe_verify_with_key() {
const payload = "Lorem ipsum"
encrypted, err := jwe.Encrypt([]byte(payload), jwe.WithKey(jwa.RSA_OAEP, jwkRSAPublicKey))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/jwe_decrypt_with_keyset_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWE_VerifyWithJWKSet() {
func Example_jwe_verify_with_jwk_set() {
privkey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Printf("failed to create private key: %s\n", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/jwe_encrypt_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWE_Encrypt() {
func Example_jwe_encrypt() {
rawprivkey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Printf("failed to create raw private key: %s\n", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/jwe_encrypt_json_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWE_EncryptJSON() {
func Example_jwe_encrypt_json() {
rawprivkey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Printf("failed to create raw private key: %s\n", err)
Expand Down Expand Up @@ -45,7 +45,7 @@ func ExampleJWE_EncryptJSON() {
// Lorem ipsum
}

func ExampleJWE_EncryptJSONMulti() {
func Example_jwe_encrypt_json_multi() {
var privkeys []jwk.Key
var pubkeys []jwk.Key

Expand Down
2 changes: 1 addition & 1 deletion examples/jwe_encrypt_with_headers_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwe"
)

func ExampleJWE_SignWithHeaders() {
func Example_jwe_sign_with_headers() {
privkey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Printf("failed to create private key: %s\n", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/jwe_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func exampleGenPayload() (*rsa.PrivateKey, []byte, error) {
return privkey, encrypted, nil
}

func ExampleJWE_Decrypt() {
func Example_jwe_decrypt() {
privkey, encrypted, err := exampleGenPayload()
if err != nil {
log.Printf("failed to generate encrypted payload: %s", err)
Expand All @@ -47,7 +47,7 @@ func ExampleJWE_Decrypt() {
// OUTPUT:
}

func ExampleJWE_ComplexDecrypt() {
func Example_jwe_complex_decrypt() {
// WARNING: THIS USAGE IS NOT FOR A CASUAL USER. ONLY use it when you must.
// Only use it when you understand how JWE is supposed to work. Only use it
// when you understand the inner workings of this code.
Expand Down
2 changes: 1 addition & 1 deletion examples/jwe_parse_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwe"
)

func ExampleJWE_Parse() {
func Example_jwe_parse() {
const src = `eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.KrFTaMKVY_iUKYYk905QjbUf_fpBXvXCzIAfbPoPMGViDzxtgz5qnch8waV7wraVDfzpW7JfPOw6Nz_-XRwN3Vbud48bRYFw92GkC0M6kpKFpl_xgZxGN47ggNk9hzgqd7mFCuyufeYdn5c2fPoRZAV4UxvakLozEYcQo-eZaFmoYS4pyoC-IKKRikobW8n__LksMzXc_Vps1axn5kdpxsKQ4k1oayvUrgWX2PMxKn_TcLEKHtCN7qRlJ5hkKbZAXAdd34zGWcFV5gc1tcLs6HFhnebo8GUgItTYWBKSKzF6MyLJNRSUPFVq9q-Jxi1juXIlDrv_7rHVsdokQmBfvA.bK7z7Z3gEzFDgDQvNen0Ww.2hngnAVrmucUpJKLgIzYcg.CHs3ZP7JtG430Dl9YAKLMAl`

msg, err := jwe.Parse([]byte(src))
Expand Down
2 changes: 1 addition & 1 deletion examples/jwe_readfile_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwe"
)

func ExampleJWE_ReadFile() {
func Example_jwe_readfile() {
const src = `eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.KrFTaMKVY_iUKYYk905QjbUf_fpBXvXCzIAfbPoPMGViDzxtgz5qnch8waV7wraVDfzpW7JfPOw6Nz_-XRwN3Vbud48bRYFw92GkC0M6kpKFpl_xgZxGN47ggNk9hzgqd7mFCuyufeYdn5c2fPoRZAV4UxvakLozEYcQo-eZaFmoYS4pyoC-IKKRikobW8n__LksMzXc_Vps1axn5kdpxsKQ4k1oayvUrgWX2PMxKn_TcLEKHtCN7qRlJ5hkKbZAXAdd34zGWcFV5gc1tcLs6HFhnebo8GUgItTYWBKSKzF6MyLJNRSUPFVq9q-Jxi1juXIlDrv_7rHVsdokQmBfvA.bK7z7Z3gEzFDgDQvNen0Ww.2hngnAVrmucUpJKLgIzYcg.CHs3ZP7JtG430Dl9YAKLMAl`

f, err := os.CreateTemp(``, `jwe_readfile_example-*.jwe`)
Expand Down
3 changes: 2 additions & 1 deletion examples/jwk_cache_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_Cache() {
func Example_jwk_cache() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

const googleCerts = `https://www.googleapis.com/oauth2/v3/certs`

Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_cached_set_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWK_CachedSet() {
func Example_jwk_cached_set() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_comparison_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_Comparison() {
func Example_jwk_comparison() {
genKey := func() (jwk.Key, error) {
raw, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/jwk_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_Usage() {
func Example_jwk_usage() {
// Use jwk.Cache if you intend to keep reuse the JWKS over and over
set, err := jwk.Fetch(context.Background(), "https://www.googleapis.com/oauth2/v3/certs")
if err != nil {
Expand Down Expand Up @@ -65,7 +65,7 @@ func ExampleJWK_Usage() {
}

//nolint:govet
func ExampleJWK_MarshalJSON() {
func Example_jwk_marshal_json() {
// JWKs that inherently involve randomness such as RSA and EC keys are
// not used in this example, because they may produce different results
// depending on the environment.
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_fetch_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_Fetch() {
func Example_jwk_fetch() {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_from_raw_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_FromRaw() {
func Example_jwk_from_raw() {
// First, THIS IS THE WRONG WAY TO USE jwk.FromRaw().
//
// Assume that the file contains a JWK in JSON format
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_key_specific_methods_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_KeySpecificMethods() {
func Example_jwk_key_specific_methods() {
raw, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Printf("failed to generate RSA private key: %s\n", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_parse_jwks_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_ParseJWKS() {
func Example_jwk_parse_jwks() {
const src = `{
"keys": [
{"kty":"EC",
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_parse_key_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_ParseKey() {
func Example_jwk_parse_key() {
const src = `{
"kty":"EC",
"crv":"P-256",
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_parse_with_pem_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_ParseWithPEM() {
func Example_jwk_parse_with_pem() {
const src = `-----BEGIN CERTIFICATE-----
MIIEljCCAn4CCQCTQBoGDvUbQTANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJK
UDAeFw0yMTA0MDEwMDE4MjhaFw0yMjA0MDEwMDE4MjhaMA0xCzAJBgNVBAYTAkpQ
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_readfile_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_ReadFile() {
func Example_jwk_readfile() {
const src = `{
"keys": [
{"kty":"EC",
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_readfile_with_pem_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_ReadFileWithPEM() {
func Example_jwk_readfile_with_pem() {
const src = `-----BEGIN CERTIFICATE-----
MIIEljCCAn4CCQCTQBoGDvUbQTANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJK
UDAeFw0yMTA0MDEwMDE4MjhaFw0yMjA0MDEwMDE4MjhaMA0xCzAJBgNVBAYTAkpQ
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_struct_field_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Proxy struct {
Key json.RawMessage `json:"key"`
}

func ExampleJWK_StructField() {
func Example_jwk_struct_field() {
const src = `{
"key": {
"kty":"EC",
Expand Down
2 changes: 1 addition & 1 deletion examples/jwk_whitelist_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)

func ExampleJWK_Whitelist() {
func Example_jwk_whitelist() {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_custom_signer_verifier_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s CirclEdDSASignerVerifier) Verify(payload []byte, signature []byte, keyif
}
}

func ExampleJWS_CustomSignerVerifier() {
func Example_jws_custom_signer_verifier() {
// This example shows how to register external jws.Signer / jws.Verifier for
// a given algorithm.
jws.RegisterSigner(jwa.EdDSA, jws.SignerFactoryFn(NewCirclEdDSASigner))
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_Message() {
func Example_jws_message() {
const payload = `eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ`
const encodedSig1 = `cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw`
const encodedSig2 = "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_parse_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_Parse() {
func Example_jws_parse() {
const src = `eyJhbGciOiJIUzI1NiJ9.TG9yZW0gaXBzdW0.idbECxA8ZhQbU0ddZmzdRZxQmHjwvw77lT2bwqGgNMo`

msg, err := jws.Parse([]byte(src))
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_readfile_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_ReadFile() {
func Example_jws_readfile() {
const src = `eyJhbGciOiJIUzI1NiJ9.TG9yZW0gaXBzdW0.idbECxA8ZhQbU0ddZmzdRZxQmHjwvw77lT2bwqGgNMo`
f, err := os.CreateTemp(``, `jws_readfile-*.jws`)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_sign_detached_payload_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_SignDetachedPayload() {
func Example_jws_sign_detached_payload() {
payload := `$.02`

key, err := jwk.FromRaw([]byte(`abracadabra`))
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_sign_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_Sign() {
func Example_jws_sign() {
key, err := jwk.FromRaw([]byte(`abracadabra`))
if err != nil {
fmt.Printf("failed to create key: %s\n", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_sign_json_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_SignJSON() {
func Example_jws_sign_json() {
var keys []jwk.Key

for i := 0; i < 3; i++ {
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_sign_with_headers_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_SignWithHeaders() {
func Example_jws_sign_with_headers() {
key, err := jwk.FromRaw([]byte(`abracadabra`))
if err != nil {
fmt.Printf("failed to create key: %s\n", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_use_jws_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt"
)

func ExampleJWS_UseJWSHeader() {
func Example_jws_use_header() {
key, err := jwk.FromRaw([]byte(`abracadabra`))
if err != nil {
fmt.Printf(`failed to create new symmetric key: %s`, err)
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_verify_detached_payload_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_VerifyDetachedPayload() {
func Example_jws_verify_detached_payload() {
serialized := `eyJhbGciOiJIUzI1NiJ9..H14oXKwyvAsl0IbBLjw9tLxNIoYisuIyb_oDV4-30Vk`
payload := `$.02`

Expand Down
2 changes: 1 addition & 1 deletion examples/jws_verify_with_key_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_VerifyWithKey() {
func Example_jws_verify_with_key() {
const src = `eyJhbGciOiJIUzI1NiJ9.TG9yZW0gaXBzdW0.EjVtju0uXjSz6QevNgAqN1ESd9aNCP7-tJLifkQ0_C0`

key, err := jwk.FromRaw([]byte(`abracadabra`))
Expand Down
2 changes: 1 addition & 1 deletion examples/jws_verify_with_keyset_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jws"
)

func ExampleJWS_VerifyWithJWKSet() {
func Example_jws_verify_with_jwk_set() {
// Setup payload first...
privkey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/jwt_builder_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt"
)

func ExampleJWT_Builder() {
func Example_jwt_builder() {
tok, err := jwt.NewBuilder().
Claim(`claim1`, `value1`).
Claim(`claim2`, `value2`).
Expand Down
2 changes: 1 addition & 1 deletion examples/jwt_construct_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt"
)

func ExampleJWT_Construct() {
func Example_jwt_construct() {
tok := jwt.New()
if err := tok.Set(jwt.IssuerKey, `github.com/lestrrat-go/jwx`); err != nil {
fmt.Printf("failed to set claim: %s\n", err)
Expand Down
Loading

0 comments on commit a3cd476

Please sign in to comment.