Port try macro to new ? operator. (#3962)

* initial untry sweep

* restore try in ipc codegen, fix inference

* change a few missed try instances
This commit is contained in:
Robert Habermeier
2016-12-27 12:53:56 +01:00
committed by Arkadiy Paronyan
parent b1ef52a6d7
commit 8125b5690c
165 changed files with 1696 additions and 1696 deletions

View File

@@ -113,7 +113,7 @@ impl Crypto {
let (derived_left_bits, derived_right_bits) = match self.kdf {
Kdf::Pbkdf2(ref params) => crypto::derive_key_iterations(password, &params.salt, params.c),
Kdf::Scrypt(ref params) => try!(crypto::derive_key_scrypt(password, &params.salt, params.n, params.p, params.r)),
Kdf::Scrypt(ref params) => crypto::derive_key_scrypt(password, &params.salt, params.n, params.p, params.r)?,
};
let mac = crypto::derive_mac(&derived_right_bits, &self.ciphertext).keccak256();
@@ -171,22 +171,22 @@ impl SafeAccount {
}
pub fn sign(&self, password: &str, message: &Message) -> Result<Signature, Error> {
let secret = try!(self.crypto.secret(password));
let secret = self.crypto.secret(password)?;
sign(&secret, message).map_err(From::from)
}
pub fn decrypt(&self, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
let secret = try!(self.crypto.secret(password));
let secret = self.crypto.secret(password)?;
crypto::ecies::decrypt(&secret, shared_mac, message).map_err(From::from)
}
pub fn public(&self, password: &str) -> Result<Public, Error> {
let secret = try!(self.crypto.secret(password));
Ok(try!(KeyPair::from_secret(secret)).public().clone())
let secret = self.crypto.secret(password)?;
Ok(KeyPair::from_secret(secret)?.public().clone())
}
pub fn change_password(&self, old_password: &str, new_password: &str, iterations: u32) -> Result<Self, Error> {
let secret = try!(self.crypto.secret(old_password));
let secret = self.crypto.secret(old_password)?;
let result = SafeAccount {
id: self.id.clone(),
version: self.version.clone(),

View File

@@ -93,11 +93,11 @@ fn main() {
fn key_dir(location: &str) -> Result<Box<KeyDirectory>, Error> {
let dir: Box<KeyDirectory> = match location {
"parity" => Box::new(try!(ParityDirectory::create(DirectoryType::Main))),
"parity-test" => Box::new(try!(ParityDirectory::create(DirectoryType::Testnet))),
"geth" => Box::new(try!(GethDirectory::create(DirectoryType::Main))),
"geth-test" => Box::new(try!(GethDirectory::create(DirectoryType::Testnet))),
path => Box::new(try!(DiskDirectory::create(path))),
"parity" => Box::new(ParityDirectory::create(DirectoryType::Main)?),
"parity-test" => Box::new(ParityDirectory::create(DirectoryType::Testnet)?),
"geth" => Box::new(GethDirectory::create(DirectoryType::Main)?),
"geth-test" => Box::new(GethDirectory::create(DirectoryType::Testnet)?),
path => Box::new(DiskDirectory::create(path)?),
};
Ok(dir)
@@ -112,9 +112,9 @@ fn format_accounts(accounts: &[Address]) -> String {
}
fn load_password(path: &str) -> Result<String, Error> {
let mut file = try!(fs::File::open(path));
let mut file = fs::File::open(path)?;
let mut password = String::new();
try!(file.read_to_string(&mut password));
file.read_to_string(&mut password)?;
// drop EOF
let _ = password.pop();
Ok(password)
@@ -125,48 +125,48 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
.and_then(|d| d.argv(command).decode())
.unwrap_or_else(|e| e.exit());
let store = try!(EthStore::open(try!(key_dir(&args.flag_dir))));
let store = EthStore::open(key_dir(&args.flag_dir)?)?;
return if args.cmd_insert {
let secret = try!(args.arg_secret.parse().map_err(|_| Error::InvalidSecret));
let password = try!(load_password(&args.arg_password));
let address = try!(store.insert_account(secret, &password));
let secret = args.arg_secret.parse().map_err(|_| Error::InvalidSecret)?;
let password = load_password(&args.arg_password)?;
let address = store.insert_account(secret, &password)?;
Ok(format!("0x{:?}", address))
} else if args.cmd_change_pwd {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let old_pwd = try!(load_password(&args.arg_old_pwd));
let new_pwd = try!(load_password(&args.arg_new_pwd));
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
let old_pwd = load_password(&args.arg_old_pwd)?;
let new_pwd = load_password(&args.arg_new_pwd)?;
let ok = store.change_password(&address, &old_pwd, &new_pwd).is_ok();
Ok(format!("{}", ok))
} else if args.cmd_list {
let accounts = try!(store.accounts());
let accounts = store.accounts()?;
Ok(format_accounts(&accounts))
} else if args.cmd_import {
let src = try!(key_dir(&args.flag_src));
let dst = try!(key_dir(&args.flag_dir));
let accounts = try!(import_accounts(&*src, &*dst));
let src = key_dir(&args.flag_src)?;
let dst = key_dir(&args.flag_dir)?;
let accounts = import_accounts(&*src, &*dst)?;
Ok(format_accounts(&accounts))
} else if args.cmd_import_wallet {
let wallet = try!(PresaleWallet::open(&args.arg_path));
let password = try!(load_password(&args.arg_password));
let kp = try!(wallet.decrypt(&password));
let address = try!(store.insert_account(kp.secret().clone(), &password));
let wallet = PresaleWallet::open(&args.arg_path)?;
let password = load_password(&args.arg_password)?;
let kp = wallet.decrypt(&password)?;
let address = store.insert_account(kp.secret().clone(), &password)?;
Ok(format!("0x{:?}", address))
} else if args.cmd_remove {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let password = try!(load_password(&args.arg_password));
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
let password = load_password(&args.arg_password)?;
let ok = store.remove_account(&address, &password).is_ok();
Ok(format!("{}", ok))
} else if args.cmd_sign {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let message = try!(args.arg_message.parse().map_err(|_| Error::InvalidMessage));
let password = try!(load_password(&args.arg_password));
let signature = try!(store.sign(&address, &password, &message));
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
let message = args.arg_message.parse().map_err(|_| Error::InvalidMessage)?;
let password = load_password(&args.arg_password)?;
let signature = store.sign(&address, &password, &message)?;
Ok(format!("0x{:?}", signature))
} else if args.cmd_public {
let address = try!(args.arg_address.parse().map_err(|_| Error::InvalidAccount));
let password = try!(load_password(&args.arg_password));
let public = try!(store.public(&address, &password));
let address = args.arg_address.parse().map_err(|_| Error::InvalidAccount)?;
let password = load_password(&args.arg_password)?;
let public = store.public(&address, &password)?;
Ok(format!("0x{:?}", public))
} else {
Ok(format!("{}", USAGE))

View File

@@ -29,8 +29,8 @@ fn restrict_permissions_to_owner(file_path: &Path) -> Result<(), i32> {
use std::ffi;
use libc;
let cstr = try!(ffi::CString::new(&*file_path.to_string_lossy())
.map_err(|_| -1));
let cstr = ffi::CString::new(&*file_path.to_string_lossy())
.map_err(|_| -1)?;
match unsafe { libc::chmod(cstr.as_ptr(), libc::S_IWUSR | libc::S_IRUSR) } {
0 => Ok(()),
x => Err(x),
@@ -48,7 +48,7 @@ pub struct DiskDirectory {
impl DiskDirectory {
pub fn create<P>(path: P) -> Result<Self, Error> where P: AsRef<Path> {
try!(fs::create_dir_all(&path));
fs::create_dir_all(&path)?;
Ok(Self::at(path))
}
@@ -62,7 +62,7 @@ impl DiskDirectory {
fn files(&self) -> Result<HashMap<PathBuf, SafeAccount>, Error> {
// it's not done using one iterator cause
// there is an issue with rustc and it takes tooo much time to compile
let paths = try!(fs::read_dir(&self.path))
let paths = fs::read_dir(&self.path)?
.flat_map(Result::ok)
.filter(|entry| {
let metadata = entry.metadata().ok();
@@ -102,7 +102,7 @@ impl DiskDirectory {
impl KeyDirectory for DiskDirectory {
fn load(&self) -> Result<Vec<SafeAccount>, Error> {
let accounts = try!(self.files())
let accounts = self.files()?
.into_iter()
.map(|(_, account)| account)
.collect();
@@ -134,8 +134,8 @@ impl KeyDirectory for DiskDirectory {
keyfile_path.push(filename.as_str());
// save the file
let mut file = try!(fs::File::create(&keyfile_path));
try!(keyfile.write(&mut file).map_err(|e| Error::Custom(format!("{:?}", e))));
let mut file = fs::File::create(&keyfile_path)?;
keyfile.write(&mut file).map_err(|e| Error::Custom(format!("{:?}", e)))?;
if let Err(_) = restrict_permissions_to_owner(keyfile_path.as_path()) {
fs::remove_file(keyfile_path).expect("Expected to remove recently created file");
@@ -149,7 +149,7 @@ impl KeyDirectory for DiskDirectory {
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
// enumerate all entries in keystore
// and find entry with given address
let to_remove = try!(self.files())
let to_remove = self.files()?
.into_iter()
.find(|&(_, ref acc)| acc == account);

View File

@@ -66,7 +66,7 @@ pub struct GethDirectory {
impl GethDirectory {
pub fn create(t: DirectoryType) -> Result<Self, Error> {
let result = GethDirectory {
dir: try!(DiskDirectory::create(geth_keystore(t))),
dir: DiskDirectory::create(geth_keystore(t))?,
};
Ok(result)

View File

@@ -45,7 +45,7 @@ pub struct ParityDirectory {
impl ParityDirectory {
pub fn create(t: DirectoryType) -> Result<Self, Error> {
let result = ParityDirectory {
dir: try!(DiskDirectory::create(parity_keystore(t))),
dir: DiskDirectory::create(parity_keystore(t))?,
};
Ok(result)

View File

@@ -38,12 +38,12 @@ impl EthStore {
pub fn open_with_iterations(directory: Box<KeyDirectory>, iterations: u32) -> Result<Self, Error> {
Ok(EthStore {
store: try!(EthMultiStore::open_with_iterations(directory, iterations)),
store: EthMultiStore::open_with_iterations(directory, iterations)?,
})
}
fn get(&self, address: &Address) -> Result<SafeAccount, Error> {
let mut accounts = try!(self.store.get(address)).into_iter();
let mut accounts = self.store.get(address)?.into_iter();
accounts.next().ok_or(Error::InvalidAccount)
}
}
@@ -66,68 +66,68 @@ impl SimpleSecretStore for EthStore {
}
fn sign(&self, address: &Address, password: &str, message: &Message) -> Result<Signature, Error> {
let account = try!(self.get(address));
let account = self.get(address)?;
account.sign(password, message)
}
fn decrypt(&self, account: &Address, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
let account = try!(self.get(account));
let account = self.get(account)?;
account.decrypt(password, shared_mac, message)
}
}
impl SecretStore for EthStore {
fn import_presale(&self, json: &[u8], password: &str) -> Result<Address, Error> {
let json_wallet = try!(json::PresaleWallet::load(json).map_err(|_| Error::InvalidKeyFile("Invalid JSON format".to_owned())));
let json_wallet = json::PresaleWallet::load(json).map_err(|_| Error::InvalidKeyFile("Invalid JSON format".to_owned()))?;
let wallet = PresaleWallet::from(json_wallet);
let keypair = try!(wallet.decrypt(password).map_err(|_| Error::InvalidPassword));
let keypair = wallet.decrypt(password).map_err(|_| Error::InvalidPassword)?;
self.insert_account(keypair.secret().clone(), password)
}
fn import_wallet(&self, json: &[u8], password: &str) -> Result<Address, Error> {
let json_keyfile = try!(json::KeyFile::load(json).map_err(|_| Error::InvalidKeyFile("Invalid JSON format".to_owned())));
let json_keyfile = json::KeyFile::load(json).map_err(|_| Error::InvalidKeyFile("Invalid JSON format".to_owned()))?;
let mut safe_account = SafeAccount::from_file(json_keyfile, None);
let secret = try!(safe_account.crypto.secret(password).map_err(|_| Error::InvalidPassword));
safe_account.address = try!(KeyPair::from_secret(secret)).address();
let secret = safe_account.crypto.secret(password).map_err(|_| Error::InvalidPassword)?;
safe_account.address = KeyPair::from_secret(secret)?.address();
let address = safe_account.address.clone();
try!(self.store.import(safe_account));
self.store.import(safe_account)?;
Ok(address)
}
fn test_password(&self, address: &Address, password: &str) -> Result<bool, Error> {
let account = try!(self.get(address));
let account = self.get(address)?;
Ok(account.check_password(password))
}
fn copy_account(&self, new_store: &SimpleSecretStore, address: &Address, password: &str, new_password: &str) -> Result<(), Error> {
let account = try!(self.get(address));
let secret = try!(account.crypto.secret(password));
try!(new_store.insert_account(secret, new_password));
let account = self.get(address)?;
let secret = account.crypto.secret(password)?;
new_store.insert_account(secret, new_password)?;
Ok(())
}
fn public(&self, account: &Address, password: &str) -> Result<Public, Error> {
let account = try!(self.get(account));
let account = self.get(account)?;
account.public(password)
}
fn uuid(&self, address: &Address) -> Result<Uuid, Error> {
let account = try!(self.get(address));
let account = self.get(address)?;
Ok(account.id.into())
}
fn name(&self, address: &Address) -> Result<String, Error> {
let account = try!(self.get(address));
let account = self.get(address)?;
Ok(account.name.clone())
}
fn meta(&self, address: &Address) -> Result<String, Error> {
let account = try!(self.get(address));
let account = self.get(address)?;
Ok(account.meta.clone())
}
fn set_name(&self, address: &Address, name: String) -> Result<(), Error> {
let old = try!(self.get(address));
let old = self.get(address)?;
let mut account = old.clone();
account.name = name;
@@ -136,7 +136,7 @@ impl SecretStore for EthStore {
}
fn set_meta(&self, address: &Address, meta: String) -> Result<(), Error> {
let old = try!(self.get(address));
let old = self.get(address)?;
let mut account = old.clone();
account.meta = meta;
@@ -176,13 +176,13 @@ impl EthMultiStore {
iterations: iterations,
cache: Default::default(),
};
try!(store.reload_accounts());
store.reload_accounts()?;
Ok(store)
}
fn reload_accounts(&self) -> Result<(), Error> {
let mut cache = self.cache.write();
let accounts = try!(self.dir.load());
let accounts = self.dir.load()?;
let mut new_accounts = BTreeMap::new();
for account in accounts {
@@ -203,9 +203,9 @@ impl EthMultiStore {
}
}
try!(self.reload_accounts());
self.reload_accounts()?;
let cache = self.cache.read();
let accounts = try!(cache.get(address).cloned().ok_or(Error::InvalidAccount));
let accounts = cache.get(address).cloned().ok_or(Error::InvalidAccount)?;
if accounts.is_empty() {
Err(Error::InvalidAccount)
} else {
@@ -215,7 +215,7 @@ impl EthMultiStore {
fn import(&self, account: SafeAccount) -> Result<(), Error> {
// save to file
let account = try!(self.dir.insert(account));
let account = self.dir.insert(account)?;
// update cache
let mut cache = self.cache.write();
@@ -226,7 +226,7 @@ impl EthMultiStore {
fn update(&self, old: SafeAccount, new: SafeAccount) -> Result<(), Error> {
// save to file
let account = try!(self.dir.update(new));
let account = self.dir.update(new)?;
// update cache
let mut cache = self.cache.write();
@@ -243,21 +243,21 @@ impl EthMultiStore {
impl SimpleSecretStore for EthMultiStore {
fn insert_account(&self, secret: Secret, password: &str) -> Result<Address, Error> {
let keypair = try!(KeyPair::from_secret(secret).map_err(|_| Error::CreationFailed));
let keypair = KeyPair::from_secret(secret).map_err(|_| Error::CreationFailed)?;
let id: [u8; 16] = Random::random();
let account = SafeAccount::create(&keypair, id, password, self.iterations, "".to_owned(), "{}".to_owned());
let address = account.address.clone();
try!(self.import(account));
self.import(account)?;
Ok(address)
}
fn accounts(&self) -> Result<Vec<Address>, Error> {
try!(self.reload_accounts());
self.reload_accounts()?;
Ok(self.cache.read().keys().cloned().collect())
}
fn remove_account(&self, address: &Address, password: &str) -> Result<(), Error> {
let accounts = try!(self.get(address));
let accounts = self.get(address)?;
for account in accounts {
// Skip if password is invalid
@@ -266,7 +266,7 @@ impl SimpleSecretStore for EthMultiStore {
}
// Remove from dir
try!(self.dir.remove(&account));
self.dir.remove(&account)?;
// Remove from cache
let mut cache = self.cache.write();
@@ -288,17 +288,17 @@ impl SimpleSecretStore for EthMultiStore {
}
fn change_password(&self, address: &Address, old_password: &str, new_password: &str) -> Result<(), Error> {
let accounts = try!(self.get(address));
let accounts = self.get(address)?;
for account in accounts {
// Change password
let new_account = try!(account.change_password(old_password, new_password, self.iterations));
try!(self.update(account, new_account));
let new_account = account.change_password(old_password, new_password, self.iterations)?;
self.update(account, new_account)?;
}
Ok(())
}
fn sign(&self, address: &Address, password: &str, message: &Message) -> Result<Signature, Error> {
let accounts = try!(self.get(address));
let accounts = self.get(address)?;
for account in accounts {
if account.check_password(password) {
return account.sign(password, message);
@@ -309,7 +309,7 @@ impl SimpleSecretStore for EthMultiStore {
}
fn decrypt(&self, account: &Address, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
let accounts = try!(self.get(account));
let accounts = self.get(account)?;
for account in accounts {
if account.check_password(password) {
return account.decrypt(password, shared_mac, message);

View File

@@ -20,14 +20,14 @@ use dir::{GethDirectory, KeyDirectory, DirectoryType};
use Error;
pub fn import_accounts(src: &KeyDirectory, dst: &KeyDirectory) -> Result<Vec<Address>, Error> {
let accounts = try!(src.load());
let existing_accounts = try!(dst.load()).into_iter().map(|a| a.address).collect::<HashSet<_>>();
let accounts = src.load()?;
let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>();
accounts.into_iter()
.filter(|a| !existing_accounts.contains(&a.address))
.map(|a| {
let address = a.address.clone();
try!(dst.insert(a));
dst.insert(a)?;
Ok(address)
}).collect()
}
@@ -55,15 +55,15 @@ pub fn import_geth_accounts(dst: &KeyDirectory, desired: HashSet<Address>, testn
};
let src = GethDirectory::open(t);
let accounts = try!(src.load());
let existing_accounts = try!(dst.load()).into_iter().map(|a| a.address).collect::<HashSet<_>>();
let accounts = src.load()?;
let existing_accounts = dst.load()?.into_iter().map(|a| a.address).collect::<HashSet<_>>();
accounts.into_iter()
.filter(|a| !existing_accounts.contains(&a.address))
.filter(|a| desired.contains(&a.address))
.map(|a| {
let address = a.address.clone();
try!(dst.insert(a));
dst.insert(a)?;
Ok(address)
}).collect()
}

View File

@@ -17,8 +17,8 @@ impl Deserialize for Bytes {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
where D: Deserializer
{
let s = try!(String::deserialize(deserializer));
let data = try!(s.from_hex().map_err(|e| Error::custom(format!("Invalid hex value {}", e))));
let s = String::deserialize(deserializer)?;
let data = s.from_hex().map_err(|e| Error::custom(format!("Invalid hex value {}", e)))?;
Ok(Bytes(data))
}
}

View File

@@ -90,13 +90,13 @@ impl Visitor for CryptoVisitor {
let mut mac = None;
loop {
match try!(visitor.visit_key()) {
Some(CryptoField::Cipher) => { cipher = Some(try!(visitor.visit_value())); }
Some(CryptoField::CipherParams) => { cipherparams = Some(try!(visitor.visit_value())); }
Some(CryptoField::CipherText) => { ciphertext = Some(try!(visitor.visit_value())); }
Some(CryptoField::Kdf) => { kdf = Some(try!(visitor.visit_value())); }
Some(CryptoField::KdfParams) => { kdfparams = Some(try!(visitor.visit_value())); }
Some(CryptoField::Mac) => { mac = Some(try!(visitor.visit_value())); }
match visitor.visit_key()? {
Some(CryptoField::Cipher) => { cipher = Some(visitor.visit_value()?); }
Some(CryptoField::CipherParams) => { cipherparams = Some(visitor.visit_value()?); }
Some(CryptoField::CipherText) => { ciphertext = Some(visitor.visit_value()?); }
Some(CryptoField::Kdf) => { kdf = Some(visitor.visit_value()?); }
Some(CryptoField::KdfParams) => { kdfparams = Some(visitor.visit_value()?); }
Some(CryptoField::Mac) => { mac = Some(visitor.visit_value()?); }
None => { break; }
}
}
@@ -109,7 +109,7 @@ impl Visitor for CryptoVisitor {
let ciphertext = match ciphertext {
Some(ciphertext) => ciphertext,
None => try!(visitor.missing_field("ciphertext")),
None => visitor.missing_field("ciphertext")?,
};
let kdf = match (kdf, kdfparams) {
@@ -122,10 +122,10 @@ impl Visitor for CryptoVisitor {
let mac = match mac {
Some(mac) => mac,
None => try!(visitor.missing_field("mac")),
None => visitor.missing_field("mac")?,
};
try!(visitor.end());
visitor.end()?;
let result = Crypto {
cipher: cipher,
@@ -142,26 +142,26 @@ impl Serialize for Crypto {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer
{
let mut state = try!(serializer.serialize_struct("Crypto", 6));
let mut state = serializer.serialize_struct("Crypto", 6)?;
match self.cipher {
Cipher::Aes128Ctr(ref params) => {
try!(serializer.serialize_struct_elt(&mut state, "cipher", &CipherSer::Aes128Ctr));
try!(serializer.serialize_struct_elt(&mut state, "cipherparams", params));
serializer.serialize_struct_elt(&mut state, "cipher", &CipherSer::Aes128Ctr)?;
serializer.serialize_struct_elt(&mut state, "cipherparams", params)?;
},
}
try!(serializer.serialize_struct_elt(&mut state, "ciphertext", &self.ciphertext));
serializer.serialize_struct_elt(&mut state, "ciphertext", &self.ciphertext)?;
match self.kdf {
Kdf::Pbkdf2(ref params) => {
try!(serializer.serialize_struct_elt(&mut state, "kdf", &KdfSer::Pbkdf2));
try!(serializer.serialize_struct_elt(&mut state, "kdfparams", params));
serializer.serialize_struct_elt(&mut state, "kdf", &KdfSer::Pbkdf2)?;
serializer.serialize_struct_elt(&mut state, "kdfparams", params)?;
},
Kdf::Scrypt(ref params) => {
try!(serializer.serialize_struct_elt(&mut state, "kdf", &KdfSer::Scrypt));
try!(serializer.serialize_struct_elt(&mut state, "kdfparams", params));
serializer.serialize_struct_elt(&mut state, "kdf", &KdfSer::Scrypt)?;
serializer.serialize_struct_elt(&mut state, "kdfparams", params)?;
},
}
try!(serializer.serialize_struct_elt(&mut state, "mac", &self.mac));
serializer.serialize_struct_elt(&mut state, "mac", &self.mac)?;
serializer.serialize_struct_end(state)
}
}

View File

@@ -62,7 +62,7 @@ impl fmt::Display for Uuid {
}
fn copy_into(from: &str, into: &mut [u8]) -> Result<(), Error> {
let from = try!(from.from_hex().map_err(|_| Error::InvalidUuid));
let from = from.from_hex().map_err(|_| Error::InvalidUuid)?;
if from.len() != into.len() {
return Err(Error::InvalidUuid);
@@ -84,11 +84,11 @@ impl str::FromStr for Uuid {
let mut uuid = [0u8; 16];
try!(copy_into(parts[0], &mut uuid[0..4]));
try!(copy_into(parts[1], &mut uuid[4..6]));
try!(copy_into(parts[2], &mut uuid[6..8]));
try!(copy_into(parts[3], &mut uuid[8..10]));
try!(copy_into(parts[4], &mut uuid[10..16]));
copy_into(parts[0], &mut uuid[0..4])?;
copy_into(parts[1], &mut uuid[4..6])?;
copy_into(parts[2], &mut uuid[6..8])?;
copy_into(parts[3], &mut uuid[8..10])?;
copy_into(parts[4], &mut uuid[10..16])?;
Ok(Uuid(uuid))
}

View File

@@ -134,7 +134,7 @@ impl Serialize for KdfSerParams {
impl Deserialize for KdfSerParams {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
where D: Deserializer {
let v = try!(Value::deserialize(deserializer));
let v = Value::deserialize(deserializer)?;
Deserialize::deserialize(&mut value::Deserializer::new(v.clone())).map(KdfSerParams::Pbkdf2)
.or_else(|_| Deserialize::deserialize(&mut value::Deserializer::new(v)).map(KdfSerParams::Scrypt))

View File

@@ -93,11 +93,11 @@ impl Visitor for KeyFileVisitor {
let mut meta = None;
loop {
match try!(visitor.visit_key()) {
Some(KeyFileField::Id) => { id = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Version) => { version = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Crypto) => { crypto = Some(try!(visitor.visit_value())); }
Some(KeyFileField::Address) => { address = Some(try!(visitor.visit_value())); }
match visitor.visit_key()? {
Some(KeyFileField::Id) => { id = Some(visitor.visit_value()?); }
Some(KeyFileField::Version) => { version = Some(visitor.visit_value()?); }
Some(KeyFileField::Crypto) => { crypto = Some(visitor.visit_value()?); }
Some(KeyFileField::Address) => { address = Some(visitor.visit_value()?); }
Some(KeyFileField::Name) => { name = visitor.visit_value().ok(); } // ignore anyhing that is not a string to be permissive.
Some(KeyFileField::Meta) => { meta = visitor.visit_value().ok(); } // ignore anyhing that is not a string to be permissive.
None => { break; }
@@ -106,25 +106,25 @@ impl Visitor for KeyFileVisitor {
let id = match id {
Some(id) => id,
None => try!(visitor.missing_field("id")),
None => visitor.missing_field("id")?,
};
let version = match version {
Some(version) => version,
None => try!(visitor.missing_field("version")),
None => visitor.missing_field("version")?,
};
let crypto = match crypto {
Some(crypto) => crypto,
None => try!(visitor.missing_field("crypto")),
None => visitor.missing_field("crypto")?,
};
let address = match address {
Some(address) => address,
None => try!(visitor.missing_field("address")),
None => visitor.missing_field("address")?,
};
try!(visitor.end());
visitor.end()?;
let result = KeyFile {
id: id,

View File

@@ -32,9 +32,9 @@ impl From<json::PresaleWallet> for PresaleWallet {
impl PresaleWallet {
pub fn open<P>(path: P) -> Result<Self, Error> where P: AsRef<Path> {
let file = try!(fs::File::open(path));
let presale = try!(json::PresaleWallet::load(file)
.map_err(|e| Error::InvalidKeyFile(format!("{}", e))));
let file = fs::File::open(path)?;
let presale = json::PresaleWallet::load(file)
.map_err(|e| Error::InvalidKeyFile(format!("{}", e)))?;
Ok(PresaleWallet::from(presale))
}
@@ -44,7 +44,7 @@ impl PresaleWallet {
pbkdf2(&mut h_mac, password.as_bytes(), 2000, &mut derived_key);
let mut key = vec![0; self.ciphertext.len()];
let len = try!(crypto::aes::decrypt_cbc(&derived_key, &self.iv, &self.ciphertext, &mut key).map_err(|_| Error::InvalidPassword));
let len = crypto::aes::decrypt_cbc(&derived_key, &self.iv, &self.ciphertext, &mut key).map_err(|_| Error::InvalidPassword)?;
let unpadded = &key[..len];
let secret = Secret::from(unpadded.keccak256());

View File

@@ -36,7 +36,7 @@ impl TransientDir {
pub fn create() -> Result<Self, Error> {
let path = random_dir();
let result = TransientDir {
dir: try!(DiskDirectory::create(&path)),
dir: DiskDirectory::create(&path)?,
path: path,
};