Upgrade to parity-crypto 0.4 (#10650)

* [whisper] Move needed aes_gcm crypto in-crate

In the latest `parity-crypto` release (upcoming 0.4), the aes GCM features were removed (done to remove the dependency on `ring`).
This PR adds the bare minimum crypto needed for Whisper directly to the crate itself and as those were the only features needed from `parity-crypto`, removes the dependency on that crate altogether.

* Upgrade to parity-crypto 0.4

Reverts using NonZeroU32 (introduced [here](b347599cf7)).

* Check for 0 in `args.arg_keys_iteration`

* Use beta.4

* parity-crypto 0.4.0 is released
This commit is contained in:
David
2019-05-28 07:50:10 +02:00
committed by Wei Tang
parent 9bbf8b6c0f
commit 9584faee55
24 changed files with 317 additions and 136 deletions

View File

@@ -14,7 +14,6 @@
// 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 params::SpecType;
#[derive(Debug, PartialEq)]
@@ -33,7 +32,7 @@ pub struct ListAccounts {
#[derive(Debug, PartialEq)]
pub struct NewAccount {
pub iterations: NonZeroU32,
pub iterations: u32,
pub path: String,
pub spec: SpecType,
pub password_file: Option<String>,
@@ -87,7 +86,7 @@ mod command {
RootDiskDirectory::create(path).map_err(|e| format!("Could not open keys directory: {}", e))
}
fn secret_store(dir: Box<RootDiskDirectory>, iterations: Option<NonZeroU32>) -> Result<EthStore, String> {
fn secret_store(dir: Box<RootDiskDirectory>, iterations: Option<u32>) -> Result<EthStore, String> {
match iterations {
Some(i) => EthStore::open_with_iterations(dir, i),
_ => EthStore::open(dir)

View File

@@ -17,7 +17,6 @@
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;
@@ -144,8 +143,11 @@ 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 key_iterations = self.args.arg_keys_iterations;
if key_iterations == 0 {
return Err("--key-iterations must be non-zero".into());
}
let cmd = if self.args.flag_version {
Cmd::Version
@@ -202,7 +204,7 @@ impl Configuration {
} else if self.args.cmd_account {
let account_cmd = if self.args.cmd_account_new {
let new_acc = NewAccount {
iterations: keys_iterations,
iterations: key_iterations,
path: dirs.keys,
spec: spec,
password_file: self.accounts_config()?.password_files.first().map(|x| x.to_owned()),
@@ -236,7 +238,7 @@ impl Configuration {
Cmd::Account(account_cmd)
} else if self.args.cmd_wallet {
let presale_cmd = ImportWallet {
iterations: keys_iterations,
iterations: key_iterations,
path: dirs.keys,
spec: spec,
wallet_path: self.args.arg_wallet_import_path.clone().unwrap(),
@@ -532,10 +534,8 @@ 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: keys_iterations,
iterations: self.args.arg_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(),
@@ -1216,10 +1216,6 @@ mod tests {
use super::*;
lazy_static! {
static ref ITERATIONS: NonZeroU32 = NonZeroU32::new(10240).expect("10240 > 0; qed");
}
#[derive(Debug, PartialEq)]
struct TestPasswordReader(&'static str);
@@ -1241,7 +1237,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: *ITERATIONS,
iterations: 10240,
path: Directories::default().keys,
password_file: None,
spec: SpecType::default(),
@@ -1276,7 +1272,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: *ITERATIONS,
iterations: 10240,
path: Directories::default().keys,
wallet_path: "my_wallet.json".into(),
password_file: Some("pwd".into()),

View File

@@ -17,7 +17,6 @@
use std::collections::HashSet;
use std::time::Duration;
use std::{str, fs, fmt};
use std::num::NonZeroU32;
use ethcore::client::Mode;
use ethcore::ethereum;
@@ -220,7 +219,7 @@ impl str::FromStr for ResealPolicy {
#[derive(Debug, PartialEq)]
pub struct AccountsConfig {
pub iterations: NonZeroU32,
pub iterations: u32,
pub refresh_time: u64,
pub testnet: bool,
pub password_files: Vec<String>,
@@ -231,7 +230,7 @@ pub struct AccountsConfig {
impl Default for AccountsConfig {
fn default() -> Self {
AccountsConfig {
iterations: NonZeroU32::new(10240).expect("10240 > 0; qed"),
iterations: 10240,
refresh_time: 5,
testnet: false,
password_files: Vec::new(),

View File

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