Skip to content

Commit 51a9e98

Browse files
committed
tests: Add missing usage attributes
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
1 parent b8ba7b1 commit 51a9e98

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

cryptoki/tests/basic.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ fn sign_verify() -> TestResult {
4646
Attribute::Private(false),
4747
Attribute::PublicExponent(public_exponent),
4848
Attribute::ModulusBits(modulus_bits.into()),
49+
Attribute::Verify(true),
4950
];
5051

5152
// priv key template
52-
let priv_key_template = vec![Attribute::Token(true)];
53+
let priv_key_template = vec![Attribute::Token(true), Attribute::Sign(true)];
5354

5455
// generate a key pair
5556
let (public, private) =
@@ -93,7 +94,7 @@ fn sign_verify_eddsa() -> TestResult {
9394
]),
9495
];
9596

96-
let priv_key_template = vec![Attribute::Token(true)];
97+
let priv_key_template = vec![Attribute::Token(true), Attribute::Sign(true)];
9798

9899
let (public, private) =
99100
session.generate_key_pair(&mechanism, &pub_key_template, &priv_key_template)?;
@@ -136,7 +137,7 @@ fn sign_verify_eddsa_with_ed25519_schemes() -> TestResult {
136137
]),
137138
];
138139

139-
let priv_key_template = vec![Attribute::Token(true)];
140+
let priv_key_template = vec![Attribute::Token(true), Attribute::Sign(true)];
140141

141142
let (public, private) =
142143
session.generate_key_pair(&mechanism, &pub_key_template, &priv_key_template)?;
@@ -186,7 +187,7 @@ fn sign_verify_eddsa_with_ed448_schemes() -> TestResult {
186187
]),
187188
];
188189

189-
let priv_key_template = vec![Attribute::Token(true)];
190+
let priv_key_template = vec![Attribute::Token(true), Attribute::Sign(true)];
190191

191192
let (public, private) =
192193
session.generate_key_pair(&mechanism, &pub_key_template, &priv_key_template)?;
@@ -1353,9 +1354,16 @@ fn rsa_pkcs_oaep_empty() -> TestResult {
13531354
let session = pkcs11.open_rw_session(slot)?;
13541355
session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into())))?;
13551356

1356-
let pub_key_template = [Attribute::ModulusBits(2048.into())];
1357-
let (pubkey, privkey) =
1358-
session.generate_key_pair(&Mechanism::RsaPkcsKeyPairGen, &pub_key_template, &[])?;
1357+
let pub_key_template = [
1358+
Attribute::ModulusBits(2048.into()),
1359+
Attribute::Encrypt(true),
1360+
];
1361+
let priv_key_template = [Attribute::Decrypt(true)];
1362+
let (pubkey, privkey) = session.generate_key_pair(
1363+
&Mechanism::RsaPkcsKeyPairGen,
1364+
&pub_key_template,
1365+
&priv_key_template,
1366+
)?;
13591367
let oaep = PkcsOaepParams::new(
13601368
MechanismType::SHA1,
13611369
PkcsMgfType::MGF1_SHA1,
@@ -1380,9 +1388,16 @@ fn rsa_pkcs_oaep_with_data() -> TestResult {
13801388
let session = pkcs11.open_rw_session(slot)?;
13811389
session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into())))?;
13821390

1383-
let pub_key_template = [Attribute::ModulusBits(2048.into())];
1384-
let (pubkey, privkey) =
1385-
session.generate_key_pair(&Mechanism::RsaPkcsKeyPairGen, &pub_key_template, &[])?;
1391+
let pub_key_template = [
1392+
Attribute::ModulusBits(2048.into()),
1393+
Attribute::Encrypt(true),
1394+
];
1395+
let priv_key_template = vec![Attribute::Decrypt(true)];
1396+
let (pubkey, privkey) = session.generate_key_pair(
1397+
&Mechanism::RsaPkcsKeyPairGen,
1398+
&pub_key_template,
1399+
&priv_key_template,
1400+
)?;
13861401
let oaep = PkcsOaepParams::new(
13871402
MechanismType::SHA1,
13881403
PkcsMgfType::MGF1_SHA1,
@@ -1523,6 +1538,7 @@ fn sign_verify_sha1_hmac() -> TestResult {
15231538
Attribute::Private(true),
15241539
Attribute::Sensitive(true),
15251540
Attribute::Sign(true),
1541+
Attribute::Verify(true),
15261542
Attribute::KeyType(KeyType::GENERIC_SECRET),
15271543
Attribute::Class(ObjectClass::SECRET_KEY),
15281544
Attribute::ValueLen(256.into()),
@@ -1552,6 +1568,7 @@ fn sign_verify_sha224_hmac() -> TestResult {
15521568
Attribute::Private(true),
15531569
Attribute::Sensitive(true),
15541570
Attribute::Sign(true),
1571+
Attribute::Verify(true),
15551572
Attribute::KeyType(KeyType::GENERIC_SECRET),
15561573
Attribute::Class(ObjectClass::SECRET_KEY),
15571574
Attribute::ValueLen(256.into()),
@@ -1581,6 +1598,7 @@ fn sign_verify_sha256_hmac() -> TestResult {
15811598
Attribute::Private(true),
15821599
Attribute::Sensitive(true),
15831600
Attribute::Sign(true),
1601+
Attribute::Verify(true),
15841602
Attribute::KeyType(KeyType::GENERIC_SECRET),
15851603
Attribute::Class(ObjectClass::SECRET_KEY),
15861604
Attribute::ValueLen(256.into()),
@@ -1610,6 +1628,7 @@ fn sign_verify_sha384_hmac() -> TestResult {
16101628
Attribute::Private(true),
16111629
Attribute::Sensitive(true),
16121630
Attribute::Sign(true),
1631+
Attribute::Verify(true),
16131632
Attribute::KeyType(KeyType::GENERIC_SECRET),
16141633
Attribute::Class(ObjectClass::SECRET_KEY),
16151634
Attribute::ValueLen(256.into()),
@@ -1639,6 +1658,7 @@ fn sign_verify_sha512_hmac() -> TestResult {
16391658
Attribute::Private(true),
16401659
Attribute::Sensitive(true),
16411660
Attribute::Sign(true),
1661+
Attribute::Verify(true),
16421662
Attribute::KeyType(KeyType::GENERIC_SECRET),
16431663
Attribute::Class(ObjectClass::SECRET_KEY),
16441664
Attribute::ValueLen(256.into()),

0 commit comments

Comments
 (0)