Skip to content

Commit d2e1a2e

Browse files
Apply suggestions from code review
Co-authored-by: Wiktor Kwapisiewicz <[email protected]>
1 parent 6524352 commit d2e1a2e

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

cryptoki/src/mechanism/aead.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ impl<'a> GcmParams<'a> {
6363
},
6464
// Since this field isn't universally used, set it to 0 if it doesn't fit in CK_ULONG.
6565
// If the HSM doesn't require the field, it won't mind; and it it does, it would break anyways.
66-
ulIvBits: match iv_bit_len.try_into() {
67-
Ok(len) => len,
68-
Err(_e) => 0,
69-
},
66+
ulIvBits: iv_bit_len.try_into().unwrap_or_default(),
7067
pAAD: aad.as_ptr() as *mut _,
7168
ulAADLen: match aad
7269
.len()

cryptoki/tests/basic.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,7 @@ fn gcm_param_graceful_failure() -> TestResult {
12791279
println!("iv");
12801280
let aad = [0; 16];
12811281

1282-
let _gcm_params = match GcmParams::new(&mut iv, &aad, 96.into()) {
1283-
Ok(params) => params,
1284-
Err(e) => {
1285-
println!("{e}");
1286-
return Err(e.into());
1287-
},
1288-
};
1282+
GcmParams::new(&mut iv, &aad, 96.into())?;
12891283

12901284
Ok(())
12911285
}
@@ -1317,7 +1311,7 @@ fn aes_gcm_no_aad() -> TestResult {
13171311
Attribute::Encrypt(true),
13181312
];
13191313
let key_handle = session.create_object(&template)?;
1320-
let mechanism = Mechanism::AesGcm(GcmParams::new(&mut iv, &aad, 96.into()).unwrap());
1314+
let mechanism = Mechanism::AesGcm(GcmParams::new(&mut iv, &aad, 96.into())?);
13211315
let cipher_and_tag = session.encrypt(&mechanism, key_handle, &plain)?;
13221316
assert_eq!(expected_cipher_and_tag[..], cipher_and_tag[..]);
13231317
Ok(())
@@ -1348,13 +1342,7 @@ fn aes_gcm_with_aad() -> TestResult {
13481342
Attribute::Encrypt(true),
13491343
];
13501344
let key_handle = session.create_object(&template)?;
1351-
let gcm_params = match GcmParams::new(&mut iv, &aad, 96.into()) {
1352-
Ok(params) => params,
1353-
Err(e) => {
1354-
println!("{e}");
1355-
return Err(e.into());
1356-
},
1357-
};
1345+
let gcm_params = match GcmParams::new(&mut iv, &aad, 96.into())?;
13581346
let mechanism = Mechanism::AesGcm(gcm_params);
13591347
let cipher_and_tag = session.encrypt(&mechanism, key_handle, &plain)?;
13601348
assert_eq!(expected_cipher_and_tag[..], cipher_and_tag[..]);

0 commit comments

Comments
 (0)