Skip to content

Commit 413d8fd

Browse files
committed
use pre-allocated vecs for tag/nonce
1 parent 44a413b commit 413d8fd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/util/storable_builder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ impl StorableBuilder {
2626
/// [`PutObjectRequest`]: crate::types::PutObjectRequest
2727
pub fn build(&self, input: Vec<u8>, version: i64) -> Storable {
2828
let mut rng = ThreadRng::default();
29-
let mut nonce = [0u8; 12];
29+
let mut nonce = Vec::with_capacity(12);
30+
nonce.resize(12, 0u8);
3031
rng.fill_bytes(&mut nonce[4..]);
3132

3233
let mut data_blob = PlaintextBlob { value: input, version }.encode_to_vec();
3334

3435
let mut cipher = ChaCha20Poly1305::new(&self.data_encryption_key, &nonce, &[]);
35-
let mut tag = [0u8; 16];
36+
let mut tag = Vec::with_capacity(16);
37+
tag.resize(16, 0u8);
3638
cipher.encrypt_inplace(&mut data_blob, &mut tag);
3739
Storable {
3840
data: data_blob,
3941
encryption_metadata: Some(EncryptionMetadata {
40-
nonce: Vec::from(nonce),
41-
tag: Vec::from(tag),
42+
nonce,
43+
tag,
4244
cipher_format: CHACHA20_CIPHER_NAME.to_string(),
4345
}),
4446
}

0 commit comments

Comments
 (0)