pub struct XTSN { /* private fields */ }
Expand description
XTSN works the same as CXTSN, the only difference is, that the XTSN version is written in pure Rust and handles Errors. This means that the Result actually returns usefull stuff, that you should defenitly parse!
Implementations
sourceimpl XTSN
impl XTSN
sourcepub fn new(crypt: &str, tweak: &str) -> Result<Self, String>
pub fn new(crypt: &str, tweak: &str) -> Result<Self, String>
initializes a new Cryptor it requires 2 keys:
- crypt to decrypt
- tweak to encrypt they can be the same but shouldn’t !!!
sourcepub fn decrypt(
&self,
buffer: Vec<u8>,
sector_off: usize
) -> Result<Vec<u8>, String>
pub fn decrypt(
&self,
buffer: Vec<u8>,
sector_off: usize
) -> Result<Vec<u8>, String>
This function is used to encrypt data. It works only with buffers, that are a multiple of 0x200! The function doesn’t check the buffer so it will silently ignore any trailing bytes in the buffer!
Example
extern crate XTSN;
fn main() {
let mut data = b"Hello XTSN".to_vec();
// the string is not 0x200 bytes:
while data.len() != 0x200 {
data.push(0);
}
let xts = match XTSN::CXTSN::new("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") {
Ok(res) => res,
Err(e) => panic!(e),
};
let ret = match xts.encrypt(data, 0) {
Ok(res) => res,
Err(e) => panic!(e),
};
println!("{:?}", &ret);
}
sourcepub fn encrypt(
&self,
buffer: Vec<u8>,
sector_off: usize
) -> Result<Vec<u8>, String>
pub fn encrypt(
&self,
buffer: Vec<u8>,
sector_off: usize
) -> Result<Vec<u8>, String>
This function is used to encrypt data. It works just only with buffers, that are a multiple of 0x200! The function doesn’t check the buffer so it will silently ignore any trailing bytes in the buffer! This function is currently broken and need some debugging, or you can just use the CXTSN version which just works :3
Example
extern crate XTSN;
fn main() {
let mut data = b"Hello XTSN".to_vec();
// the string is not 0x200 bytes:
while data.len() != 0x200 {
data.push(0);
}
let xts = match XTSN::XTSN::new("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") {
Ok(res) => res,
Err(e) => panic!(e),
};
let ret = match xts.encrypt(data, 0) {
Ok(res) => res,
Err(e) => panic!(e),
};
println!("{:?}", &ret);
}