Compare commits

..

No commits in common. "c5aef7dd13b9498707a690d2f9c7f73dae0f670e" and "bc4109d0c0c84355b7dae33be22d5988c06bee5f" have entirely different histories.

5 changed files with 1 additions and 66 deletions

1
Cargo.lock generated
View File

@ -447,7 +447,6 @@ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"getrandom", "getrandom",
"umc_kuwo", "umc_kuwo",
"umc_ncm",
"umc_qmc", "umc_qmc",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-test", "wasm-bindgen-test",

View File

@ -24,7 +24,6 @@ getrandom = { version = "0.2", features = ["js"] }
# 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_kuwo = { path = "../um_crypto/kuwo" } umc_kuwo = { path = "../um_crypto/kuwo" }
umc_ncm = { path = "../um_crypto/ncm" }
umc_qmc = { path = "../um_crypto/qmc" } umc_qmc = { path = "../um_crypto/qmc" }
[dev-dependencies] [dev-dependencies]

View File

@ -1,3 +1,2 @@
pub mod kuwo; pub mod kuwo;
pub mod ncm;
pub mod qmc; pub mod qmc;

View File

@ -1,62 +0,0 @@
use umc_ncm::header::NCMFile;
use umc_ncm::NetEaseCryptoError;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsError;
/// QMC Footer.
#[wasm_bindgen(js_name=NCMFile)]
pub struct JsNCMFile {
ncm: Option<NCMFile>,
}
#[wasm_bindgen(js_class=NCMFile)]
impl JsNCMFile {
/// Open NCM file.
/// If everything is ok, return `0`.
///
/// # Arguments
///
/// * `header`: Header bytes of NCM file.
///
/// returns: Result<usize, JsError>
///
/// If it needs more bytes, the new header size will be returned.
/// If the header was large enough, it will return 0.
pub fn open(&mut self, header: &[u8]) -> Result<usize, JsError> {
match NCMFile::new(header) {
Ok(ncm) => {
self.ncm = Some(ncm);
Ok(0)
}
Err(NetEaseCryptoError::HeaderTooSmall(n)) => Ok(n),
Err(err) => Err(JsError::new(err.to_string().as_str())),
}
}
/// Decrypt buffer.
///
/// # Arguments
///
/// * `buffer`: Buffer to decrypt.
/// * `offset`: Offset (start from 0, of encrypted binary data)
///
/// returns: Result<(), JsError>
pub fn decrypt(&self, buffer: &mut [u8], offset: usize) -> Result<(), JsError> {
if let Some(ncm) = &self.ncm {
ncm.decrypt(buffer, offset);
Ok(())
} else {
Err(JsError::new("NCMFile not initialized."))
}
}
/// Get audio data offset.
#[wasm_bindgen(getter, js_name=audioOffset)]
pub fn get_audio_offset(&self) -> Result<usize, JsError> {
if let Some(ncm) = &self.ncm {
Ok(ncm.audio_data_offset)
} else {
Err(JsError::new("NCMFile not initialized."))
}
}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@um/crypto", "name": "@um/crypto",
"version": "0.0.0-alpha.2", "version": "0.0.0-alpha.1",
"description": "Project Unlock Music: 加解密支持库", "description": "Project Unlock Music: 加解密支持库",
"scripts": { "scripts": {
"build": "node build.js", "build": "node build.js",