@@ -1309,20 +1309,18 @@ fn sha256_digest() -> TestResult {
1309
1309
fn sha256_digest_multipart ( ) -> TestResult {
1310
1310
let ( pkcs11, slot) = init_pins ( ) ;
1311
1311
1312
- // Open a session
1312
+ // Open a session and log in
1313
1313
let session = pkcs11. open_ro_session ( slot) ?;
1314
-
1315
- // Log into the session
1316
1314
session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
1317
1315
1318
1316
// 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 ] ;
1321
1318
1322
1319
// Digest data in parts
1323
1320
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
+ }
1326
1324
1327
1325
let have = session. digest_finalize ( ) ?;
1328
1326
let want = vec ! [
@@ -1341,10 +1339,8 @@ fn sha256_digest_multipart() -> TestResult {
1341
1339
fn sha256_digest_multipart_with_key ( ) -> TestResult {
1342
1340
let ( pkcs11, slot) = init_pins ( ) ;
1343
1341
1344
- // Open a session
1342
+ // Open a session and log in
1345
1343
let session = pkcs11. open_rw_session ( slot) ?;
1346
-
1347
- // Log into the session
1348
1344
session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
1349
1345
1350
1346
// Create a key to add to the digest
@@ -1380,6 +1376,9 @@ fn sha256_digest_multipart_with_key() -> TestResult {
1380
1376
1381
1377
assert_eq ! ( have, want) ;
1382
1378
1379
+ // Delete key
1380
+ session. destroy_object ( key) ?;
1381
+
1383
1382
Ok ( ( ) )
1384
1383
}
1385
1384
@@ -1388,10 +1387,8 @@ fn sha256_digest_multipart_with_key() -> TestResult {
1388
1387
fn sha256_digest_multipart_not_initialized ( ) -> TestResult {
1389
1388
let ( pkcs11, slot) = init_pins ( ) ;
1390
1389
1391
- // Open a session
1390
+ // Open a session and log in
1392
1391
let session = pkcs11. open_ro_session ( slot) ?;
1393
-
1394
- // Log into the session
1395
1392
session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
1396
1393
1397
1394
// Data to digest
@@ -1423,10 +1420,8 @@ fn sha256_digest_multipart_not_initialized() -> TestResult {
1423
1420
fn sha256_digest_multipart_already_initialized ( ) -> TestResult {
1424
1421
let ( pkcs11, slot) = init_pins ( ) ;
1425
1422
1426
- // Open a session
1423
+ // Open a session and log in
1427
1424
let session = pkcs11. open_ro_session ( slot) ?;
1428
-
1429
- // Log into the session
1430
1425
session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
1431
1426
1432
1427
// Initialize digesting operation twice in a row
0 commit comments