Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Key load avoid warning (#1303)
Browse files Browse the repository at this point in the history
* avoid warning with key

* fix intendations

* more intendation fix

* ok() instead of expect()
  • Loading branch information
NikVolf authored and gavofyork committed Jun 16, 2016
1 parent 10bbe8c commit 07641b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions util/src/keys/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ impl KeyFileContent {
let crypto = match as_object.get("crypto") {
None => { return Err(KeyFileParseError::NoCryptoSection); }
Some(crypto_json) => match KeyFileCrypto::from_json(crypto_json) {
Ok(crypto) => crypto,
Err(crypto_error) => { return Err(KeyFileParseError::Crypto(crypto_error)); }
}
Ok(crypto) => crypto,
Err(crypto_error) => { return Err(KeyFileParseError::Crypto(crypto_error)); }
}
};

Ok(KeyFileContent {
Expand Down Expand Up @@ -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()
}
}


Expand Down
12 changes: 8 additions & 4 deletions util/src/keys/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ impl SecretStore {
if let Some(unlock) = read_lock.get(account) {
(unlock.relock_on_use, match crypto::KeyPair::from_secret(unlock.secret) {
Ok(pair) => match pair.sign(message) {
Ok(signature) => Ok(signature),
Err(_) => Err(SigningError::InvalidSecret)
},
Ok(signature) => Ok(signature),
Err(_) => Err(SigningError::InvalidSecret)
},
Err(_) => Err(SigningError::InvalidSecret)
})
} else {
Expand Down Expand Up @@ -348,6 +348,10 @@ impl SecretStore {

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) {
Expand Down Expand Up @@ -408,7 +412,7 @@ impl EncryptedHashMap<H128> for SecretStore {
}

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
let salt = H256::random();
Expand Down

0 comments on commit 07641b8

Please sign in to comment.