@@ -31,7 +31,9 @@ impl<'a> GcmParams<'a> {
31
31
/// `tag_bits` - The length, in **bits**, of the authentication tag. Must
32
32
/// be between 0 and 128. The tag is appended to the end of the
33
33
/// ciphertext.
34
- ///
34
+ /// # Errors
35
+ /// This function returns an error if the length of `iv` or `aad` does not
36
+ /// fit into an [Ulong].
35
37
pub fn new ( iv : & ' a mut [ u8 ] , aad : & ' a [ u8 ] , tag_bits : Ulong ) -> Result < Self , & ' a str > {
36
38
// The ulIvBits parameter seems to be missing from the 2.40 spec,
37
39
// although it is included in the header file. In [1], OASIS clarified
@@ -52,7 +54,7 @@ impl<'a> GcmParams<'a> {
52
54
53
55
let iv_len = iv. len ( ) ;
54
56
// Some HSMs may require the ulIvBits field to be populated, while others don't pay attention to it.
55
- let iv_bit_len = iv_len* 8 ;
57
+ let iv_bit_len = iv_len * 8 ;
56
58
57
59
Ok ( GcmParams {
58
60
inner : CK_GCM_PARAMS {
@@ -65,9 +67,7 @@ impl<'a> GcmParams<'a> {
65
67
// If the HSM doesn't require the field, it won't mind; and it it does, it would break anyways.
66
68
ulIvBits : iv_bit_len. try_into ( ) . unwrap_or_default ( ) ,
67
69
pAAD : aad. as_ptr ( ) as * mut _ ,
68
- ulAADLen : match aad
69
- . len ( )
70
- . try_into ( ) {
70
+ ulAADLen : match aad. len ( ) . try_into ( ) {
71
71
Ok ( len) => len,
72
72
Err ( _e) => return Err ( "aad length does not fit in CK_ULONG" ) ,
73
73
} ,
0 commit comments