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());