Skip to content

Commit

Permalink
fix: add missing switch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Jul 23, 2024
1 parent 6e94c8f commit fb88f32
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions internal/conf/jwk.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package conf

import (
"crypto/ecdh"
"crypto/ed25519"
"crypto/rsa"
"encoding/base64"
"encoding/json"
"fmt"

"github.com/golang-jwt/jwt/v5"
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwk"
)

Expand Down Expand Up @@ -101,20 +105,24 @@ func GetSigningJwk(config *JWTConfiguration) (*jwk.Key, error) {
}

func GetSigningKey(k *jwk.Key) (any, error) {
var key any
switch (*k).KeyType() {

Check failure on line 109 in internal/conf/jwk.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

missing cases in switch of type jwa.KeyType: jwa.InvalidKeyType
case "oct":
var symmetricKey []byte
if err := (*k).Raw(&symmetricKey); err != nil {
return nil, err
}
return symmetricKey, nil
case jwa.OctetSeq:
key = []byte{}
case jwa.EC:
key = ecdh.PrivateKey{}
case jwa.RSA:
key = rsa.PrivateKey{}
case jwa.OKP:
// OKP is used for EdDSA keys
key = ed25519.PrivateKey{}
default:
var key interface{}
if err := (*k).Raw(&key); err != nil {
return nil, err
}
return key, nil
return nil, jwt.ErrInvalidKeyType
}
if err := (*k).Raw(&key); err != nil {
return nil, err
}
return key, nil
}

func GetSigningAlg(k *jwk.Key) jwt.SigningMethod {
Expand Down

0 comments on commit fb88f32

Please sign in to comment.