Key load avoid warning (#1303)

* avoid warning with key

* fix intendations

* more intendation fix

* ok() instead of expect()
This commit is contained in:
Nikolay Volf 2016-06-16 16:14:22 +04:00 committed by Gav Wood
parent 10bbe8c8a2
commit 07641b8f0a
2 changed files with 15 additions and 8 deletions

View File

@ -428,9 +428,9 @@ impl KeyFileContent {
let crypto = match as_object.get("crypto") { let crypto = match as_object.get("crypto") {
None => { return Err(KeyFileParseError::NoCryptoSection); } None => { return Err(KeyFileParseError::NoCryptoSection); }
Some(crypto_json) => match KeyFileCrypto::from_json(crypto_json) { Some(crypto_json) => match KeyFileCrypto::from_json(crypto_json) {
Ok(crypto) => crypto, Ok(crypto) => crypto,
Err(crypto_error) => { return Err(KeyFileParseError::Crypto(crypto_error)); } Err(crypto_error) => { return Err(KeyFileParseError::Crypto(crypto_error)); }
} }
}; };
Ok(KeyFileContent { Ok(KeyFileContent {
@ -627,7 +627,10 @@ impl KeyDirectory {
} }
} }
/// Checks if key exists
pub fn exists(&self, id: &Uuid) -> bool {
KeyDirectory::load_key(&self.key_path(id)).is_ok()
}
} }

View File

@ -294,9 +294,9 @@ impl SecretStore {
if let Some(unlock) = read_lock.get(account) { if let Some(unlock) = read_lock.get(account) {
(unlock.relock_on_use, match crypto::KeyPair::from_secret(unlock.secret) { (unlock.relock_on_use, match crypto::KeyPair::from_secret(unlock.secret) {
Ok(pair) => match pair.sign(message) { Ok(pair) => match pair.sign(message) {
Ok(signature) => Ok(signature), Ok(signature) => Ok(signature),
Err(_) => Err(SigningError::InvalidSecret) Err(_) => Err(SigningError::InvalidSecret)
}, },
Err(_) => Err(SigningError::InvalidSecret) Err(_) => Err(SigningError::InvalidSecret)
}) })
} else { } else {
@ -348,6 +348,10 @@ impl SecretStore {
garbage_lock.shrink_to_fit(); garbage_lock.shrink_to_fit();
} }
fn exists(&self, key: &H128) -> bool {
self.directory.exists(key)
}
} }
fn derive_key_iterations(password: &str, salt: &H256, c: u32) -> (Bytes, Bytes) { fn derive_key_iterations(password: &str, salt: &H256, c: u32) -> (Bytes, Bytes) {
@ -408,7 +412,7 @@ impl EncryptedHashMap<H128> for SecretStore {
} }
fn insert<Value: FromRawBytesVariable + BytesConvertable>(&mut self, key: H128, value: Value, password: &str) -> Option<Value> { fn insert<Value: FromRawBytesVariable + BytesConvertable>(&mut self, key: H128, value: Value, password: &str) -> Option<Value> {
let previous = if let Ok(previous_value) = self.get(&key, password) { Some(previous_value) } else { None }; let previous = if !self.exists(&key) { None } else { self.get(&key, password).ok() };
// crypto random initiators // crypto random initiators
let salt = H256::random(); let salt = H256::random();