mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-08 04:29:54 +00:00
[joox] feat #1: add joox decipher implementation
This commit is contained in:
29
um_wasm/src/exports/joox.rs
Normal file
29
um_wasm/src/exports/joox.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use umc_joox::decrypt::JooxDecipher;
|
||||
use umc_joox::header::Header;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsError;
|
||||
|
||||
/// Joox file.
|
||||
#[wasm_bindgen(js_name=JooxFile)]
|
||||
pub struct JsJooxFile(Header);
|
||||
|
||||
#[wasm_bindgen(js_class = JooxFile)]
|
||||
impl JsJooxFile {
|
||||
/// Initialize header. Header should be 0x0c bytes.
|
||||
pub fn parse(header: &[u8], uuid: String) -> Result<JsJooxFile, JsError> {
|
||||
Ok(JsJooxFile(
|
||||
Header::from_buffer(header, uuid.as_bytes()).map_err(JsError::from)?,
|
||||
))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter, js_name = "bufferLength")]
|
||||
pub fn get_buffer_size(&self) -> usize {
|
||||
self.0.get_audio_block_size()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "decrypt")]
|
||||
pub fn decrypt(&self, buffer: &mut [u8]) -> Result<usize, JsError> {
|
||||
let decrypted = self.0.decrypt_audio_block(buffer).map_err(JsError::from)?;
|
||||
Ok(decrypted.len())
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod audio;
|
||||
pub mod joox;
|
||||
pub mod kgm;
|
||||
pub mod kuwo;
|
||||
pub mod ncm;
|
||||
|
||||
Reference in New Issue
Block a user