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

Key load avoid warning #1303

Merged
merged 4 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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