From 39aa1f0ad65e8b2d24159e78ae7e19b7ace74e0f Mon Sep 17 00:00:00 2001 From: EETagent Date: Wed, 16 Nov 2022 14:11:01 +0100 Subject: [PATCH] fix: possible crypto file write fixes --- core/src/crypto.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/crypto.rs b/core/src/crypto.rs index 9eaf538..c8344f1 100644 --- a/core/src/crypto.rs +++ b/core/src/crypto.rs @@ -238,8 +238,8 @@ async fn age_decrypt_with_private_key( }; let mut decrypt_writer = decryptor.decrypt_async(iter::once( - &age::x25519::Identity::from_str(key).map_err(|e| ServiceError::AgeKeyError(e.to_string()))? - as &dyn age::Identity, + &age::x25519::Identity::from_str(key) + .map_err(|e| ServiceError::AgeKeyError(e.to_string()))? as &dyn age::Identity, ))?; decrypt_writer.read_to_end(output_buffer).await?; @@ -289,12 +289,18 @@ pub async fn encrypt_file_with_recipients>( tokio::io::AsyncReadExt::read_to_end(&mut plain_file, &mut plain_file_contents).await?; + drop(plain_file); + age_encrypt_with_recipients( plain_file_contents.as_slice(), &mut cipher_file, &recipients, ) - .await + .await?; + + tokio::io::AsyncWriteExt::shutdown(&mut cipher_file).await?; + + Ok(()) } pub async fn decrypt_file_with_private_key>(