From 0bc1ec8a9ad16f10ba3aeae0fb6eefa6ea76fbbd Mon Sep 17 00:00:00 2001 From: 17ms <79069176+17ms@users.noreply.github.com> Date: Mon, 1 May 2023 13:52:54 +0300 Subject: [PATCH] split 1 of 772644f, debugging ci --- src/crypto.rs | 12 ++++++++---- src/error.rs | 1 - 2 files changed, 8 insertions(+), 5 deletions(-) delete mode 100644 src/error.rs diff --git a/src/crypto.rs b/src/crypto.rs index 538e282..c662cfb 100755 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -62,7 +62,10 @@ pub fn aes_encrypt( rng: &mut OsRng, ) -> Result, Box> { let nonce = generate_nonce(rng); - let encrypted = cipher.encrypt(&nonce, data.as_ref()).unwrap(); // TODO: handle errors + let encrypted = match cipher.encrypt(&nonce, data.as_ref()) { + Ok(data) => data, + Err(_) => return Err("AES encryption failed".into()), + }; let mut data = nonce.to_vec(); data.extend_from_slice(&encrypted); @@ -74,9 +77,10 @@ pub fn aes_decrypt( cipher: &mut AesGcm, ) -> Result, Box> { let (nonce_bytes, data) = data.split_at(AES_NONCE_SIZE); - let decrypted = cipher - .decrypt(Nonce::from_slice(nonce_bytes), data.as_ref()) - .unwrap(); // TODO: handle errors + let decrypted = match cipher.decrypt(Nonce::from_slice(nonce_bytes), data.as_ref()) { + Ok(data) => data, + Err(_) => return Err("AES decryption failed".into()), + }; Ok(decrypted) } diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index ff7bd09..0000000 --- a/src/error.rs +++ /dev/null @@ -1 +0,0 @@ -// placeholder