Skip to content

Commit

Permalink
Merge pull request #57 from ThalesIgnite/key-list
Browse files Browse the repository at this point in the history
Finding multiple keys and accessing key attributes
  • Loading branch information
Duncan Jones authored Aug 22, 2019
2 parents 8367a3e + c074415 commit 8656b49
Show file tree
Hide file tree
Showing 9 changed files with 686 additions and 100 deletions.
30 changes: 30 additions & 0 deletions close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func TestClose(t *testing.T) {
require.NoError(t, err)

testDsaSigning(t, key2.(*pkcs11PrivateKeyDSA), pSize, fmt.Sprintf("close%d", i))

if i == 4 {
err = key2.Delete()
require.NoError(t, err)
}

require.NoError(t, ctx.Close())
}
}
Expand Down Expand Up @@ -83,9 +89,21 @@ func TestErrorAfterClosed(t *testing.T) {
_, err = ctx.FindKey(bytes, nil)
assert.Equal(t, errClosed, err)

_, err = ctx.FindKeys(bytes, nil)
assert.Equal(t, errClosed, err)

_, err = ctx.FindKeysWithAttributes(NewAttributeSet())
assert.Equal(t, errClosed, err)

_, err = ctx.FindKeyPair(bytes, nil)
assert.Equal(t, errClosed, err)

_, err = ctx.FindKeyPairs(bytes, nil)
assert.Equal(t, errClosed, err)

_, err = ctx.FindKeyPairsWithAttributes(NewAttributeSet())
assert.Equal(t, errClosed, err)

_, err = ctx.GenerateSecretKey(bytes, 256, CipherAES)
assert.Equal(t, errClosed, err)

Expand Down Expand Up @@ -123,4 +141,16 @@ func TestErrorAfterClosed(t *testing.T) {

err = ctx.ImportCertificateWithAttributes(NewAttributeSet(), cert)
assert.Equal(t, errClosed, err)

_, err = ctx.GetAttribute(nil, CkaLabel)
assert.Equal(t, errClosed, err)

_, err = ctx.GetAttributes(nil, []AttributeType{CkaLabel})
assert.Equal(t, errClosed, err)

_, err = ctx.GetPubAttribute(nil, CkaLabel)
assert.Equal(t, errClosed, err)

_, err = ctx.GetPubAttributes(nil, []AttributeType{CkaLabel})
assert.Equal(t, errClosed, err)
}
2 changes: 2 additions & 0 deletions dsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func TestHardDSA(t *testing.T) {
key, err := ctx.GenerateDSAKeyPairWithLabel(id, label, params)
require.NoError(t, err)
require.NotNil(t, key)
defer key.Delete()

testDsaSigning(t, key, pSize, "hard1")

key2, err := ctx.FindKeyPair(id, nil)
Expand Down
1 change: 1 addition & 0 deletions ecdsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestHardECDSA(t *testing.T) {
key, err := ctx.GenerateECDSAKeyPairWithLabel(id, label, curve)
require.NoError(t, err)
require.NotNil(t, key)
defer key.Delete()

testEcdsaSigning(t, key, crypto.SHA1)
testEcdsaSigning(t, key, crypto.SHA224)
Expand Down
1 change: 1 addition & 0 deletions hmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func testHmac(t *testing.T, ctx *Context, keytype int, mech int, length int, xle
key, err := ctx.GenerateSecretKey(id, 256, Ciphers[keytype])
require.NoError(t, err)
require.NotNil(t, key)
defer key.Delete()

t.Run("Short", func(t *testing.T) {
input := []byte("a short string")
Expand Down
Loading

0 comments on commit 8656b49

Please sign in to comment.