Skip to content

Commit a3a791f

Browse files
Jason Parkerjaeparker22
authored andcommitted
Changed GcmParams::new to use cryptoki::error::Error rather than a string.
Signed-off-by: Jason Parker <[email protected]>
1 parent bf1e682 commit a3a791f

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

cryptoki/src/mechanism/aead.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//! AEAD block cipher mechanism types
44
5+
use crate::error::Error;
56
use crate::types::Ulong;
67
use cryptoki_sys::*;
78
use std::convert::TryInto;
@@ -34,7 +35,7 @@ impl<'a> GcmParams<'a> {
3435
/// # Errors
3536
/// This function returns an error if the length of `iv` or `aad` does not
3637
/// fit into an [Ulong].
37-
pub fn new(iv: &'a mut [u8], aad: &'a [u8], tag_bits: Ulong) -> Result<Self, &'a str> {
38+
pub fn new(iv: &'a mut [u8], aad: &'a [u8], tag_bits: Ulong) -> Result<Self, Error> {
3839
// The ulIvBits parameter seems to be missing from the 2.40 spec,
3940
// although it is included in the header file. In [1], OASIS clarified
4041
// that the header file is normative. In 3.0, they added the parameter
@@ -59,18 +60,12 @@ impl<'a> GcmParams<'a> {
5960
Ok(GcmParams {
6061
inner: CK_GCM_PARAMS {
6162
pIv: iv.as_mut_ptr(),
62-
ulIvLen: match iv_len.try_into() {
63-
Ok(len) => len,
64-
Err(_e) => return Err("iv length does not fit in CK_ULONG"),
65-
},
63+
ulIvLen: iv_len.try_into()?,
6664
// Since this field isn't universally used, set it to 0 if it doesn't fit in CK_ULONG.
6765
// If the HSM doesn't require the field, it won't mind; and it it does, it would break anyways.
6866
ulIvBits: iv_bit_len.try_into().unwrap_or_default(),
6967
pAAD: aad.as_ptr() as *mut _,
70-
ulAADLen: match aad.len().try_into() {
71-
Ok(len) => len,
72-
Err(_e) => return Err("aad length does not fit in CK_ULONG"),
73-
},
68+
ulAADLen: aad.len().try_into()?,
7469
ulTagBits: tag_bits.into(),
7570
},
7671
_marker: PhantomData,

0 commit comments

Comments
 (0)