@@ -23,6 +23,8 @@ use std::thread;
2323use cryptoki:: mechanism:: ekdf:: AesCbcDeriveParams ;
2424use testresult:: TestResult ;
2525
26+ const AES128_BLOCK_SIZE : usize = 128 / 8 ;
27+
2628#[ test]
2729#[ serial]
2830fn sign_verify ( ) -> TestResult {
@@ -446,7 +448,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
446448 let template = vec ! [
447449 Attribute :: Token ( true ) ,
448450 Attribute :: Private ( false ) ,
449- Attribute :: ValueLen ( ( 128 / 8 ) . into( ) ) ,
451+ Attribute :: ValueLen ( ( AES128_BLOCK_SIZE as u64 ) . into( ) ) ,
450452 Attribute :: Encrypt ( true ) ,
451453 Attribute :: Decrypt ( true ) ,
452454 ] ;
@@ -455,14 +457,16 @@ fn encrypt_decrypt_multipart() -> TestResult {
455457 // Data to encrypt
456458 let data = vec ! [
457459 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 ,
458- 0x77 ,
460+ 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 ,
461+ 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB , 0x33 , 0x99 , 0x77 , 0xFF , 0x55 , 0xDD , 0x11 , 0xBB ,
462+ 0x33 , 0x99 , 0x77 ,
459463 ] ;
460464
461- // Encrypt data in parts
465+ // // Encrypt data in parts
462466 session. encrypt_init ( & Mechanism :: AesEcb , key) ?;
463467
464468 let mut encrypted_data = vec ! [ ] ;
465- for part in data. chunks ( 3 ) {
469+ for part in data. chunks ( AES128_BLOCK_SIZE ) {
466470 encrypted_data. extend ( session. encrypt_update ( part) ?) ;
467471 }
468472 encrypted_data. extend ( session. encrypt_final ( ) ?) ;
@@ -471,7 +475,7 @@ fn encrypt_decrypt_multipart() -> TestResult {
471475 session. decrypt_init ( & Mechanism :: AesEcb , key) ?;
472476
473477 let mut decrypted_data = vec ! [ ] ;
474- for part in encrypted_data. chunks ( 3 ) {
478+ for part in encrypted_data. chunks ( AES128_BLOCK_SIZE ) {
475479 decrypted_data. extend ( session. decrypt_update ( part) ?) ;
476480 }
477481 decrypted_data. extend ( session. decrypt_final ( ) ?) ;
@@ -555,7 +559,7 @@ fn encrypt_decrypt_multipart_already_initialized() -> TestResult {
555559 let template = vec ! [
556560 Attribute :: Token ( true ) ,
557561 Attribute :: Private ( false ) ,
558- Attribute :: ValueLen ( ( 128 / 8 ) . into( ) ) ,
562+ Attribute :: ValueLen ( ( AES128_BLOCK_SIZE as u64 ) . into( ) ) ,
559563 Attribute :: Encrypt ( true ) ,
560564 Attribute :: Decrypt ( true ) ,
561565 ] ;
0 commit comments