Skip to content

Commit 63ad209

Browse files
committed
tests: 32b compatibility
Fixes: #282 Signed-off-by: Jakub Jelen <[email protected]>
1 parent 9d6fd32 commit 63ad209

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

cryptoki/tests/basic.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
455455
let template = vec![
456456
Attribute::Token(true),
457457
Attribute::Private(false),
458-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
458+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
459459
Attribute::Encrypt(true),
460460
Attribute::Decrypt(true),
461461
];
@@ -566,7 +566,7 @@ fn encrypt_decrypt_multipart_already_initialized() -> TestResult {
566566
let template = vec![
567567
Attribute::Token(true),
568568
Attribute::Private(false),
569-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
569+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
570570
Attribute::Encrypt(true),
571571
Attribute::Decrypt(true),
572572
];
@@ -775,7 +775,7 @@ fn session_find_objects() -> testresult::TestResult {
775775
Attribute::Token(true),
776776
Attribute::Encrypt(true),
777777
Attribute::Label(format!("key_{}", i).as_bytes().to_vec()),
778-
Attribute::ValueLen(32.into()),
778+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into().unwrap()),
779779
Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID
780780
];
781781

@@ -825,7 +825,7 @@ fn session_objecthandle_iterator() -> testresult::TestResult {
825825
let key_template = vec![
826826
Attribute::Token(true),
827827
Attribute::Encrypt(true),
828-
Attribute::ValueLen(32.into()),
828+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
829829
Attribute::Label(format!("key_{}", i).as_bytes().to_vec()),
830830
Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID
831831
];
@@ -915,7 +915,7 @@ fn wrap_and_unwrap_key() {
915915

916916
let key_to_be_wrapped_template = vec![
917917
Attribute::Token(true),
918-
Attribute::ValueLen(32.into()),
918+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into().unwrap()),
919919
// the key needs to be extractable to be suitable for being wrapped
920920
Attribute::Extractable(true),
921921
Attribute::Encrypt(true),
@@ -1197,7 +1197,7 @@ fn get_attribute_info_test() -> TestResult {
11971197
session.generate_key_pair(&mechanism, &pub_key_template, &priv_key_template)?;
11981198

11991199
let pub_attribs = vec![AttributeType::PublicExponent, AttributeType::Modulus];
1200-
let mut priv_attribs = [
1200+
let priv_attribs = [
12011201
AttributeType::PublicExponent,
12021202
AttributeType::Modulus,
12031203
AttributeType::PrivateExponent,
@@ -1369,7 +1369,7 @@ fn aes_key_attributes_test() -> TestResult {
13691369
Attribute::Class(ObjectClass::SECRET_KEY),
13701370
Attribute::Token(true),
13711371
Attribute::Sensitive(true),
1372-
Attribute::ValueLen(16.into()),
1372+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
13731373
Attribute::KeyType(KeyType::AES),
13741374
Attribute::Label(b"testAES".to_vec()),
13751375
Attribute::Private(true),
@@ -1465,7 +1465,7 @@ fn session_copy_object() -> TestResult {
14651465
Attribute::Private(true),
14661466
Attribute::Sensitive(true),
14671467
Attribute::Extractable(false),
1468-
Attribute::ValueLen(16.into()),
1468+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
14691469
Attribute::Label("original".as_bytes().to_vec()),
14701470
];
14711471

@@ -1678,7 +1678,7 @@ fn sha256_digest_multipart_with_key() -> TestResult {
16781678
let key_template = vec![
16791679
Attribute::Token(true),
16801680
Attribute::Private(false),
1681-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
1681+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
16821682
// Key must be non-sensitive and extractable to get its bytes and digest them directly, for comparison
16831683
Attribute::Sensitive(false),
16841684
Attribute::Extractable(true),
@@ -2119,7 +2119,7 @@ fn ekdf_aes_cbc_encrypt_data() -> TestResult {
21192119
Attribute::Token(true),
21202120
Attribute::Sensitive(true),
21212121
Attribute::Private(true),
2122-
Attribute::ValueLen(32.into()),
2122+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
21232123
Attribute::Derive(true),
21242124
];
21252125

@@ -2179,7 +2179,7 @@ fn kbkdf_counter_mode() -> TestResult {
21792179
let base_template = [
21802180
Attribute::Token(true),
21812181
Attribute::Private(false),
2182-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2182+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
21832183
Attribute::Derive(true),
21842184
];
21852185
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2190,7 +2190,7 @@ fn kbkdf_counter_mode() -> TestResult {
21902190
Attribute::Private(false),
21912191
Attribute::Class(ObjectClass::SECRET_KEY),
21922192
Attribute::KeyType(KeyType::AES),
2193-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2193+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
21942194
Attribute::Encrypt(true),
21952195
Attribute::Decrypt(true),
21962196
];
@@ -2234,7 +2234,7 @@ fn kbkdf_counter_mode() -> TestResult {
22342234
let wanted_attributes = [
22352235
Attribute::Class(ObjectClass::SECRET_KEY),
22362236
Attribute::KeyType(KeyType::AES),
2237-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2237+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
22382238
Attribute::Encrypt(true),
22392239
Attribute::Decrypt(true),
22402240
Attribute::Sign(false),
@@ -2272,7 +2272,7 @@ fn kbkdf_feedback_mode() -> TestResult {
22722272
let base_template = [
22732273
Attribute::Token(true),
22742274
Attribute::Private(false),
2275-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2275+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
22762276
Attribute::Derive(true),
22772277
];
22782278
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2283,7 +2283,7 @@ fn kbkdf_feedback_mode() -> TestResult {
22832283
Attribute::Private(false),
22842284
Attribute::Class(ObjectClass::SECRET_KEY),
22852285
Attribute::KeyType(KeyType::AES),
2286-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2286+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
22872287
Attribute::Encrypt(true),
22882288
Attribute::Decrypt(true),
22892289
];
@@ -2350,7 +2350,7 @@ fn kbkdf_feedback_mode() -> TestResult {
23502350
let wanted_attributes = [
23512351
Attribute::Class(ObjectClass::SECRET_KEY),
23522352
Attribute::KeyType(KeyType::AES),
2353-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2353+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
23542354
Attribute::Encrypt(true),
23552355
Attribute::Decrypt(true),
23562356
Attribute::Sign(false),
@@ -2389,7 +2389,7 @@ fn kbkdf_double_pipeline_mode() -> TestResult {
23892389
let base_template = [
23902390
Attribute::Token(true),
23912391
Attribute::Private(false),
2392-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2392+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
23932393
Attribute::Derive(true),
23942394
];
23952395
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2400,7 +2400,7 @@ fn kbkdf_double_pipeline_mode() -> TestResult {
24002400
Attribute::Private(false),
24012401
Attribute::Class(ObjectClass::SECRET_KEY),
24022402
Attribute::KeyType(KeyType::AES),
2403-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2403+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
24042404
Attribute::Encrypt(true),
24052405
Attribute::Decrypt(true),
24062406
];
@@ -2440,7 +2440,7 @@ fn kbkdf_double_pipeline_mode() -> TestResult {
24402440
let wanted_attributes = [
24412441
Attribute::Class(ObjectClass::SECRET_KEY),
24422442
Attribute::KeyType(KeyType::AES),
2443-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2443+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
24442444
Attribute::Encrypt(true),
24452445
Attribute::Decrypt(true),
24462446
Attribute::Sign(false),
@@ -2478,7 +2478,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
24782478
let base_template = [
24792479
Attribute::Token(true),
24802480
Attribute::Private(false),
2481-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2481+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
24822482
Attribute::Derive(true),
24832483
];
24842484
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2490,7 +2490,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
24902490
Attribute::Private(false),
24912491
Attribute::Class(ObjectClass::SECRET_KEY),
24922492
Attribute::KeyType(KeyType::AES),
2493-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2493+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
24942494
Attribute::Encrypt(true),
24952495
Attribute::Decrypt(true),
24962496
],
@@ -2499,7 +2499,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
24992499
Attribute::Private(false),
25002500
Attribute::Class(ObjectClass::SECRET_KEY),
25012501
Attribute::KeyType(KeyType::AES),
2502-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
2502+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
25032503
Attribute::Sign(true),
25042504
Attribute::Verify(true),
25052505
],
@@ -2570,7 +2570,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
25702570
vec![
25712571
Attribute::Class(ObjectClass::SECRET_KEY),
25722572
Attribute::KeyType(KeyType::AES),
2573-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2573+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
25742574
Attribute::Encrypt(true),
25752575
Attribute::Decrypt(true),
25762576
Attribute::Sign(false),
@@ -2580,7 +2580,7 @@ fn kbkdf_additional_keys_counter_mode() -> TestResult {
25802580
vec![
25812581
Attribute::Class(ObjectClass::SECRET_KEY),
25822582
Attribute::KeyType(KeyType::AES),
2583-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
2583+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
25842584
Attribute::Encrypt(false),
25852585
Attribute::Decrypt(false),
25862586
Attribute::Sign(true),
@@ -2634,7 +2634,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
26342634
let base_template = [
26352635
Attribute::Token(true),
26362636
Attribute::Private(false),
2637-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2637+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
26382638
Attribute::Derive(true),
26392639
];
26402640
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2646,7 +2646,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
26462646
Attribute::Private(false),
26472647
Attribute::Class(ObjectClass::SECRET_KEY),
26482648
Attribute::KeyType(KeyType::AES),
2649-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2649+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
26502650
Attribute::Encrypt(true),
26512651
Attribute::Decrypt(true),
26522652
],
@@ -2655,7 +2655,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
26552655
Attribute::Private(false),
26562656
Attribute::Class(ObjectClass::SECRET_KEY),
26572657
Attribute::KeyType(KeyType::AES),
2658-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
2658+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
26592659
Attribute::Sign(true),
26602660
Attribute::Verify(true),
26612661
],
@@ -2759,7 +2759,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
27592759
vec![
27602760
Attribute::Class(ObjectClass::SECRET_KEY),
27612761
Attribute::KeyType(KeyType::AES),
2762-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2762+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
27632763
Attribute::Encrypt(true),
27642764
Attribute::Decrypt(true),
27652765
Attribute::Sign(false),
@@ -2769,7 +2769,7 @@ fn kbkdf_additional_keys_feedback_mode() -> TestResult {
27692769
vec![
27702770
Attribute::Class(ObjectClass::SECRET_KEY),
27712771
Attribute::KeyType(KeyType::AES),
2772-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
2772+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
27732773
Attribute::Encrypt(false),
27742774
Attribute::Decrypt(false),
27752775
Attribute::Sign(true),
@@ -2819,7 +2819,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
28192819
let base_template = [
28202820
Attribute::Token(true),
28212821
Attribute::Private(false),
2822-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2822+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
28232823
Attribute::Derive(true),
28242824
];
28252825
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2831,7 +2831,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
28312831
Attribute::Private(false),
28322832
Attribute::Class(ObjectClass::SECRET_KEY),
28332833
Attribute::KeyType(KeyType::AES),
2834-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2834+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
28352835
Attribute::Encrypt(true),
28362836
Attribute::Decrypt(true),
28372837
],
@@ -2840,7 +2840,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
28402840
Attribute::Private(false),
28412841
Attribute::Class(ObjectClass::SECRET_KEY),
28422842
Attribute::KeyType(KeyType::AES),
2843-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
2843+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
28442844
Attribute::Sign(true),
28452845
Attribute::Verify(true),
28462846
],
@@ -2907,7 +2907,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
29072907
vec![
29082908
Attribute::Class(ObjectClass::SECRET_KEY),
29092909
Attribute::KeyType(KeyType::AES),
2910-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2910+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
29112911
Attribute::Encrypt(true),
29122912
Attribute::Decrypt(true),
29132913
Attribute::Sign(false),
@@ -2917,7 +2917,7 @@ fn kbkdf_additional_keys_double_pipeline_mode() -> TestResult {
29172917
vec![
29182918
Attribute::Class(ObjectClass::SECRET_KEY),
29192919
Attribute::KeyType(KeyType::AES),
2920-
Attribute::ValueLen((AES128_BLOCK_SIZE as u64).into()),
2920+
Attribute::ValueLen(AES128_BLOCK_SIZE.try_into()?),
29212921
Attribute::Encrypt(false),
29222922
Attribute::Decrypt(false),
29232923
Attribute::Sign(true),
@@ -2971,7 +2971,7 @@ fn kbkdf_invalid_data_params_counter_mode() -> TestResult {
29712971
let base_template = [
29722972
Attribute::Token(true),
29732973
Attribute::Private(false),
2974-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2974+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
29752975
Attribute::Derive(true),
29762976
];
29772977
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -2982,7 +2982,7 @@ fn kbkdf_invalid_data_params_counter_mode() -> TestResult {
29822982
Attribute::Private(false),
29832983
Attribute::Class(ObjectClass::SECRET_KEY),
29842984
Attribute::KeyType(KeyType::AES),
2985-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
2985+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
29862986
Attribute::Encrypt(true),
29872987
Attribute::Decrypt(true),
29882988
];
@@ -3120,7 +3120,7 @@ fn kbkdf_invalid_data_params_feedback_mode() -> TestResult {
31203120
let base_template = [
31213121
Attribute::Token(true),
31223122
Attribute::Private(false),
3123-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
3123+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
31243124
Attribute::Derive(true),
31253125
];
31263126
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -3131,7 +3131,7 @@ fn kbkdf_invalid_data_params_feedback_mode() -> TestResult {
31313131
Attribute::Private(false),
31323132
Attribute::Class(ObjectClass::SECRET_KEY),
31333133
Attribute::KeyType(KeyType::AES),
3134-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
3134+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
31353135
Attribute::Encrypt(true),
31363136
Attribute::Decrypt(true),
31373137
];
@@ -3243,7 +3243,7 @@ fn kbkdf_invalid_data_params_double_pipeline_mode() -> TestResult {
32433243
let base_template = [
32443244
Attribute::Token(true),
32453245
Attribute::Private(false),
3246-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
3246+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
32473247
Attribute::Derive(true),
32483248
];
32493249
let base_key = session.generate_key(&Mechanism::AesKeyGen, &base_template)?;
@@ -3254,7 +3254,7 @@ fn kbkdf_invalid_data_params_double_pipeline_mode() -> TestResult {
32543254
Attribute::Private(false),
32553255
Attribute::Class(ObjectClass::SECRET_KEY),
32563256
Attribute::KeyType(KeyType::AES),
3257-
Attribute::ValueLen((AES256_BLOCK_SIZE as u64).into()),
3257+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
32583258
Attribute::Encrypt(true),
32593259
Attribute::Decrypt(true),
32603260
];
@@ -3707,7 +3707,7 @@ fn unique_id() -> TestResult {
37073707

37083708
let generate_template = vec![
37093709
Attribute::Token(true),
3710-
Attribute::ValueLen(32.into()),
3710+
Attribute::ValueLen(AES256_BLOCK_SIZE.try_into()?),
37113711
Attribute::Encrypt(true),
37123712
];
37133713

0 commit comments

Comments
 (0)