Skip to content

Commit 334bc5e

Browse files
Cleaned up tests a bit
Signed-off-by: Jacob Prud'homme <[email protected]>
1 parent 69632a6 commit 334bc5e

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

cryptoki/tests/basic.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,20 +1309,18 @@ fn sha256_digest() -> TestResult {
13091309
fn sha256_digest_multipart() -> TestResult {
13101310
let (pkcs11, slot) = init_pins();
13111311

1312-
// Open a session
1312+
// Open a session and log in
13131313
let session = pkcs11.open_ro_session(slot)?;
1314-
1315-
// Log into the session
13161314
session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into())))?;
13171315

13181316
// Data to digest
1319-
let data1 = vec![0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF];
1320-
let data2 = vec![0x66, 0x55, 0x44, 0x33, 0x22, 0x11];
1317+
let data = vec![0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11];
13211318

13221319
// Digest data in parts
13231320
session.digest_initialize(&Mechanism::Sha256)?;
1324-
session.digest_update(&data1)?;
1325-
session.digest_update(&data2)?;
1321+
for part in data.chunks(3) {
1322+
session.digest_update(part)?;
1323+
}
13261324

13271325
let have = session.digest_finalize()?;
13281326
let want = vec![
@@ -1341,10 +1339,8 @@ fn sha256_digest_multipart() -> TestResult {
13411339
fn sha256_digest_multipart_with_key() -> TestResult {
13421340
let (pkcs11, slot) = init_pins();
13431341

1344-
// Open a session
1342+
// Open a session and log in
13451343
let session = pkcs11.open_rw_session(slot)?;
1346-
1347-
// Log into the session
13481344
session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into())))?;
13491345

13501346
// Create a key to add to the digest
@@ -1380,6 +1376,9 @@ fn sha256_digest_multipart_with_key() -> TestResult {
13801376

13811377
assert_eq!(have, want);
13821378

1379+
// Delete key
1380+
session.destroy_object(key)?;
1381+
13831382
Ok(())
13841383
}
13851384

@@ -1388,10 +1387,8 @@ fn sha256_digest_multipart_with_key() -> TestResult {
13881387
fn sha256_digest_multipart_not_initialized() -> TestResult {
13891388
let (pkcs11, slot) = init_pins();
13901389

1391-
// Open a session
1390+
// Open a session and log in
13921391
let session = pkcs11.open_ro_session(slot)?;
1393-
1394-
// Log into the session
13951392
session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into())))?;
13961393

13971394
// Data to digest
@@ -1423,10 +1420,8 @@ fn sha256_digest_multipart_not_initialized() -> TestResult {
14231420
fn sha256_digest_multipart_already_initialized() -> TestResult {
14241421
let (pkcs11, slot) = init_pins();
14251422

1426-
// Open a session
1423+
// Open a session and log in
14271424
let session = pkcs11.open_ro_session(slot)?;
1428-
1429-
// Log into the session
14301425
session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into())))?;
14311426

14321427
// Initialize digesting operation twice in a row

0 commit comments

Comments
 (0)