[wasm/kgm] feat #2: add kgm glue
This commit is contained in:
parent
75ebe1e631
commit
adabbbd27e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -485,6 +485,7 @@ dependencies = [
|
|||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"um_audio",
|
"um_audio",
|
||||||
|
"umc_kgm",
|
||||||
"umc_kuwo",
|
"umc_kuwo",
|
||||||
"umc_ncm",
|
"umc_ncm",
|
||||||
"umc_qmc",
|
"umc_qmc",
|
||||||
|
@ -23,6 +23,7 @@ getrandom = { version = "0.2", features = ["js"] }
|
|||||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||||
# code size when deploying.
|
# code size when deploying.
|
||||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||||
|
umc_kgm = { path = "../um_crypto/kgm" }
|
||||||
umc_kuwo = { path = "../um_crypto/kuwo" }
|
umc_kuwo = { path = "../um_crypto/kuwo" }
|
||||||
umc_ncm = { path = "../um_crypto/ncm" }
|
umc_ncm = { path = "../um_crypto/ncm" }
|
||||||
umc_qmc = { path = "../um_crypto/qmc" }
|
umc_qmc = { path = "../um_crypto/qmc" }
|
||||||
|
37
um_wasm/src/exports/kgm.rs
Normal file
37
um_wasm/src/exports/kgm.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use umc_kgm::{header::Header, Decipher};
|
||||||
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
use wasm_bindgen::JsError;
|
||||||
|
|
||||||
|
/// KuGou KGM file header.
|
||||||
|
#[wasm_bindgen(js_name=KuGouHeader)]
|
||||||
|
pub struct JsKuGouHeader(Header);
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_class = KuGouHeader)]
|
||||||
|
impl JsKuGouHeader {
|
||||||
|
/// Parse the KuGou header (0x400 bytes)
|
||||||
|
pub fn parse(header: &[u8]) -> Result<JsKuGouHeader, JsError> {
|
||||||
|
Ok(JsKuGouHeader(
|
||||||
|
Header::from_buffer(header).map_err(JsError::from)?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// KuGou KGM file decipher.
|
||||||
|
#[wasm_bindgen(js_name=KuGouDecipher)]
|
||||||
|
pub struct JsKuGouDecipher(Decipher);
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_class=KuGouDecipher)]
|
||||||
|
impl JsKuGouDecipher {
|
||||||
|
/// Create an instance of cipher (decipher) for decryption
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(header: &JsKuGouHeader) -> Result<JsKuGouDecipher, JsError> {
|
||||||
|
Ok(JsKuGouDecipher(
|
||||||
|
Decipher::new(&header.0).map_err(JsError::from)?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decrypt a buffer.
|
||||||
|
pub fn decrypt(&self, buffer: &mut [u8], offset: usize) {
|
||||||
|
self.0.decrypt(buffer, offset)
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
pub mod audio;
|
pub mod audio;
|
||||||
|
pub mod kgm;
|
||||||
pub mod kuwo;
|
pub mod kuwo;
|
||||||
pub mod ncm;
|
pub mod ncm;
|
||||||
pub mod qmc;
|
pub mod qmc;
|
||||||
|
Loading…
Reference in New Issue
Block a user