2
2
// SPDX-License-Identifier: Apache-2.0
3
3
//! AEAD block cipher mechanism types
4
4
5
+ use crate :: error:: Error ;
5
6
use crate :: types:: Ulong ;
6
7
use cryptoki_sys:: * ;
7
8
use std:: convert:: TryInto ;
@@ -34,7 +35,7 @@ impl<'a> GcmParams<'a> {
34
35
/// # Errors
35
36
/// This function returns an error if the length of `iv` or `aad` does not
36
37
/// 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 > {
38
39
// The ulIvBits parameter seems to be missing from the 2.40 spec,
39
40
// although it is included in the header file. In [1], OASIS clarified
40
41
// that the header file is normative. In 3.0, they added the parameter
@@ -59,18 +60,12 @@ impl<'a> GcmParams<'a> {
59
60
Ok ( GcmParams {
60
61
inner : CK_GCM_PARAMS {
61
62
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 ( ) ?,
66
64
// Since this field isn't universally used, set it to 0 if it doesn't fit in CK_ULONG.
67
65
// If the HSM doesn't require the field, it won't mind; and it it does, it would break anyways.
68
66
ulIvBits : iv_bit_len. try_into ( ) . unwrap_or_default ( ) ,
69
67
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 ( ) ?,
74
69
ulTagBits : tag_bits. into ( ) ,
75
70
} ,
76
71
_marker : PhantomData ,
0 commit comments