lib_um_crypto_rust/um_crypto/kgm/src/v2.rs

29 lines
725 B
Rust

use crate::header::Header;
use crate::KugouError;
pub struct DecipherV2 {
key: [u8; 4],
}
impl DecipherV2 {
pub fn new(_header: &Header, slot_key: &[u8]) -> Result<Self, KugouError> {
let mut key = [0u8; 4];
key.copy_from_slice(slot_key);
Ok(Self { key })
}
pub fn decrypt<T: AsMut<[u8]> + ?Sized>(&self, buffer: &mut T, offset: usize) {
for (datum, offset) in buffer.as_mut().iter_mut().zip(offset..) {
*datum ^= self.key[offset % self.key.len()];
}
}
}
#[test]
fn test_v2_init() -> Result<(), KugouError> {
let hdr_v2 = Header::from_buffer(include_bytes!("__fixtures__/kgm_v2_hdr.bin"))?;
DecipherV2::new(&hdr_v2, b"1234")?;
Ok(())
}