Add commands for importing and exporting room keys (#233)

This commit is contained in:
Ulyssa 2024-03-28 20:58:34 -07:00 committed by GitHub
parent b4e9c213e6
commit 2327658e8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 116 additions and 3 deletions

View file

@ -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) => {