mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
no point to clone key
This commit is contained in:
parent
0a90725d4a
commit
b1a8281551
1 changed files with 7 additions and 7 deletions
|
@ -70,8 +70,8 @@ impl Index {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrypt(key: &Option<aes::Aes256>, bytes: &mut [u8]) -> Result<(), super::Error> {
|
fn decrypt(key: Option<&aes::Aes256>, bytes: &mut [u8]) -> Result<(), super::Error> {
|
||||||
if let Some(key) = &key {
|
if let Some(key) = key {
|
||||||
use aes::cipher::BlockDecrypt;
|
use aes::cipher::BlockDecrypt;
|
||||||
for chunk in bytes.chunks_mut(16) {
|
for chunk in bytes.chunks_mut(16) {
|
||||||
key.decrypt_block(aes::Block::from_mut_slice(chunk))
|
key.decrypt_block(aes::Block::from_mut_slice(chunk))
|
||||||
|
@ -91,7 +91,7 @@ impl PakReader {
|
||||||
let mut log = "\n".to_owned();
|
let mut log = "\n".to_owned();
|
||||||
|
|
||||||
for ver in Version::iter() {
|
for ver in Version::iter() {
|
||||||
match Pak::read(&mut *reader, ver, key.clone()) {
|
match Pak::read(&mut *reader, ver, key.as_ref()) {
|
||||||
Ok(pak) => {
|
Ok(pak) => {
|
||||||
return Ok(PakReader { pak, key });
|
return Ok(PakReader { pak, key });
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ impl Pak {
|
||||||
fn read<R: Read + Seek>(
|
fn read<R: Read + Seek>(
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
version: super::Version,
|
version: super::Version,
|
||||||
key: Option<aes::Aes256>,
|
key: Option<&aes::Aes256>,
|
||||||
) -> Result<Self, super::Error> {
|
) -> Result<Self, super::Error> {
|
||||||
// read footer to get index, encryption & compression info
|
// read footer to get index, encryption & compression info
|
||||||
reader.seek(io::SeekFrom::End(-version.size()))?;
|
reader.seek(io::SeekFrom::End(-version.size()))?;
|
||||||
|
@ -236,7 +236,7 @@ impl Pak {
|
||||||
|
|
||||||
// decrypt index if needed
|
// decrypt index if needed
|
||||||
if footer.encrypted {
|
if footer.encrypted {
|
||||||
decrypt(&key, &mut index)?;
|
decrypt(key, &mut index)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut index = io::Cursor::new(index);
|
let mut index = io::Cursor::new(index);
|
||||||
|
@ -257,7 +257,7 @@ impl Pak {
|
||||||
// TODO verify hash
|
// TODO verify hash
|
||||||
|
|
||||||
if footer.encrypted {
|
if footer.encrypted {
|
||||||
decrypt(&key, &mut path_hash_index_buf)?;
|
decrypt(key, &mut path_hash_index_buf)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut path_hash_index = vec![];
|
let mut path_hash_index = vec![];
|
||||||
|
@ -285,7 +285,7 @@ impl Pak {
|
||||||
// TODO verify hash
|
// TODO verify hash
|
||||||
|
|
||||||
if footer.encrypted {
|
if footer.encrypted {
|
||||||
decrypt(&key, &mut full_directory_index)?;
|
decrypt(key, &mut full_directory_index)?;
|
||||||
}
|
}
|
||||||
let mut fdi = io::Cursor::new(full_directory_index);
|
let mut fdi = io::Cursor::new(full_directory_index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue