Skip to content

Commit f0e9e21

Browse files
Matched against generic PKCS#11 error instead of specific one, in tests
Signed-off-by: Jacob Prud'homme <2160185+jacobprudhomme@users.noreply.github.com>
1 parent b2e490b commit f0e9e21

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

cryptoki/tests/basic.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,36 +283,40 @@ fn sign_verify_multipart_not_initialized() -> TestResult {
283283
let result = session.sign_update(&data);
284284

285285
assert!(result.is_err());
286+
// The exact error returned is inconsistent between backends, so we only match on the function
286287
assert!(matches!(
287288
result.unwrap_err(),
288-
Error::Pkcs11(RvError::OperationNotInitialized, Function::SignUpdate)
289+
Error::Pkcs11(_, Function::SignUpdate)
289290
));
290291

291292
// Attempt to finalize signing without an operation having been initialized
292293
let result = session.sign_final();
293294

294295
assert!(result.is_err());
296+
// The exact error returned is inconsistent between backends, so we only match on the function
295297
assert!(matches!(
296298
result.unwrap_err(),
297-
Error::Pkcs11(RvError::OperationNotInitialized, Function::SignFinal)
299+
Error::Pkcs11(_, Function::SignFinal)
298300
));
299301

300302
// Attempt to update verification without an operation having been initialized
301303
let result = session.verify_update(&data);
302304

303305
assert!(result.is_err());
306+
// The exact error returned is inconsistent between backends, so we only match on the function
304307
assert!(matches!(
305308
result.unwrap_err(),
306-
Error::Pkcs11(RvError::OperationNotInitialized, Function::VerifyUpdate)
309+
Error::Pkcs11(_, Function::VerifyUpdate)
307310
));
308311

309312
// Attempt to finalize verification without an operation having been initialized
310313
let result = session.verify_final(&signature);
311314

312315
assert!(result.is_err());
316+
// The exact error returned is inconsistent between backends, so we only match on the function
313317
assert!(matches!(
314318
result.unwrap_err(),
315-
Error::Pkcs11(RvError::OperationNotInitialized, Function::VerifyFinal)
319+
Error::Pkcs11(_, Function::VerifyFinal)
316320
));
317321

318322
Ok(())
@@ -499,36 +503,40 @@ fn encrypt_decrypt_multipart_not_initialized() -> TestResult {
499503
let result = session.encrypt_update(&data);
500504

501505
assert!(result.is_err());
506+
// The exact error returned is inconsistent between backends, so we only match on the function
502507
assert!(matches!(
503508
result.unwrap_err(),
504-
Error::Pkcs11(RvError::OperationNotInitialized, Function::EncryptUpdate)
509+
Error::Pkcs11(_, Function::EncryptUpdate)
505510
));
506511

507512
// Attempt to finalize encryption without an operation having been initialized
508513
let result = session.encrypt_final();
509514

510515
assert!(result.is_err());
516+
// The exact error returned is inconsistent between backends, so we only match on the function
511517
assert!(matches!(
512518
result.unwrap_err(),
513-
Error::Pkcs11(RvError::OperationNotInitialized, Function::EncryptFinal)
519+
Error::Pkcs11(_, Function::EncryptFinal)
514520
));
515521

516522
// Attempt to update decryption without an operation having been initialized
517523
let result = session.decrypt_update(&data);
518524

519525
assert!(result.is_err());
526+
// The exact error returned is inconsistent between backends, so we only match on the function
520527
assert!(matches!(
521528
result.unwrap_err(),
522-
Error::Pkcs11(RvError::OperationNotInitialized, Function::DecryptUpdate)
529+
Error::Pkcs11(_, Function::DecryptUpdate)
523530
));
524531

525532
// Attempt to finalize decryption without an operation having been initialized
526533
let result = session.decrypt_final();
527534

528535
assert!(result.is_err());
536+
// The exact error returned is inconsistent between backends, so we only match on the function
529537
assert!(matches!(
530538
result.unwrap_err(),
531-
Error::Pkcs11(RvError::OperationNotInitialized, Function::DecryptFinal)
539+
Error::Pkcs11(_, Function::DecryptFinal)
532540
));
533541

534542
Ok(())
@@ -1718,18 +1726,20 @@ fn sha256_digest_multipart_not_initialized() -> TestResult {
17181726
let result = session.digest_update(&data);
17191727

17201728
assert!(result.is_err());
1729+
// The exact error returned is inconsistent between backends, so we only match on the function
17211730
assert!(matches!(
17221731
result.unwrap_err(),
1723-
Error::Pkcs11(RvError::OperationNotInitialized, Function::DigestUpdate)
1732+
Error::Pkcs11(_, Function::DigestUpdate)
17241733
));
17251734

17261735
// Attempt to finalize digest without an operation having been initialized
17271736
let result = session.digest_final();
17281737

17291738
assert!(result.is_err());
1739+
// The exact error returned is inconsistent between backends, so we only match on the function
17301740
assert!(matches!(
17311741
result.unwrap_err(),
1732-
Error::Pkcs11(RvError::OperationNotInitialized, Function::DigestFinal)
1742+
Error::Pkcs11(_, Function::DigestFinal)
17331743
));
17341744

17351745
Ok(())

0 commit comments

Comments
 (0)