@@ -7,8 +7,8 @@ use std::borrow::Borrow;
7
7
use std:: io;
8
8
use std:: io:: { Error , ErrorKind } ;
9
9
10
- /// [`StorableBuilder`] is a helper utility to build and deconstruct [`Storable`] objects.
11
- /// It provides client-side ` Encrypt-then-MAC` using ChaCha20-Poly1305.
10
+ /// [`StorableBuilder`] is a utility to build and deconstruct [`Storable`] objects.
11
+ /// It provides client-side Encrypt-then-MAC using ChaCha20-Poly1305.
12
12
pub struct StorableBuilder {
13
13
data_encryption_key : [ u8 ; 32 ] ,
14
14
}
@@ -18,22 +18,20 @@ const CHACHA20_CIPHER_NAME: &'static str = "ChaCha20Poly1305";
18
18
impl StorableBuilder {
19
19
/// Creates a [`Storable`] that can be serialized and stored as `value` in [`PutObjectRequest`].
20
20
///
21
- /// Uses ChaCha20 for encrypting the `input` and Poly1305 for generating mac/tag.
21
+ /// Uses ChaCha20 for encrypting `input` and Poly1305 for generating a mac/tag.
22
22
///
23
23
/// Refer to docs on [`Storable`] for more information.
24
24
///
25
25
/// [`PutObjectRequest`]: crate::types::PutObjectRequest
26
26
pub fn build ( & self , input : Vec < u8 > , version : i64 ) -> Storable {
27
27
let mut rng = ThreadRng :: default ( ) ;
28
- let mut nonce = Vec :: with_capacity ( 12 ) ;
29
- nonce. resize ( 12 , 0u8 ) ;
28
+ let mut nonce = vec ! [ 0u8 ; 12 ] ;
30
29
rng. fill_bytes ( & mut nonce[ 4 ..] ) ;
31
30
32
31
let mut data_blob = PlaintextBlob { value : input, version } . encode_to_vec ( ) ;
33
32
34
33
let mut cipher = ChaCha20Poly1305 :: new ( & self . data_encryption_key , & nonce, & [ ] ) ;
35
- let mut tag = Vec :: with_capacity ( 16 ) ;
36
- tag. resize ( 16 , 0u8 ) ;
34
+ let mut tag = vec ! [ 0u8 ; 16 ] ;
37
35
cipher. encrypt_inplace ( & mut data_blob, & mut tag) ;
38
36
Storable {
39
37
data : data_blob,
0 commit comments