mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
Use use Aes256 for both encoding and decoding
This commit is contained in:
parent
d4a56617f8
commit
847f2d7aa8
4 changed files with 14 additions and 14 deletions
|
@ -310,7 +310,7 @@ impl Entry {
|
||||||
&self,
|
&self,
|
||||||
reader: &mut R,
|
reader: &mut R,
|
||||||
version: Version,
|
version: Version,
|
||||||
key: Option<&aes::Aes256Dec>,
|
key: Option<&aes::Aes256>,
|
||||||
buf: &mut W,
|
buf: &mut W,
|
||||||
) -> Result<(), super::Error> {
|
) -> Result<(), super::Error> {
|
||||||
reader.seek(io::SeekFrom::Start(self.offset))?;
|
reader.seek(io::SeekFrom::Start(self.offset))?;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::ext::{ReadExt, WriteExt};
|
use super::ext::{ReadExt, WriteExt};
|
||||||
use super::{Version, VersionMajor};
|
use super::{Version, VersionMajor};
|
||||||
use aes::Aes256Enc;
|
use aes::Aes256;
|
||||||
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
|
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::io::{self, Read, Seek, Write};
|
use std::io::{self, Read, Seek, Write};
|
||||||
|
@ -8,14 +8,14 @@ use std::io::{self, Read, Seek, Write};
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PakReader {
|
pub struct PakReader {
|
||||||
pak: Pak,
|
pak: Pak,
|
||||||
key: Option<aes::Aes256Dec>,
|
key: Option<aes::Aes256>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PakWriter<W: Write + Seek> {
|
pub struct PakWriter<W: Write + Seek> {
|
||||||
pak: Pak,
|
pak: Pak,
|
||||||
writer: W,
|
writer: W,
|
||||||
key: Option<aes::Aes256Enc>,
|
key: Option<aes::Aes256>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -62,7 +62,7 @@ impl Index {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrypt(key: &Option<aes::Aes256Dec>, 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) {
|
||||||
|
@ -77,7 +77,7 @@ fn decrypt(key: &Option<aes::Aes256Dec>, bytes: &mut [u8]) -> Result<(), super::
|
||||||
impl PakReader {
|
impl PakReader {
|
||||||
pub fn new_any<R: Read + Seek>(
|
pub fn new_any<R: Read + Seek>(
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
key: Option<aes::Aes256Dec>,
|
key: Option<aes::Aes256>,
|
||||||
) -> Result<Self, super::Error> {
|
) -> Result<Self, super::Error> {
|
||||||
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.clone()) {
|
||||||
|
@ -124,7 +124,7 @@ impl PakReader {
|
||||||
impl<W: Write + io::Seek> PakWriter<W> {
|
impl<W: Write + io::Seek> PakWriter<W> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
writer: W,
|
writer: W,
|
||||||
key: Option<aes::Aes256Enc>,
|
key: Option<aes::Aes256>,
|
||||||
version: Version,
|
version: Version,
|
||||||
mount_point: String,
|
mount_point: String,
|
||||||
path_hash_seed: Option<u64>,
|
path_hash_seed: Option<u64>,
|
||||||
|
@ -185,7 +185,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::Aes256Dec>,
|
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()))?;
|
||||||
|
@ -316,7 +316,7 @@ impl Pak {
|
||||||
fn write<W: Write + Seek>(
|
fn write<W: Write + Seek>(
|
||||||
&self,
|
&self,
|
||||||
writer: &mut W,
|
writer: &mut W,
|
||||||
_key: Option<aes::Aes256Enc>,
|
_key: Option<aes::Aes256>,
|
||||||
) -> Result<(), super::Error> {
|
) -> Result<(), super::Error> {
|
||||||
let index_offset = writer.stream_position()?;
|
let index_offset = writer.stream_position()?;
|
||||||
|
|
||||||
|
@ -548,7 +548,7 @@ fn pad_zeros_to_alignment(v: &mut Vec<u8>, alignment: usize) {
|
||||||
assert!(v.len() % alignment == 0);
|
assert!(v.len() % alignment == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encrypt(key: Aes256Enc, bytes: &mut [u8]) {
|
fn encrypt(key: Aes256, bytes: &mut [u8]) {
|
||||||
use aes::cipher::BlockEncrypt;
|
use aes::cipher::BlockEncrypt;
|
||||||
for chunk in bytes.chunks_mut(16) {
|
for chunk in bytes.chunks_mut(16) {
|
||||||
key.encrypt_block(aes::Block::from_mut_slice(chunk))
|
key.encrypt_block(aes::Block::from_mut_slice(chunk))
|
||||||
|
|
|
@ -113,7 +113,7 @@ macro_rules! mt_encryptindex_read {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|_| repak::Error::Base64)
|
.map_err(|_| repak::Error::Base64)
|
||||||
.and_then(|bytes| {
|
.and_then(|bytes| {
|
||||||
aes::Aes256Dec::new_from_slice(bytes).map_err(|_| repak::Error::Aes)
|
aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes)
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ macro_rules! mt_encryptindex_write {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|_| repak::Error::Base64)
|
.map_err(|_| repak::Error::Base64)
|
||||||
.and_then(|bytes| {
|
.and_then(|bytes| {
|
||||||
aes::Aes256Dec::new_from_slice(bytes).map_err(|_| repak::Error::Aes)
|
aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes)
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let mut reader = std::io::Cursor::new(include_bytes!(concat!("packs/pack_", $version, $compress, $encrypt, $encryptindex, ".pak")));
|
let mut reader = std::io::Cursor::new(include_bytes!(concat!("packs/pack_", $version, $compress, $encrypt, $encryptindex, ".pak")));
|
||||||
|
|
|
@ -117,14 +117,14 @@ fn main() -> Result<(), repak::Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aes_key(key: &str) -> Result<aes::Aes256Dec, repak::Error> {
|
fn aes_key(key: &str) -> Result<aes::Aes256, repak::Error> {
|
||||||
use aes::cipher::KeyInit;
|
use aes::cipher::KeyInit;
|
||||||
use base64::{engine::general_purpose, Engine as _};
|
use base64::{engine::general_purpose, Engine as _};
|
||||||
general_purpose::STANDARD
|
general_purpose::STANDARD
|
||||||
.decode(key)
|
.decode(key)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|_| repak::Error::Base64)
|
.map_err(|_| repak::Error::Base64)
|
||||||
.and_then(|bytes| aes::Aes256Dec::new_from_slice(bytes).map_err(|_| repak::Error::Aes))
|
.and_then(|bytes| aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn info(args: ActionInfo) -> Result<(), repak::Error> {
|
fn info(args: ActionInfo) -> Result<(), repak::Error> {
|
||||||
|
|
Loading…
Reference in a new issue