Skip to content

Commit 54214e2

Browse files
committed
Refactor key provider interfaces in JWT utilities
1 parent 437e587 commit 54214e2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

coderd/jwtutils/jwe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ const (
1616
encryptContentAlgo = jose.A256GCM
1717
)
1818

19-
type EncryptKeyer interface {
19+
type EncryptKeyProvider interface {
2020
EncryptingKey(ctx context.Context) (id string, key interface{}, err error)
2121
}
2222

23-
type DecryptKeyer interface {
23+
type DecryptKeyProvider interface {
2424
DecryptingKey(ctx context.Context, id string) (key interface{}, err error)
2525
}
2626

2727
// Encrypt encrypts a token and returns it as a string.
28-
func Encrypt(ctx context.Context, e EncryptKeyer, claims Claims) (string, error) {
28+
func Encrypt(ctx context.Context, e EncryptKeyProvider, claims Claims) (string, error) {
2929
id, key, err := e.EncryptingKey(ctx)
3030
if err != nil {
3131
return "", xerrors.Errorf("get signing key: %w", err)
@@ -72,7 +72,7 @@ type DecryptOptions struct {
7272
}
7373

7474
// Decrypt decrypts the token using the provided key. It unmarshals into the provided claims.
75-
func Decrypt(ctx context.Context, d DecryptKeyer, token string, claims Claims, opts ...func(*DecryptOptions)) error {
75+
func Decrypt(ctx context.Context, d DecryptKeyProvider, token string, claims Claims, opts ...func(*DecryptOptions)) error {
7676
options := DecryptOptions{
7777
RegisteredClaims: jwt.Expected{
7878
Time: time.Now(),

coderd/jwtutils/jws.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ const (
2424
signingAlgo = jose.HS512
2525
)
2626

27-
type SignKeyer interface {
27+
type SigningKeyProvider interface {
2828
SigningKey(ctx context.Context) (id string, key interface{}, err error)
2929
}
3030

31-
type VerifyKeyer interface {
31+
type VerifyKeyProvider interface {
3232
VerifyingKey(ctx context.Context, id string) (key interface{}, err error)
3333
}
3434

3535
// Sign signs a token and returns it as a string.
36-
func Sign(ctx context.Context, s SignKeyer, claims Claims) (string, error) {
36+
func Sign(ctx context.Context, s SigningKeyProvider, claims Claims) (string, error) {
3737
id, key, err := s.SigningKey(ctx)
3838
if err != nil {
3939
return "", xerrors.Errorf("get signing key: %w", err)
@@ -78,7 +78,7 @@ type VerifyOptions struct {
7878
}
7979

8080
// Verify verifies that a token was signed by the provided key. It unmarshals into the provided claims.
81-
func Verify(ctx context.Context, v VerifyKeyer, token string, claims Claims, opts ...func(*VerifyOptions)) error {
81+
func Verify(ctx context.Context, v VerifyKeyProvider, token string, claims Claims, opts ...func(*VerifyOptions)) error {
8282
options := VerifyOptions{
8383
RegisteredClaims: jwt.Expected{
8484
Time: time.Now(),

0 commit comments

Comments
 (0)