mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-08 04:29:54 +00:00
[xiami] feat: implement xiami decipher
This commit is contained in:
@@ -4,4 +4,5 @@ pub mod kgm;
|
||||
pub mod kuwo;
|
||||
pub mod ncm;
|
||||
pub mod qmc;
|
||||
mod xiami;
|
||||
pub mod xmly;
|
||||
|
||||
27
um_wasm/src/exports/xiami.rs
Normal file
27
um_wasm/src/exports/xiami.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use umc_xiami::XiamiFile;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsError;
|
||||
|
||||
/// Xiami XM file decipher.
|
||||
#[wasm_bindgen(js_name=Xiami)]
|
||||
pub struct JsXiami(XiamiFile);
|
||||
|
||||
#[wasm_bindgen(js_class = Xiami)]
|
||||
impl JsXiami {
|
||||
/// Parse the Xiami header (0x400 bytes)
|
||||
pub fn from_header(header: &[u8]) -> Result<JsXiami, JsError> {
|
||||
let hdr = XiamiFile::from_header(header)?;
|
||||
Ok(JsXiami(hdr))
|
||||
}
|
||||
|
||||
/// Decrypt encrypted buffer part.
|
||||
pub fn decrypt(&self, buffer: &mut [u8]) {
|
||||
self.0.decrypt(buffer)
|
||||
}
|
||||
|
||||
/// After header (0x10 bytes), the number of bytes should be copied without decryption.
|
||||
#[wasm_bindgen(getter, js_name=copyPlainLength)]
|
||||
pub fn get_copy_plain_length(&self) -> usize {
|
||||
self.0.copy_len
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user