[joox] feat #1: add joox decipher implementation

This commit is contained in:
鲁树人
2024-09-17 21:45:51 +01:00
parent b3fc9f8318
commit 12199616c2
13 changed files with 293 additions and 1 deletions

View File

@@ -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" }

View 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())
}
}

View File

@@ -1,4 +1,5 @@
pub mod audio;
pub mod joox;
pub mod kgm;
pub mod kuwo;
pub mod ncm;