Skip to content

Commit

Permalink
Merge pull request #12 from skynet2/support-rsa-2
Browse files Browse the repository at this point in the history
fix: did rsa create
  • Loading branch information
fqutishat authored Feb 15, 2024
2 parents 7a38a93 + f25c1c1 commit 850e27c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/jws/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type JWK struct {
Crv string `json:"crv"`
X string `json:"x"`
Y string `json:"y"`
N string `json:"n,omitempty"`
E string `json:"e,omitempty"`
Nonce string `json:"nonce,omitempty"`
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/jwsutil/jws_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"
"encoding/base64"
"errors"
"fmt"
Expand Down Expand Up @@ -253,6 +254,18 @@ func TestParseJWS_ED25519(t *testing.T) {
require.Equal(t, jws, parsedJWS)
}

func TestParseJWS_RSA(t *testing.T) {
key, err := rsa.GenerateKey(rand.Reader, 2048)
require.NoError(t, err)

jwk, err := getPublicKeyJWK(&key.PublicKey)
require.NoError(t, err)

require.Equal(t, "RSA", jwk.Kty)
require.NotEmpty(t, jwk.E)
require.NotEmpty(t, jwk.N)
}

func TestIsCompactJWS(t *testing.T) {
require.True(t, IsCompactJWS("a.b.c"))
require.False(t, IsCompactJWS("a.b"))
Expand Down
3 changes: 2 additions & 1 deletion pkg/jwsutil/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"crypto/ed25519"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -257,7 +258,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 := pubKey.(*ecdsa.PublicKey)
Expand Down

0 comments on commit 850e27c

Please sign in to comment.