Skip to content

Commit

Permalink
Merge pull request #11 from skynet2/support-rsa
Browse files Browse the repository at this point in the history
feat: add rsa support
  • Loading branch information
fqutishat authored Feb 15, 2024
2 parents 6f4f189 + 3871fda commit 7a38a93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/util/pubkey/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package pubkey
import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"errors"
"fmt"
"reflect"
Expand All @@ -33,7 +34,7 @@ func GetPublicKeyJWK(pubKey interface{}) (*jws.JWK, error) {
}

switch key := pubKey.(type) {
case ed25519.PublicKey:
case ed25519.PublicKey, *rsa.PublicKey:
// handled automatically by gojose
case *ecdsa.PublicKey:
ecdsaPubKey, ok := pubKey.(*ecdsa.PublicKey)
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/pubkey/jwk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"crypto/ed25519"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"testing"

"github.com/btcsuite/btcd/btcec/v2"
Expand All @@ -29,6 +30,17 @@ func TestGetPublicKeyJWK(t *testing.T) {
require.Equal(t, "EC", jwk.Kty)
})

t.Run("success RSA-2048", func(t *testing.T) {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
require.NoError(t, err)

jwk, err := GetPublicKeyJWK(&privateKey.PublicKey)
require.NoError(t, err)
require.NotEmpty(t, jwk)
require.Equal(t, "", jwk.Crv)
require.Equal(t, "RSA", jwk.Kty)
})

t.Run("success EC secp256k1 ", func(t *testing.T) {
privateKey, err := ecdsa.GenerateKey(btcec.S256(), rand.Reader)
require.NoError(t, err)
Expand Down

0 comments on commit 7a38a93

Please sign in to comment.