From ee851f57a0d879d868ba328056e8a3a20a0a36b0 Mon Sep 17 00:00:00 2001 From: Bernd Krietenstein Date: Mon, 4 Dec 2023 08:32:52 +0100 Subject: [PATCH] Improve code readability Co-authored-by: Arthur Gautier --- cms/src/builder.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cms/src/builder.rs b/cms/src/builder.rs index b4f2e2a43..b4abec592 100644 --- a/cms/src/builder.rs +++ b/cms/src/builder.rs @@ -783,15 +783,11 @@ where let cek_byte_count: u8 = content_encryption_key.len().try_into().map_err(|_| { Error::Builder("Content encryption key length must not exceed 255".to_string()) })?; - let mut check_value = vec![ - 0xff ^ content_encryption_key[0], - 0xff ^ content_encryption_key[1], - 0xff ^ content_encryption_key[2], - ]; - - let mut wrapped_cek: Vec = Vec::new(); + let mut wrapped_cek: Vec = Vec::with_capacity(4 + padding_length); wrapped_cek.insert(0, cek_byte_count); - wrapped_cek.append(&mut check_value); + wrapped_cek.insert(0xff ^ content_encryption_key[0]); + wrapped_cek.insert(0xff ^ content_encryption_key[1]); + wrapped_cek.insert(0xff ^ content_encryption_key[2]); if padding_length > 0 { let mut padding = vec![0_u8; padding_length]; self.rng.fill_bytes(padding.as_mut_slice());