封装两设备 MLS 客户端引擎与状态恢复
This commit is contained in:
1 parent
0b17dd07c5
commit
1e05d7a3af
7 files changed
+448
No files matched your search
@@ -0,0 +1,61 @@
|
||||
use crate::engine::Engine;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct DeviceMls(Engine);
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl DeviceMls {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(device: &str) -> Result<DeviceMls, JsError> {
|
||||
Ok(Self(Engine::new(device).map_err(JsError::new)?))
|
||||
}
|
||||
|
||||
pub fn restore(state: &[u8]) -> Result<DeviceMls, JsError> {
|
||||
Ok(Self(Engine::restore(state).map_err(JsError::new)?))
|
||||
}
|
||||
|
||||
pub fn snapshot(&self) -> Result<Vec<u8>, JsError> {
|
||||
self.0.snapshot().map_err(JsError::new)
|
||||
}
|
||||
|
||||
pub fn device(&self) -> String {
|
||||
self.0.device().to_owned()
|
||||
}
|
||||
|
||||
pub fn public_key(&self) -> Vec<u8> {
|
||||
self.0.public_key().to_vec()
|
||||
}
|
||||
|
||||
pub fn key_package(&self) -> Result<Vec<u8>, JsError> {
|
||||
self.0.key_package().map_err(JsError::new)
|
||||
}
|
||||
|
||||
pub fn start(
|
||||
&self,
|
||||
id: &[u8],
|
||||
peer: &str,
|
||||
key: &[u8],
|
||||
wire: &[u8],
|
||||
) -> Result<Vec<u8>, JsError> {
|
||||
self.0.start(id, peer, key, wire).map_err(JsError::new)
|
||||
}
|
||||
|
||||
pub fn join(&self, peer: &str, key: &[u8], wire: &[u8]) -> Result<Vec<u8>, JsError> {
|
||||
self.0.join(peer, key, wire).map_err(JsError::new)
|
||||
}
|
||||
|
||||
pub fn encrypt(&self, id: &[u8], aad: &[u8], plaintext: &[u8]) -> Result<Vec<u8>, JsError> {
|
||||
self.0.encrypt(id, aad, plaintext).map_err(JsError::new)
|
||||
}
|
||||
|
||||
pub fn decrypt(
|
||||
&self,
|
||||
peer: &str,
|
||||
key: &[u8],
|
||||
aad: &[u8],
|
||||
wire: &[u8],
|
||||
) -> Result<Vec<u8>, JsError> {
|
||||
self.0.decrypt(peer, key, aad, wire).map_err(JsError::new)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user