use crate::header::Header; use crate::{Decipher, KugouError}; pub struct DecipherV2 { key: [u8; 4], } impl DecipherV2 { pub fn new(_header: &Header, slot_key: &[u8]) -> Result { let mut key = [0u8; 4]; key.copy_from_slice(slot_key); Ok(Self { key }) } } impl Decipher for DecipherV2 { fn decrypt(&self, buffer: &mut [u8], offset: usize) { let key_stream = self.key.iter().cycle().skip(offset % self.key.len()); for (datum, &k) in buffer.iter_mut().zip(key_stream) { *datum ^= k; } } } #[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(()) }