mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-08 04:29:54 +00:00
[kgm] refactor: convert to enum for dispatch
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use crate::v2::DecipherV2;
|
||||
use crate::v3::DecipherV3;
|
||||
use crate::{Decipher, KugouError};
|
||||
use crate::KugouError;
|
||||
use byteorder::{ByteOrder, LE};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -48,25 +46,8 @@ impl Header {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn make_decipher(&self) -> Result<Box<dyn Decipher>, KugouError> {
|
||||
let slot_key: &[u8] = match self.key_slot {
|
||||
1 => b"l,/'",
|
||||
slot => Err(KugouError::UnsupportedKeySlot(slot))?,
|
||||
};
|
||||
|
||||
let decipher: Box<dyn Decipher> = match self.crypto_version {
|
||||
2 => Box::new(DecipherV2::new(self, slot_key)?),
|
||||
3 => Box::new(DecipherV3::new(self, slot_key)?),
|
||||
version => Err(KugouError::UnsupportedCipherVersion(version))?,
|
||||
};
|
||||
|
||||
let mut test_data = self.decrypt_test_data;
|
||||
decipher.decrypt(&mut test_data, 0);
|
||||
if self.challenge_data != test_data {
|
||||
Err(KugouError::SelfTestFailed)?;
|
||||
}
|
||||
|
||||
Ok(decipher)
|
||||
pub fn get_challenge_data(&self) -> [u8; 0x10] {
|
||||
self.challenge_data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user