update ring to 0.14 (#10262)

* cargo upgrade hyper-rustls --all

* cargo upgrade parity-crypto --all

* update Cargo.lock

* propagate NonZeroU32

* use NonZeroU32::new_unchecked for crypto::KEY_ITERATIONS

* update Cargo.lock

* replace unsafe code with lazy_static
This commit is contained in:
Andronik Ordian
2019-02-06 19:53:34 +03:00
committed by Niklas Adolfsson
parent 8ab6d89810
commit a3e39c9858
29 changed files with 256 additions and 180 deletions

View File

@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use std::num::NonZeroU32;
use std::path::PathBuf;
use ethstore::{EthStore, SecretStore, import_account, import_accounts, read_geth_accounts};
use ethstore::accounts_dir::RootDiskDirectory;
@@ -38,7 +39,7 @@ pub struct ListAccounts {
#[derive(Debug, PartialEq)]
pub struct NewAccount {
pub iterations: u32,
pub iterations: NonZeroU32,
pub path: String,
pub spec: SpecType,
pub password_file: Option<String>,
@@ -77,7 +78,7 @@ fn keys_dir(path: String, spec: SpecType) -> Result<RootDiskDirectory, String> {
RootDiskDirectory::create(path).map_err(|e| format!("Could not open keys directory: {}", e))
}
fn secret_store(dir: Box<RootDiskDirectory>, iterations: Option<u32>) -> Result<EthStore, String> {
fn secret_store(dir: Box<RootDiskDirectory>, iterations: Option<NonZeroU32>) -> Result<EthStore, String> {
match iterations {
Some(i) => EthStore::open_with_iterations(dir, i),
_ => EthStore::open(dir)

View File

@@ -17,6 +17,7 @@
use std::time::Duration;
use std::io::Read;
use std::net::SocketAddr;
use std::num::NonZeroU32;
use std::path::PathBuf;
use std::collections::{HashSet, BTreeMap};
use std::iter::FromIterator;
@@ -143,6 +144,8 @@ impl Configuration {
let ipfs_conf = self.ipfs_config();
let secretstore_conf = self.secretstore_config()?;
let format = self.format()?;
let keys_iterations = NonZeroU32::new(self.args.arg_keys_iterations)
.ok_or_else(|| "--keys-iterations must be non-zero")?;
let cmd = if self.args.flag_version {
Cmd::Version
@@ -199,7 +202,7 @@ impl Configuration {
} else if self.args.cmd_account {
let account_cmd = if self.args.cmd_account_new {
let new_acc = NewAccount {
iterations: self.args.arg_keys_iterations,
iterations: keys_iterations,
path: dirs.keys,
spec: spec,
password_file: self.accounts_config()?.password_files.first().map(|x| x.to_owned()),
@@ -233,7 +236,7 @@ impl Configuration {
Cmd::Account(account_cmd)
} else if self.args.cmd_wallet {
let presale_cmd = ImportWallet {
iterations: self.args.arg_keys_iterations,
iterations: keys_iterations,
path: dirs.keys,
spec: spec,
wallet_path: self.args.arg_wallet_import_path.clone().unwrap(),
@@ -528,8 +531,10 @@ impl Configuration {
}
fn accounts_config(&self) -> Result<AccountsConfig, String> {
let keys_iterations = NonZeroU32::new(self.args.arg_keys_iterations)
.ok_or_else(|| "--keys-iterations must be non-zero")?;
let cfg = AccountsConfig {
iterations: self.args.arg_keys_iterations,
iterations: keys_iterations,
refresh_time: self.args.arg_accounts_refresh,
testnet: self.args.flag_testnet,
password_files: self.args.arg_password.iter().map(|s| replace_home(&self.directories().base, s)).collect(),
@@ -1212,6 +1217,10 @@ mod tests {
use super::*;
lazy_static! {
static ref ITERATIONS: NonZeroU32 = NonZeroU32::new(10240).expect("10240 > 0; qed");
}
#[derive(Debug, PartialEq)]
struct TestPasswordReader(&'static str);
@@ -1233,7 +1242,7 @@ mod tests {
let args = vec!["parity", "account", "new"];
let conf = parse(&args);
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(AccountCmd::New(NewAccount {
iterations: 10240,
iterations: *ITERATIONS,
path: Directories::default().keys,
password_file: None,
spec: SpecType::default(),
@@ -1268,7 +1277,7 @@ mod tests {
let args = vec!["parity", "wallet", "import", "my_wallet.json", "--password", "pwd"];
let conf = parse(&args);
assert_eq!(conf.into_command().unwrap().cmd, Cmd::ImportPresaleWallet(ImportWallet {
iterations: 10240,
iterations: *ITERATIONS,
path: Directories::default().keys,
wallet_path: "my_wallet.json".into(),
password_file: Some("pwd".into()),

View File

@@ -86,6 +86,10 @@ extern crate pretty_assertions;
#[cfg(test)]
extern crate tempdir;
#[cfg(test)]
#[macro_use]
extern crate lazy_static;
mod account;
mod blockchain;
mod cache;

View File

@@ -15,6 +15,7 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use std::{str, fs, fmt};
use std::num::NonZeroU32;
use std::time::Duration;
use ethcore::client::Mode;
@@ -214,7 +215,7 @@ impl str::FromStr for ResealPolicy {
#[derive(Debug, PartialEq)]
pub struct AccountsConfig {
pub iterations: u32,
pub iterations: NonZeroU32,
pub refresh_time: u64,
pub testnet: bool,
pub password_files: Vec<String>,
@@ -226,7 +227,7 @@ pub struct AccountsConfig {
impl Default for AccountsConfig {
fn default() -> Self {
AccountsConfig {
iterations: 10240,
iterations: NonZeroU32::new(10240).expect("10240 > 0; qed"),
refresh_time: 5,
testnet: false,
password_files: Vec::new(),

View File

@@ -19,10 +19,11 @@ use ethstore::accounts_dir::RootDiskDirectory;
use ethcore::account_provider::{AccountProvider, AccountProviderSettings};
use helpers::{password_prompt, password_from_file};
use params::SpecType;
use std::num::NonZeroU32;
#[derive(Debug, PartialEq)]
pub struct ImportWallet {
pub iterations: u32,
pub iterations: NonZeroU32,
pub path: String,
pub spec: SpecType,
pub wallet_path: String,