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 byteorder::{ReadBytesExt, LE};
use std::io; use std::io;
use super::{Compression, ReadExt, Version};
#[derive(Debug)] #[derive(Debug)]
pub struct Block { pub struct Block {
pub offset: u64, pub offset: u64,
@ -72,8 +71,30 @@ impl Entry {
version: super::Version, version: super::Version,
key: Option<&aes::Aes256Dec>, key: Option<&aes::Aes256Dec>,
) -> Result<Vec<u8>, super::Error> { ) -> Result<Vec<u8>, super::Error> {
let buf = io::BufWriter::new(Vec::new()); let mut buf = io::BufWriter::new(Vec::with_capacity(self.uncompressed as usize));
todo!("read the stuff"); 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()?) Ok(buf.into_inner()?)
} }
} }

View file

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

View file

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