Skip to content

Commit f2c18b9

Browse files
committed
Refactor keyset package to provide JWKS handling and remove unused keyset code
1 parent f3f5cbc commit f2c18b9

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

cache/cache.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package cache provides a thread-safe in-memory cache for storing public keys.
2+
// It allows adding and retrieving public keys using their key IDs.
3+
// It also provides a no-operation cache implementation that does not store any keys.
14
package cache
25

36
import (
File renamed without changes.

signer.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package tokenbridge
33
import (
44
"context"
55
"crypto/ecdsa"
6-
"crypto/elliptic"
76
"crypto/rsa"
87
"encoding/base64"
98
"fmt"
@@ -190,29 +189,15 @@ func (s *ecSigner) GetJWKS(_ context.Context) (*keyset.JWKS, error) {
190189
x := base64.RawURLEncoding.EncodeToString(s.publicKey.X.Bytes())
191190
y := base64.RawURLEncoding.EncodeToString(s.publicKey.Y.Bytes())
192191

193-
// Determine the curve name
194-
var crv string
195-
196-
switch s.publicKey.Curve {
197-
case elliptic.P256():
198-
crv = "P-256"
199-
case elliptic.P384():
200-
crv = "P-384"
201-
case elliptic.P521():
202-
crv = "P-521"
203-
default:
204-
return nil, fmt.Errorf("unsupported elliptic curve")
205-
}
206-
207192
// Create the JWK for the EC public key
208193
jwk := keyset.JWK{
209194
Kty: "EC", // Key type
210195
Alg: s.signingMethod.Alg(),
211196
Use: "sig", // Key usage (signature)
212197
Kid: s.keyID,
213-
Crv: crv, // Curve name
214-
X: x, // X coordinate
215-
Y: y, // Y coordinate
198+
Crv: s.publicKey.Curve.Params().Name, // Curve name
199+
X: x, // X coordinate
200+
Y: y, // Y coordinate
216201
}
217202

218203
return &keyset.JWKS{Keys: []keyset.JWK{jwk}}, nil

signer/signer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package signer provides a simple interface for signing and verifying messages.
2+
// It supports different signing algorithms and key management systems.
3+
package signer

0 commit comments

Comments
 (0)