Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Jul 5, 2023
1 parent e0ec36d commit b6fb49d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 0 additions & 4 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,6 @@ func (k *Key) PrivateKey() (crypto.PrivateKey, error) {
return nil, err
}

if len(k.D) == 0 {
return nil, ErrNotPrivKey
}

switch alg {
case AlgorithmES256, AlgorithmES384, AlgorithmES512:
// RFC8152 allows omitting X and Y from private keys;
Expand Down
14 changes: 14 additions & 0 deletions key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ func TestKey_PrivateKey(t *testing.T) {
_, err = k.PrivateKey()
assertEqualError(t, err, ErrNotPrivKey.Error())

k.KeyType = KeyTypeEC2
k.Curve = CurveP256

_, err = k.PrivateKey()
assertEqualError(t, err, ErrNotPrivKey.Error())

k = Key{
KeyType: KeyTypeOKP,
Curve: CurveEd25519,
Expand All @@ -621,11 +627,19 @@ func TestKey_PrivateKey(t *testing.T) {
_, err = k.PrivateKey()
assertEqualError(t, err, ErrOKPNoPub.Error())

k.Curve = CurveInvalid
_, err = k.PrivateKey()
assertEqualError(t, err, ErrInvalidKey.Error())

k.KeyType = KeyTypeEC2
k.Curve = CurveP256

_, err = k.PrivateKey()
assertEqualError(t, err, ErrEC2NoPub.Error())

k.Curve = CurveInvalid
_, err = k.PrivateKey()
assertEqualError(t, err, ErrInvalidKey.Error())
}

func TestKey_PublicKey(t *testing.T) {
Expand Down

0 comments on commit b6fb49d

Please sign in to comment.