Skip to content

Commit 6dc5002

Browse files
authored
pin jwx/v3 to 89c1d7848e6e (#4)
* pin jwx/v3 to 89c1d7848e6e * update ed448 to use KeyExporter API * trigger CI on all pushes
1 parent 2a040d3 commit 6dc5002

5 files changed

Lines changed: 40 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
name: CI
2-
on:
3-
push:
4-
branches:
5-
- main
6-
pull_request:
7-
branches:
8-
- main
2+
on: [push]
93

104
jobs:
115
build:

ed448.go

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ func init() {
3333
// Register Ed448 as valid algorithm for OKP key type
3434
jws.RegisterAlgorithmForKeyType(jwa.OKP(), jwa.EdDSAEd448())
3535

36-
// Register JWK OKP curve builders for Ed448
37-
jwk.RegisterOKPCurveBuilder(jwa.Ed448(), jwk.OKPCurveBuilder{
38-
BuildPublicKey: buildEd448PublicKey,
39-
BuildPrivateKey: buildEd448PrivateKey,
40-
})
36+
// Register JWK exporter for OKP:Ed448 keys (JWK → raw ed448 key)
37+
jwk.RegisterKeyExporter(jwk.KeyKind("OKP:Ed448"), jwk.KeyExportFunc(exportEd448Key))
4138

4239
// Register raw key importer for Ed448 keys
4340
jwk.RegisterOKPRawKeyImporter(importEd448RawKey)
4441

45-
// Register jwk.Import handlers for Ed448 key types
42+
// Register jwk.Import handlers for Ed448 key types (raw ed448 key → JWK)
4643
f := jwk.KeyImportFunc(importOKPEd448Key)
4744
jwk.RegisterKeyImporter(ed448.PublicKey(nil), f)
4845
jwk.RegisterKeyImporter(ed448.PrivateKey(nil), f)
@@ -126,25 +123,40 @@ func ed448PublicKey(dst *ed448.PublicKey, src any) error {
126123
return nil
127124
}
128125

129-
// --- JWK OKP key building ---
126+
// --- JWK key export (JWK → raw ed448 key) ---
130127

131-
func buildEd448PublicKey(xbuf []byte) (any, error) {
132-
if len(xbuf) != ed448.PublicKeySize {
133-
return nil, fmt.Errorf(`ed448: wrong public key size %d (expected %d)`, len(xbuf), ed448.PublicKeySize)
134-
}
135-
return ed448.PublicKey(xbuf), nil
136-
}
137-
138-
func buildEd448PrivateKey(xbuf, dbuf []byte) (any, error) {
139-
if len(dbuf) != ed448.SeedSize {
140-
return nil, fmt.Errorf(`ed448: wrong private key seed size %d (expected %d)`, len(dbuf), ed448.SeedSize)
141-
}
142-
ret := ed448.NewKeyFromSeed(dbuf)
143-
pub := ret.Public().(ed448.PublicKey) //nolint:forcetypeassert
144-
if !bytes.Equal(xbuf, pub) {
145-
return nil, fmt.Errorf(`ed448: invalid x value given d value`)
128+
func exportEd448Key(key jwk.Key, _ any) (any, error) {
129+
switch key := key.(type) {
130+
case jwk.OKPPrivateKey:
131+
x, ok := key.X()
132+
if !ok {
133+
return nil, fmt.Errorf(`missing "x" field`)
134+
}
135+
d, ok := key.D()
136+
if !ok {
137+
return nil, fmt.Errorf(`missing "d" field`)
138+
}
139+
if len(d) != ed448.SeedSize {
140+
return nil, fmt.Errorf(`ed448: wrong private key seed size %d (expected %d)`, len(d), ed448.SeedSize)
141+
}
142+
ret := ed448.NewKeyFromSeed(d)
143+
pub := ret.Public().(ed448.PublicKey) //nolint:forcetypeassert
144+
if !bytes.Equal(x, pub) {
145+
return nil, fmt.Errorf(`ed448: invalid x value given d value`)
146+
}
147+
return ret, nil
148+
case jwk.OKPPublicKey:
149+
x, ok := key.X()
150+
if !ok {
151+
return nil, fmt.Errorf(`missing "x" field`)
152+
}
153+
if len(x) != ed448.PublicKeySize {
154+
return nil, fmt.Errorf(`ed448: wrong public key size %d (expected %d)`, len(x), ed448.PublicKeySize)
155+
}
156+
return ed448.PublicKey(x), nil
157+
default:
158+
return nil, jwk.ContinueError()
146159
}
147-
return ret, nil
148160
}
149161

150162
// --- JWK raw key import ---

ed448_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ func TestEd448JWKRoundtrip(t *testing.T) {
112112
require.Equal(t, priv.Seed(), exported.Seed())
113113
})
114114
}
115+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.25.0
44

55
require (
66
github.com/cloudflare/circl v1.6.3
7-
github.com/lestrrat-go/jwx/v3 v3.0.14-0.20260401120942-afa5b058da4f
7+
github.com/lestrrat-go/jwx/v3 v3.0.14-0.20260401135236-89c1d7848e6e
88
github.com/stretchr/testify v1.11.1
99
)
1010

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZ
1717
github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E=
1818
github.com/lestrrat-go/httprc/v3 v3.0.5 h1:S+Mb4L2I+bM6JGTibLmxExhyTOqnXjqx+zi9MoXw/TM=
1919
github.com/lestrrat-go/httprc/v3 v3.0.5/go.mod h1:mSMtkZW92Z98M5YoNNztbRGxbXHql7tSitCvaxvo9l0=
20-
github.com/lestrrat-go/jwx/v3 v3.0.14-0.20260401120942-afa5b058da4f h1:K86lFdx4kZMoFIcp7h8uKIYCzvyVVc6yl1kJR4LS15Q=
21-
github.com/lestrrat-go/jwx/v3 v3.0.14-0.20260401120942-afa5b058da4f/go.mod h1:vuqP7b/QKMjPSwaYSFxZNfIVxm7OreavgfKUjkw4gjY=
20+
github.com/lestrrat-go/jwx/v3 v3.0.14-0.20260401135236-89c1d7848e6e h1:GFSbTQz4VvJP1ZJ6lTUdOedHm7rCdSa8IpPHLYGeBrE=
21+
github.com/lestrrat-go/jwx/v3 v3.0.14-0.20260401135236-89c1d7848e6e/go.mod h1:vuqP7b/QKMjPSwaYSFxZNfIVxm7OreavgfKUjkw4gjY=
2222
github.com/lestrrat-go/option/v2 v2.0.0 h1:XxrcaJESE1fokHy3FpaQ/cXW8ZsIdWcdFzzLOcID3Ss=
2323
github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg=
2424
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)