From b1a82815513f6a9dfddbd981a9d6e07a2f1ee5f2 Mon Sep 17 00:00:00 2001 From: spuds <71292624+bananaturtlesandwich@users.noreply.github.com> Date: Sun, 27 Aug 2023 15:20:24 +0100 Subject: [PATCH] no point to clone key --- repak/src/pak.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/repak/src/pak.rs b/repak/src/pak.rs index 16399cd..9c575b6 100644 --- a/repak/src/pak.rs +++ b/repak/src/pak.rs @@ -70,8 +70,8 @@ impl Index { } } -fn decrypt(key: &Option, bytes: &mut [u8]) -> Result<(), super::Error> { - if let Some(key) = &key { +fn decrypt(key: Option<&aes::Aes256>, bytes: &mut [u8]) -> Result<(), super::Error> { + if let Some(key) = key { use aes::cipher::BlockDecrypt; for chunk in bytes.chunks_mut(16) { key.decrypt_block(aes::Block::from_mut_slice(chunk)) @@ -91,7 +91,7 @@ impl PakReader { let mut log = "\n".to_owned(); for ver in Version::iter() { - match Pak::read(&mut *reader, ver, key.clone()) { + match Pak::read(&mut *reader, ver, key.as_ref()) { Ok(pak) => { return Ok(PakReader { pak, key }); } @@ -225,7 +225,7 @@ impl Pak { fn read( mut reader: R, version: super::Version, - key: Option, + key: Option<&aes::Aes256>, ) -> Result { // read footer to get index, encryption & compression info reader.seek(io::SeekFrom::End(-version.size()))?; @@ -236,7 +236,7 @@ impl Pak { // decrypt index if needed if footer.encrypted { - decrypt(&key, &mut index)?; + decrypt(key, &mut index)?; } let mut index = io::Cursor::new(index); @@ -257,7 +257,7 @@ impl Pak { // TODO verify hash if footer.encrypted { - decrypt(&key, &mut path_hash_index_buf)?; + decrypt(key, &mut path_hash_index_buf)?; } let mut path_hash_index = vec![]; @@ -285,7 +285,7 @@ impl Pak { // TODO verify hash if footer.encrypted { - decrypt(&key, &mut full_directory_index)?; + decrypt(key, &mut full_directory_index)?; } let mut fdi = io::Cursor::new(full_directory_index);