@@ -18,7 +18,7 @@ use cryptoki::object::{
1818 Attribute , AttributeInfo , AttributeType , KeyType , ObjectClass , ObjectHandle ,
1919} ;
2020use cryptoki:: session:: { SessionState , UserType } ;
21- use cryptoki:: types:: AuthPin ;
21+ use cryptoki:: types:: { AuthPin , Ulong } ;
2222use serial_test:: serial;
2323use std:: collections:: HashMap ;
2424use std:: num:: NonZeroUsize ;
@@ -27,8 +27,8 @@ use std::thread;
2727use cryptoki:: mechanism:: ekdf:: AesCbcDeriveParams ;
2828use testresult:: TestResult ;
2929
30- const AES128_BLOCK_SIZE : usize = 128 / 8 ;
31- const AES256_BLOCK_SIZE : usize = 256 / 8 ;
30+ const AES128_BLOCK_SIZE : Ulong = Ulong :: new ( 128 / 8 ) ;
31+ const AES256_BLOCK_SIZE : Ulong = Ulong :: new ( 256 / 8 ) ;
3232
3333#[ test]
3434#[ serial]
@@ -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 ) ,
459459 Attribute :: Encrypt ( true ) ,
460460 Attribute :: Decrypt ( true ) ,
461461 ] ;
@@ -473,7 +473,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
473473 session. encrypt_init ( & Mechanism :: AesEcb , key) ?;
474474
475475 let mut encrypted_data = vec ! [ ] ;
476- for part in data. chunks ( AES128_BLOCK_SIZE ) {
476+ for part in data. chunks ( AES128_BLOCK_SIZE . into ( ) ) {
477477 encrypted_data. extend ( session. encrypt_update ( part) ?) ;
478478 }
479479 encrypted_data. extend ( session. encrypt_final ( ) ?) ;
@@ -482,7 +482,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
482482 session. decrypt_init ( & Mechanism :: AesEcb , key) ?;
483483
484484 let mut decrypted_data = vec ! [ ] ;
485- for part in encrypted_data. chunks ( AES128_BLOCK_SIZE ) {
485+ for part in encrypted_data. chunks ( AES128_BLOCK_SIZE . into ( ) ) {
486486 decrypted_data. extend ( session. decrypt_update ( part) ?) ;
487487 }
488488 decrypted_data. extend ( session. decrypt_final ( ) ?) ;
@@ -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 ) ,
570570 Attribute :: Encrypt ( true ) ,
571571 Attribute :: Decrypt ( true ) ,
572572 ] ;
@@ -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 ,
@@ -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 ) ,
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 ) ,
@@ -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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
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 ) ,
32583258 Attribute :: Encrypt ( true ) ,
32593259 Attribute :: Decrypt ( true ) ,
32603260 ] ;
0 commit comments