mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-07 20:19:51 +00:00
[joox] feat #1: add joox decipher implementation
This commit is contained in:
@@ -23,6 +23,7 @@ getrandom = { version = "0.2", features = ["js"] }
|
||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||
# code size when deploying.
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
umc_joox = { path = "../um_crypto/joox" }
|
||||
umc_kgm = { path = "../um_crypto/kgm" }
|
||||
umc_kuwo = { path = "../um_crypto/kuwo" }
|
||||
umc_ncm = { path = "../um_crypto/ncm" }
|
||||
|
||||
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