before inevitable borking

This commit is contained in:
spuds 2023-01-13 15:23:51 +00:00
parent 7d1fd167e1
commit c0107af12f
No known key found for this signature in database
GPG key ID: 0B6CA6068E827C8F
3 changed files with 28 additions and 10 deletions

View file

@ -1,8 +1,7 @@
use super::{Compression, ReadExt, Version};
use byteorder::{ReadBytesExt, LE};
use std::io;
use super::{Compression, ReadExt, Version};
#[derive(Debug)]
pub struct Block {
pub offset: u64,
@ -72,8 +71,30 @@ impl Entry {
version: super::Version,
key: Option<&aes::Aes256Dec>,
) -> Result<Vec<u8>, super::Error> {
let buf = io::BufWriter::new(Vec::new());
todo!("read the stuff");
let mut buf = io::BufWriter::new(Vec::with_capacity(self.uncompressed as usize));
reader.seek(io::SeekFrom::Start(self.offset))?;
let mut data = reader.read_len(match self.encrypted {
// add alignment (aes block size: 16) then zero out alignment bits
true => (self.compressed + 15) & !17,
false => self.compressed,
} as usize)?;
if self.encrypted {
if let Some(key) = key {
use aes::cipher::BlockDecrypt;
for block in data.chunks_mut(16) {
key.decrypt_block(aes::Block::from_mut_slice(block))
}
data.truncate(self.compressed as usize);
}
}
use io::Write;
match self.compression {
Compression::None => buf.write_all(&data)?,
Compression::Zlib => todo!(),
Compression::Gzip => todo!(),
Compression::Oodle => todo!(),
}
buf.flush()?;
Ok(buf.into_inner()?)
}
}

View file

@ -1,8 +1,6 @@
use std::str::FromStr;
use byteorder::{ReadBytesExt, LE};
use super::{Compression, ReadExt, Version};
use byteorder::{ReadBytesExt, LE};
use std::str::FromStr;
#[derive(Debug)]
pub struct Footer {

View file

@ -1,6 +1,5 @@
use std::io;
use super::Version;
use std::io;
#[derive(Debug)]
pub struct Pak<R: io::Read + io::Seek> {