diff --git a/um_crypto/kuwo/src/lib.rs b/um_crypto/kuwo/src/lib.rs index 3d64679..04dc1a7 100644 --- a/um_crypto/kuwo/src/lib.rs +++ b/um_crypto/kuwo/src/lib.rs @@ -1,6 +1,7 @@ use crate::kwm_v1::CipherV1; use anyhow::Result; use byteorder::{ReadBytesExt, LE}; +use std::fmt; use std::io::{Cursor, Read}; use thiserror::Error; use umc_qmc::QMCv2Cipher; @@ -13,13 +14,16 @@ pub use umc_qmc::QMCv2Cipher as CipherV2; /// Commonly used secret key for Kuwo services. pub const SECRET_KEY: [u8; 8] = *b"ylzsxkwm"; +#[derive(Debug)] +pub struct HeaderMagicBytes(pub [u8; 16]); + #[derive(Error, Debug)] pub enum KuwoCryptoError { #[error("Invalid DES data size (expected: {0} mod 8 == 0)")] InvalidDesDataSize(usize), - #[error("Invalid KWM header magic bytes: {0:?}")] - InvalidHeaderMagic([u8; 16]), + #[error("Invalid KWM header magic bytes: {0}")] + InvalidHeaderMagic(HeaderMagicBytes), #[error("KWMv2: EKey required")] V2EKeyRequired, @@ -28,6 +32,15 @@ pub enum KuwoCryptoError { UnsupportedVersion(usize), } +impl fmt::Display for HeaderMagicBytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for byte in self.0.iter() { + write!(f, "{:02x} ", byte)?; + } + Ok(()) + } +} + pub const DATA_START_OFFSET: usize = 0x400; pub enum Cipher {