encrypt/decrypt and db interaction

This commit is contained in:
jfmonty2 committed 2022-12-03 21:47:09 -08:00
1 parent 196510e9a2
commit 1e4e1c9a5f
9 files changed
+375 -49

No files matched your search

+17 -6
View File
@@ -1,8 +1,7 @@
use serde::{Serialize, Deserialize};
use tauri::State;
use crate::state::AppState;
use crate::storage;
use crate::state::{AppState, Session};
#[derive(Copy, Clone, Serialize, Deserialize)]
@@ -33,9 +32,21 @@ pub fn respond(response: RequestResponse, app_state: State<'_, AppState>) -> Res
#[tauri::command]
pub fn unlock(passphrase: String, app_state: State<'_, AppState>) -> bool {
let root_credentials = storage::load(&passphrase);
app_state.set_creds(root_credentials); // for now
true
pub async fn unlock(passphrase: String, app_state: State<'_, AppState>) -> Result<(), String> {
app_state.decrypt(&passphrase)
.await
.map_err(|e| e.to_string())?;
Ok(())
}
#[tauri::command]
pub fn session_status(app_state: State<'_, AppState>) -> String {
let session = app_state.session.read().unwrap();
match *session {
Session::Locked(_) => "locked".into(),
Session::Unlocked(_) => "unlocked".into(),
Session::Empty => "empty".into()
}
}