This commit is contained in:
veeso 2021-06-20 11:00:31 +02:00
parent 3df8ed13a4
commit 15d13af7d5
3 changed files with 23 additions and 21 deletions

View file

@ -36,6 +36,7 @@ dirs = "3.0.1"
edit = "0.1.3"
getopts = "0.2.21"
hostname = "0.3.1"
keyring = { version = "0.10.1", optional = true }
lazy_static = "1.4.0"
log = "0.4.14"
magic-crypt = "3.1.7"
@ -70,14 +71,16 @@ version = "2.1.0"
[features]
githubActions = []
with-containers = []
with-keyring = [ "keyring" ]
[target."cfg(any(target_os = \"unix\", target_os = \"macos\", target_os = \"linux\"))"]
[target."cfg(any(target_os = \"unix\", target_os = \"macos\", target_os = \"linux\"))".dependencies]
users = "0.11.0"
[target."cfg(any(target_os = \"windows\", target_os = \"macos\"))"]
[target."cfg(any(target_os = \"windows\", target_os = \"macos\"))".dependencies]
keyring = "0.10.1"
[target."cfg(any(target_os = \"windows\", target_os = \"macos\", target_os = \"linux\"))"]
[target."cfg(any(target_os = \"windows\", target_os = \"macos\", target_os = \"linux\"))".features]
default = [ "keyring" ]
[target."cfg(target_os = \"windows\")"]
[target."cfg(target_os = \"windows\")".dependencies]

View file

@ -39,7 +39,6 @@ pub struct KeyringStorage {
username: String,
}
#[cfg(not(tarpaulin_include))]
impl KeyringStorage {
/// ### new
///
@ -51,7 +50,6 @@ impl KeyringStorage {
}
}
#[cfg(not(tarpaulin_include))]
impl KeyStorage for KeyringStorage {
/// ### get_key
///
@ -68,7 +66,10 @@ impl KeyStorage for KeyringStorage {
KeyringError::WindowsVaultError => Err(KeyStorageError::NoSuchKey),
#[cfg(target_os = "macos")]
KeyringError::MacOsKeychainError(_) => Err(KeyStorageError::NoSuchKey),
_ => panic!("{}", e),
#[cfg(target_os = "linux")]
KeyringError::SecretServiceError(SsError) => Err(KeyStorageError::ProviderError),
KeyringError::Parse(_) => Err(KeyStorageError::BadSytax),
_ => Err(KeyStorageError::ProviderError),
},
}
}

View file

@ -29,28 +29,22 @@
pub mod filestorage;
#[cfg(any(target_os = "windows", target_os = "macos"))]
pub mod keyringstorage;
// ext
use thiserror::Error;
/// ## KeyStorageError
///
/// defines the error type for the `KeyStorage`
#[derive(PartialEq, std::fmt::Debug)]
#[derive(Debug, Error, PartialEq)]
pub enum KeyStorageError {
//BadKey,
#[error("Key has a bad syntax")]
BadSytax,
#[error("Provider service error")]
ProviderError,
#[error("No such key")]
NoSuchKey,
}
impl std::fmt::Display for KeyStorageError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let err: String = String::from(match &self {
//KeyStorageError::BadKey => "Bad key syntax",
KeyStorageError::ProviderError => "Provider service error",
KeyStorageError::NoSuchKey => "No such key",
});
write!(f, "{}", err)
}
}
/// ## KeyStorage
///
/// this traits provides the methods to communicate and interact with the key storage.
@ -83,11 +77,15 @@ mod tests {
#[test]
fn test_system_keys_mod_errors() {
assert_eq!(
format!("{}", KeyStorageError::ProviderError),
KeyStorageError::BadSytax.to_string(),
String::from("Key has a bad syntax")
);
assert_eq!(
KeyStorageError::ProviderError.to_string(),
String::from("Provider service error")
);
assert_eq!(
format!("{}", KeyStorageError::NoSuchKey),
KeyStorageError::NoSuchKey.to_string(),
String::from("No such key")
);
}