Compare commits
No commits in common. "60d2fb4ce0f5e757ab44ab902a0f1bafaafe1aa1" and "75ebe1e63173939643e94cc9bf4927f6dc143426" have entirely different histories.
60d2fb4ce0
...
75ebe1e631
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -485,7 +485,6 @@ dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"getrandom",
|
||||
"um_audio",
|
||||
"umc_kgm",
|
||||
"umc_kuwo",
|
||||
"umc_ncm",
|
||||
"umc_qmc",
|
||||
|
@ -23,7 +23,6 @@ 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_kgm = { path = "../um_crypto/kgm" }
|
||||
umc_kuwo = { path = "../um_crypto/kuwo" }
|
||||
umc_ncm = { path = "../um_crypto/ncm" }
|
||||
umc_qmc = { path = "../um_crypto/qmc" }
|
||||
|
@ -1,37 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
@ -23,6 +23,13 @@ impl JsKuwoHeader {
|
||||
pub fn quality_id(&self) -> u32 {
|
||||
self.0.get_quality_id()
|
||||
}
|
||||
|
||||
/// Create an instance of cipher (decipher) for decryption
|
||||
#[wasm_bindgen(js_name=makeDecipher)]
|
||||
pub fn make_decipher(&self, ekey: Option<String>) -> Result<JsCipher, JsError> {
|
||||
let cipher = Decipher::new(&self.0, ekey).map_err(map_js_error)?;
|
||||
Ok(JsCipher(cipher))
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a decipher instance for "BoDian Music".
|
||||
@ -33,11 +40,11 @@ pub fn js_kuwo_bodian_cipher_factory(ekey: &str) -> Result<JsQMC2, JsError> {
|
||||
}
|
||||
|
||||
/// Kuwo KWM v1
|
||||
#[wasm_bindgen(js_name=KWMDecipherV1)]
|
||||
pub struct JsDecipherV1(CipherV1);
|
||||
#[wasm_bindgen(js_name=KWMCipherV1)]
|
||||
pub struct JsCipherV1(CipherV1);
|
||||
|
||||
#[wasm_bindgen(js_class=KWMDecipherV1)]
|
||||
impl JsDecipherV1 {
|
||||
#[wasm_bindgen(js_class=KWMCipherV1)]
|
||||
impl JsCipherV1 {
|
||||
/// Create a decipher instance for "Kuwo KWM v1".
|
||||
pub fn decrypt(&self, buffer: &mut [u8], offset: usize) {
|
||||
self.0.decrypt(buffer, offset)
|
||||
@ -51,21 +58,11 @@ pub fn js_kuwo_v2_cipher_factory(ekey: &str) -> Result<JsQMC2, JsError> {
|
||||
}
|
||||
|
||||
/// Common V1/V2 wrapper interface, derived from `KuwoHeader.makeCipher`
|
||||
#[wasm_bindgen(js_name=KWMDecipher)]
|
||||
pub struct JsDecipher(Decipher);
|
||||
|
||||
#[wasm_bindgen(js_class=KWMDecipher)]
|
||||
impl JsDecipher {
|
||||
/// Create an instance of cipher (decipher) for decryption
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn make_decipher(
|
||||
header: &JsKuwoHeader,
|
||||
ekey: Option<String>,
|
||||
) -> Result<JsDecipher, JsError> {
|
||||
let cipher = Decipher::new(&header.0, ekey).map_err(map_js_error)?;
|
||||
Ok(JsDecipher(cipher))
|
||||
}
|
||||
#[wasm_bindgen(js_name=KWMCipher)]
|
||||
pub struct JsCipher(Decipher);
|
||||
|
||||
#[wasm_bindgen(js_class=KWMCipher)]
|
||||
impl JsCipher {
|
||||
/// Decrypt buffer at given offset.
|
||||
pub fn decrypt(&self, buffer: &mut [u8], offset: usize) {
|
||||
self.0.decrypt(buffer, offset)
|
||||
|
@ -1,5 +1,4 @@
|
||||
pub mod audio;
|
||||
pub mod kgm;
|
||||
pub mod kuwo;
|
||||
pub mod ncm;
|
||||
pub mod qmc;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@unlock-music/crypto",
|
||||
"version": "0.0.0-alpha.12",
|
||||
"version": "0.0.0-alpha.11",
|
||||
"description": "Project Unlock Music: 加解密支持库",
|
||||
"scripts": {
|
||||
"build": "node build.js",
|
||||
|
Loading…
Reference in New Issue
Block a user