|
16 | 16 | // under the License.
|
17 | 17 |
|
18 | 18 | #[cfg(feature = "encryption")]
|
19 |
| -use crate::encryption::ciphers::{NONCE_LEN, SIZE_LEN, TAG_LEN}; |
20 |
| -#[cfg(feature = "encryption")] |
21 |
| -use crate::encryption::encrypt::{encrypt_object, encrypt_object_to_vec, FileEncryptor}; |
| 19 | +use crate::encryption::encrypt::{encrypt_object, encrypt_object_to_vec, sign_and_write_object, FileEncryptor}; |
22 | 20 | #[cfg(feature = "encryption")]
|
23 | 21 | use crate::encryption::modules::{create_footer_aad, create_module_aad, ModuleType};
|
24 | 22 | #[cfg(feature = "encryption")]
|
@@ -507,35 +505,9 @@ impl MetadataObjectWriter {
|
507 | 505 | }
|
508 | 506 | Some(file_encryptor) if !file_encryptor.properties().encrypt_footer() => {
|
509 | 507 | // todo: should we also check for file_metadata.encryption_algorithm.is_some() ?
|
510 |
| - // Write unencrypted footer |
511 |
| - let data_len: usize; |
512 |
| - { |
513 |
| - let mut buffer: Vec<u8> = vec![]; |
514 |
| - let mut unencrypted_protocol = TCompactOutputProtocol::new(&mut buffer); |
515 |
| - file_metadata.write_to_out_protocol(&mut unencrypted_protocol)?; |
516 |
| - data_len = buffer.len(); |
517 |
| - sink.write_all(&buffer)?; |
518 |
| - } |
519 |
| - |
520 |
| - // Write nonce and tag |
521 |
| - { |
522 |
| - let mut encrypted_buffer: Vec<u8> = vec![]; |
523 |
| - let aad = create_footer_aad(file_encryptor.file_aad())?; |
524 |
| - let mut encryptor = file_encryptor.get_footer_encryptor()?; |
525 |
| - |
526 |
| - let mut protocol = TCompactOutputProtocol::new(&mut encrypted_buffer); |
527 |
| - file_metadata.write_to_out_protocol(&mut protocol)?; |
528 |
| - encryptor.encrypt(encrypted_buffer.as_ref(), &aad)?; |
529 |
| - |
530 |
| - // todo: check for overflow when calculating lengths |
531 |
| - let nonce = |
532 |
| - &encrypted_buffer[SIZE_LEN + data_len..SIZE_LEN + data_len + NONCE_LEN]; |
533 |
| - sink.write_all(nonce)?; |
534 |
| - let tag = &encrypted_buffer[SIZE_LEN + data_len + NONCE_LEN |
535 |
| - ..SIZE_LEN + data_len + NONCE_LEN + TAG_LEN]; |
536 |
| - sink.write_all(tag)?; |
537 |
| - } |
538 |
| - Ok(()) |
| 508 | + let aad = create_footer_aad(file_encryptor.file_aad())?; |
| 509 | + let mut encryptor = file_encryptor.get_footer_encryptor()?; |
| 510 | + sign_and_write_object(file_metadata, &mut encryptor, &mut sink, &aad) |
539 | 511 | }
|
540 | 512 | _ => Self::write_object(file_metadata, &mut sink),
|
541 | 513 | }
|
|
0 commit comments