Fixed unused imports and variables
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::session::SessionManager;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn register_rhai_api<S: kvstore::traits::KVStore + Send + Sync + Clone + 'static>(
|
||||
engine: &mut Engine,
|
||||
session_manager: std::sync::Arc<std::sync::Mutex<SessionManager<S>>>,
|
||||
_session_manager: std::sync::Arc<std::sync::Mutex<SessionManager<S>>>,
|
||||
) {
|
||||
engine.register_type::<RhaiSessionManager<S>>();
|
||||
engine.register_fn("select_keypair", RhaiSessionManager::<S>::select_keypair);
|
||||
@@ -37,7 +37,7 @@ impl<S: kvstore::traits::KVStore + Send + Sync + Clone + 'static> RhaiSessionMan
|
||||
// Use Mutex for interior mutability, &self is sufficient
|
||||
self.inner.lock().unwrap().select_keypair(&key_id).map_err(|e| format!("select_keypair error: {e}"))
|
||||
}
|
||||
|
||||
|
||||
pub fn select_default_keypair(&self) -> Result<(), String> {
|
||||
self.inner.lock().unwrap().select_default_keypair()
|
||||
.map_err(|e| format!("select_default_keypair error: {e}"))
|
||||
|
@@ -3,7 +3,6 @@
|
||||
//! All state is local to the SessionManager instance. No global state.
|
||||
|
||||
use crate::{KVStore, KeyEntry, KeyspaceData, Vault, VaultError};
|
||||
use std::collections::HashMap;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
/// SessionManager: Ergonomic, stateful wrapper over the Vault stateless API.
|
||||
@@ -130,17 +129,17 @@ impl<S: KVStore + Send + Sync> SessionManager<S> {
|
||||
self.current_keyspace()
|
||||
.and_then(|ks| ks.keypairs.first())
|
||||
}
|
||||
|
||||
|
||||
/// Selects the default keypair (first keypair) as the current keypair.
|
||||
pub fn select_default_keypair(&mut self) -> Result<(), VaultError> {
|
||||
let default_id = self
|
||||
.default_keypair()
|
||||
.map(|k| k.id.clone())
|
||||
.ok_or_else(|| VaultError::Crypto("No default keypair found".to_string()))?;
|
||||
|
||||
|
||||
self.select_keypair(&default_id)
|
||||
}
|
||||
|
||||
|
||||
/// Returns true if the current keypair is the default keypair (first keypair).
|
||||
pub fn is_default_keypair_selected(&self) -> bool {
|
||||
match (self.current_keypair(), self.default_keypair()) {
|
||||
@@ -312,17 +311,17 @@ impl<S: KVStore> SessionManager<S> {
|
||||
self.current_keyspace()
|
||||
.and_then(|ks| ks.keypairs.first())
|
||||
}
|
||||
|
||||
|
||||
/// Selects the default keypair (first keypair) as the current keypair.
|
||||
pub fn select_default_keypair(&mut self) -> Result<(), VaultError> {
|
||||
let default_id = self
|
||||
.default_keypair()
|
||||
.map(|k| k.id.clone())
|
||||
.ok_or_else(|| VaultError::Crypto("No default keypair found".to_string()))?;
|
||||
|
||||
|
||||
self.select_keypair(&default_id)
|
||||
}
|
||||
|
||||
|
||||
/// Returns true if the current keypair is the default keypair (first keypair).
|
||||
pub fn is_default_keypair_selected(&self) -> bool {
|
||||
match (self.current_keypair(), self.default_keypair()) {
|
||||
|
@@ -26,6 +26,8 @@ async fn test_keypair_management_and_crypto() {
|
||||
vault.create_keyspace(keyspace, password, None).await.unwrap();
|
||||
|
||||
debug!("after create_keyspace: keyspace={} password={}", keyspace, hex::encode(password));
|
||||
let keys = vault.list_keypairs(keyspace, password).await.unwrap();
|
||||
assert_eq!(keys.len(), 1); // should be 1 because we added a default keypair on create_keyspace
|
||||
debug!("before add Ed25519 keypair");
|
||||
let key_id = vault.add_keypair(keyspace, password, Some(KeyType::Ed25519), Some(KeyMetadata { name: Some("edkey".into()), created_at: None, tags: None })).await;
|
||||
match &key_id {
|
||||
@@ -38,7 +40,7 @@ async fn test_keypair_management_and_crypto() {
|
||||
|
||||
debug!("before list_keypairs");
|
||||
let keys = vault.list_keypairs(keyspace, password).await.unwrap();
|
||||
assert_eq!(keys.len(), 2);
|
||||
assert_eq!(keys.len(), 3);
|
||||
|
||||
debug!("before export Ed25519 keypair");
|
||||
let (priv_bytes, pub_bytes) = vault.export_keypair(keyspace, password, &key_id).await.unwrap();
|
||||
@@ -65,5 +67,5 @@ async fn test_keypair_management_and_crypto() {
|
||||
// Remove a keypair
|
||||
vault.remove_keypair(keyspace, password, &key_id).await.unwrap();
|
||||
let keys = vault.list_keypairs(keyspace, password).await.unwrap();
|
||||
assert_eq!(keys.len(), 1);
|
||||
assert_eq!(keys.len(), 2);
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ async fn session_manager_end_to_end() {
|
||||
use tempfile::TempDir;
|
||||
let tmp_dir = TempDir::new().expect("create temp dir");
|
||||
let store = NativeStore::open(tmp_dir.path().to_str().unwrap()).expect("open NativeStore");
|
||||
let mut vault = Vault::new(store);
|
||||
let vault = Vault::new(store);
|
||||
let keyspace = "personal";
|
||||
let password = b"testpass";
|
||||
|
||||
|
Reference in New Issue
Block a user