mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-19 21:29:52 -07:00
Add commands for importing and exporting room keys (#233)
This commit is contained in:
parent
b4e9c213e6
commit
2327658e8c
4 changed files with 116 additions and 3 deletions
32
src/main.rs
32
src/main.rs
|
@ -87,6 +87,7 @@ use crate::{
|
|||
IambId,
|
||||
IambInfo,
|
||||
IambResult,
|
||||
KeysAction,
|
||||
ProgramAction,
|
||||
ProgramContext,
|
||||
ProgramStore,
|
||||
|
@ -529,6 +530,7 @@ impl Application {
|
|||
|
||||
None
|
||||
},
|
||||
IambAction::Keys(act) => self.keys_command(act, ctx, store).await?,
|
||||
IambAction::Message(act) => {
|
||||
self.screen.current_window_mut()?.message_command(act, ctx, store).await?
|
||||
},
|
||||
|
@ -603,6 +605,36 @@ impl Application {
|
|||
}
|
||||
}
|
||||
|
||||
async fn keys_command(
|
||||
&mut self,
|
||||
action: KeysAction,
|
||||
_: ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> IambResult<EditInfo> {
|
||||
let encryption = store.application.worker.client.encryption();
|
||||
|
||||
match action {
|
||||
KeysAction::Export(path, passphrase) => {
|
||||
encryption
|
||||
.export_room_keys(path.into(), &passphrase, |_| true)
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
|
||||
Ok(Some("Successfully exported room keys".into()))
|
||||
},
|
||||
KeysAction::Import(path, passphrase) => {
|
||||
let res = encryption
|
||||
.import_room_keys(path.into(), &passphrase)
|
||||
.await
|
||||
.map_err(IambError::from)?;
|
||||
|
||||
let msg = format!("Imported {} of {} keys", res.imported_count, res.total_count);
|
||||
|
||||
Ok(Some(msg.into()))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_info(&mut self, info: InfoMessage) {
|
||||
match info {
|
||||
InfoMessage::Message(info) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue