[kgm] refactor: convert to enum for dispatch

This commit is contained in:
鲁树人
2024-09-16 20:59:05 +01:00
parent e011f75d36
commit e45d09cf8e
5 changed files with 48 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
use crate::header::Header;
use crate::{Decipher, KugouError};
use crate::KugouError;
pub struct DecipherV3 {
slot_key: [u8; 16],
@@ -30,11 +30,9 @@ impl DecipherV3 {
let offset_key = (offset as u32).to_ne_bytes();
offset_key[0] ^ offset_key[1] ^ offset_key[2] ^ offset_key[3]
}
}
impl Decipher for DecipherV3 {
fn decrypt(&self, buffer: &mut [u8], offset: usize) {
for (datum, offset) in buffer.iter_mut().zip(offset..) {
pub fn decrypt<T: AsMut<[u8]> + ?Sized>(&self, buffer: &mut T, offset: usize) {
for (datum, offset) in buffer.as_mut().iter_mut().zip(offset..) {
let offset_key = Self::offset_key(offset);
let file_key = self.file_key[offset % self.file_key.len()];