repak/examples/subcommands/mod.rs

26 lines
789 B
Rust
Raw Normal View History

2023-01-14 18:32:06 +00:00
mod list;
mod unpack;
mod version;
pub use {list::list, unpack::unpack, version::version};
fn load_pak(
path: String,
2023-01-17 05:27:36 +00:00
key: Option<String>,
2023-01-20 03:53:13 +00:00
) -> Result<unpak::PakReader<std::io::BufReader<std::fs::File>>, unpak::Error> {
2023-01-17 05:27:36 +00:00
use aes::cipher::KeyInit;
use base64::{engine::general_purpose, Engine as _};
let key = key
.map(|k| {
general_purpose::STANDARD
.decode(k)
.as_ref()
.map_err(|_| unpak::Error::Base64)
.and_then(|bytes| {
aes::Aes256Dec::new_from_slice(bytes).map_err(|_| unpak::Error::Aes)
})
})
.transpose()?;
2023-01-20 03:53:13 +00:00
unpak::PakReader::new_any( std::io::BufReader::new(std::fs::OpenOptions::new().read(true).open(&path)?), key)
2023-01-14 18:32:06 +00:00
}