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

Commit

Permalink
Handle geth keys with lowercase crypto key
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Apr 3, 2016
1 parent 4854f69 commit 27fcc49
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions util/src/keys/geth_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use keys::store::SecretStore;
use keys::directory::KeyFileContent;

/// Enumerates all geth keys in the directory and returns collection of tuples `(accountId, filename)`
pub fn enumerate_geth_keys(path: &Path) -> Result<Vec<(Address, String)>, io::Error> {
pub fn enumerate_geth_keys(path: &Path) -> Result<Vec<(Address, String)>, ImportError> {
let mut entries = Vec::new();
for entry in try!(fs::read_dir(path)) {
let entry = try!(entry);
Expand All @@ -30,10 +30,8 @@ pub fn enumerate_geth_keys(path: &Path) -> Result<Vec<(Address, String)>, io::Er
Some(name) => {
let parts: Vec<&str> = name.split("--").collect();
if parts.len() != 3 { continue; }
match Address::from_str(parts[2]) {
Ok(account_id) => { entries.push((account_id, name.to_owned())); }
Err(e) => { panic!("error: {:?}", e); }
}
let account_id = try!(Address::from_str(parts[2]).map_err(|_| ImportError::Format));
entries.push((account_id, name.to_owned()));
},
None => { continue; }
};
Expand Down Expand Up @@ -68,9 +66,10 @@ pub fn import_geth_key(secret_store: &mut SecretStore, geth_keyfile_path: &Path)
Ok(ref mut parsed_json) => try!(parsed_json.as_object_mut().ok_or(ImportError::Format)),
Err(_) => { return Err(ImportError::Format); }
};
let crypto_object = try!(json.get("Crypto").and_then(|crypto| crypto.as_object()).ok_or(ImportError::Format)).clone();
json.insert("crypto".to_owned(), Json::Object(crypto_object));
json.remove("Crypto");
if let Some(crypto_object) = json.get("Crypto").and_then(|crypto| crypto.as_object()).cloned() {
json.insert("crypto".to_owned(), Json::Object(crypto_object));
json.remove("Crypto");
}
match KeyFileContent::load(&Json::Object(json.clone())) {
Ok(key_file) => try!(secret_store.import_key(key_file)),
Err(_) => { return Err(ImportError::Format); }
Expand Down

0 comments on commit 27fcc49

Please sign in to comment.