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
+6 -3
View File
@@ -36,6 +36,7 @@ dirs = "3.0.1"
edit = "0.1.3" edit = "0.1.3"
getopts = "0.2.21" getopts = "0.2.21"
hostname = "0.3.1" hostname = "0.3.1"
keyring = { version = "0.10.1", optional = true }
lazy_static = "1.4.0" lazy_static = "1.4.0"
log = "0.4.14" log = "0.4.14"
magic-crypt = "3.1.7" magic-crypt = "3.1.7"
@@ -70,14 +71,16 @@ version = "2.1.0"
[features] [features]
githubActions = [] 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\"))"]
[target."cfg(any(target_os = \"unix\", target_os = \"macos\", target_os = \"linux\"))".dependencies] [target."cfg(any(target_os = \"unix\", target_os = \"macos\", target_os = \"linux\"))".dependencies]
users = "0.11.0" users = "0.11.0"
[target."cfg(any(target_os = \"windows\", target_os = \"macos\"))"] [target."cfg(any(target_os = \"windows\", target_os = \"macos\", target_os = \"linux\"))"]
[target."cfg(any(target_os = \"windows\", target_os = \"macos\"))".dependencies] [target."cfg(any(target_os = \"windows\", target_os = \"macos\", target_os = \"linux\"))".features]
keyring = "0.10.1" default = [ "keyring" ]
[target."cfg(target_os = \"windows\")"] [target."cfg(target_os = \"windows\")"]
[target."cfg(target_os = \"windows\")".dependencies] [target."cfg(target_os = \"windows\")".dependencies]
+4 -3
View File
@@ -39,7 +39,6 @@ pub struct KeyringStorage {
username: String, username: String,
} }
#[cfg(not(tarpaulin_include))]
impl KeyringStorage { impl KeyringStorage {
/// ### new /// ### new
/// ///
@@ -51,7 +50,6 @@ impl KeyringStorage {
} }
} }
#[cfg(not(tarpaulin_include))]
impl KeyStorage for KeyringStorage { impl KeyStorage for KeyringStorage {
/// ### get_key /// ### get_key
/// ///
@@ -68,7 +66,10 @@ impl KeyStorage for KeyringStorage {
KeyringError::WindowsVaultError => Err(KeyStorageError::NoSuchKey), KeyringError::WindowsVaultError => Err(KeyStorageError::NoSuchKey),
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
KeyringError::MacOsKeychainError(_) => Err(KeyStorageError::NoSuchKey), 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),
}, },
} }
} }
+13 -15
View File
@@ -29,28 +29,22 @@
pub mod filestorage; pub mod filestorage;
#[cfg(any(target_os = "windows", target_os = "macos"))] #[cfg(any(target_os = "windows", target_os = "macos"))]
pub mod keyringstorage; pub mod keyringstorage;
// ext
use thiserror::Error;
/// ## KeyStorageError /// ## KeyStorageError
/// ///
/// defines the error type for the `KeyStorage` /// defines the error type for the `KeyStorage`
#[derive(PartialEq, std::fmt::Debug)] #[derive(Debug, Error, PartialEq)]
pub enum KeyStorageError { pub enum KeyStorageError {
//BadKey, #[error("Key has a bad syntax")]
BadSytax,
#[error("Provider service error")]
ProviderError, ProviderError,
#[error("No such key")]
NoSuchKey, 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 /// ## KeyStorage
/// ///
/// this traits provides the methods to communicate and interact with the key storage. /// this traits provides the methods to communicate and interact with the key storage.
@@ -83,11 +77,15 @@ mod tests {
#[test] #[test]
fn test_system_keys_mod_errors() { fn test_system_keys_mod_errors() {
assert_eq!( 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") String::from("Provider service error")
); );
assert_eq!( assert_eq!(
format!("{}", KeyStorageError::NoSuchKey), KeyStorageError::NoSuchKey.to_string(),
String::from("No such key") String::from("No such key")
); );
} }