[wasm/mg3d] feat #3: expose mg3d to wasm glue
This commit is contained in:
parent
0da553c4dd
commit
87d1d8152a
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -555,6 +555,7 @@ dependencies = [
|
|||||||
"umc_joox",
|
"umc_joox",
|
||||||
"umc_kgm",
|
"umc_kgm",
|
||||||
"umc_kuwo",
|
"umc_kuwo",
|
||||||
|
"umc_mg3d",
|
||||||
"umc_ncm",
|
"umc_ncm",
|
||||||
"umc_qmc",
|
"umc_qmc",
|
||||||
"umc_qtfm",
|
"umc_qtfm",
|
||||||
|
@ -26,6 +26,7 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
|
|||||||
umc_joox = { path = "../um_crypto/joox" }
|
umc_joox = { path = "../um_crypto/joox" }
|
||||||
umc_kgm = { path = "../um_crypto/kgm" }
|
umc_kgm = { path = "../um_crypto/kgm" }
|
||||||
umc_kuwo = { path = "../um_crypto/kuwo" }
|
umc_kuwo = { path = "../um_crypto/kuwo" }
|
||||||
|
umc_mg3d = { path = "../um_crypto/mg3d" }
|
||||||
umc_ncm = { path = "../um_crypto/ncm" }
|
umc_ncm = { path = "../um_crypto/ncm" }
|
||||||
umc_qmc = { path = "../um_crypto/qmc" }
|
umc_qmc = { path = "../um_crypto/qmc" }
|
||||||
umc_qtfm = { path = "../um_crypto/qtfm" }
|
umc_qtfm = { path = "../um_crypto/qtfm" }
|
||||||
|
30
um_wasm/src/exports/mg3d.rs
Normal file
30
um_wasm/src/exports/mg3d.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
use umc_mg3d::{guess_key, Decipher};
|
||||||
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
use wasm_bindgen::JsError;
|
||||||
|
|
||||||
|
/// Migu3D MG3D file decipher.
|
||||||
|
#[wasm_bindgen(js_name=Migu3D)]
|
||||||
|
pub struct JsMigu3D(Decipher);
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_class=Migu3D)]
|
||||||
|
impl JsMigu3D {
|
||||||
|
/// Create a new decipher and guess its key from first 0x100 bytes.
|
||||||
|
#[wasm_bindgen(js_name=fromHeader)]
|
||||||
|
pub fn from_header(header: &[u8]) -> Result<JsMigu3D, JsError> {
|
||||||
|
let key = guess_key(header).ok_or_else(|| JsError::new("failed to guess key"))?;
|
||||||
|
let decipher = Decipher::new_from_final_key(&key)?;
|
||||||
|
Ok(JsMigu3D(decipher))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new decipher from file_key
|
||||||
|
#[wasm_bindgen(js_name=fromFileKey)]
|
||||||
|
pub fn from_file_key(file_key: &str) -> Result<JsMigu3D, JsError> {
|
||||||
|
let decipher = Decipher::new_from_file_key(file_key)?;
|
||||||
|
Ok(JsMigu3D(decipher))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decrypt encrypted buffer part.
|
||||||
|
pub fn decrypt(&self, buffer: &mut [u8], offset: usize) {
|
||||||
|
self.0.decrypt(buffer, offset)
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ pub mod audio;
|
|||||||
pub mod joox;
|
pub mod joox;
|
||||||
pub mod kgm;
|
pub mod kgm;
|
||||||
pub mod kuwo;
|
pub mod kuwo;
|
||||||
|
pub mod mg3d;
|
||||||
pub mod ncm;
|
pub mod ncm;
|
||||||
pub mod qmc;
|
pub mod qmc;
|
||||||
pub mod qtfm;
|
pub mod qtfm;
|
||||||
|
Loading…
Reference in New Issue
Block a user