[wasm/kwm] refactor: change kwm constructors
This commit is contained in:
parent
adabbbd27e
commit
929beeb9f9
@ -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<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".
|
||||
@ -40,11 +33,11 @@ pub fn js_kuwo_bodian_cipher_factory(ekey: &str) -> Result<JsQMC2, JsError> {
|
||||
}
|
||||
|
||||
/// 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<JsQMC2, JsError> {
|
||||
}
|
||||
|
||||
/// 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<String>,
|
||||
) -> Result<JsDecipher, JsError> {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user