From 929beeb9f99b314d2785a770e9c4c4556da3c624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Mon, 16 Sep 2024 21:28:35 +0100 Subject: [PATCH] [wasm/kwm] refactor: change kwm constructors --- um_wasm/src/exports/kuwo.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/um_wasm/src/exports/kuwo.rs b/um_wasm/src/exports/kuwo.rs index 49f129a..e037a61 100644 --- a/um_wasm/src/exports/kuwo.rs +++ b/um_wasm/src/exports/kuwo.rs @@ -23,13 +23,6 @@ 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) -> Result { - let cipher = Decipher::new(&self.0, ekey).map_err(map_js_error)?; - Ok(JsCipher(cipher)) - } } /// Create a decipher instance for "BoDian Music". @@ -40,11 +33,11 @@ pub fn js_kuwo_bodian_cipher_factory(ekey: &str) -> Result { } /// Kuwo KWM v1 -#[wasm_bindgen(js_name=KWMCipherV1)] -pub struct JsCipherV1(CipherV1); +#[wasm_bindgen(js_name=KWMDecipherV1)] +pub struct JsDecipherV1(CipherV1); -#[wasm_bindgen(js_class=KWMCipherV1)] -impl JsCipherV1 { +#[wasm_bindgen(js_class=KWMDecipherV1)] +impl JsDecipherV1 { /// Create a decipher instance for "Kuwo KWM v1". pub fn decrypt(&self, buffer: &mut [u8], offset: usize) { self.0.decrypt(buffer, offset) @@ -58,11 +51,21 @@ pub fn js_kuwo_v2_cipher_factory(ekey: &str) -> Result { } /// Common V1/V2 wrapper interface, derived from `KuwoHeader.makeCipher` -#[wasm_bindgen(js_name=KWMCipher)] -pub struct JsCipher(Decipher); +#[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, + ) -> Result { + let cipher = Decipher::new(&header.0, ekey).map_err(map_js_error)?; + Ok(JsDecipher(cipher)) + } -#[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)