Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: did rsa create #12

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading