Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Fix compilation errors
  • Loading branch information
tomaka committed Nov 20, 2020
commit b10a1fd547c496b992714ce71dc330770499ea56
23 changes: 7 additions & 16 deletions client/cli/src/params/keystore_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use std::fs;
use std::path::PathBuf;
use structopt::StructOpt;
use crate::error;
use sp_core::crypto::{SecretString, Zeroize};
use std::str::FromStr;
use sp_core::crypto::SecretString;

/// default sub directory for the key store
const DEFAULT_KEYSTORE_CONFIG_PATH: &'static str = "keystore";
Expand Down Expand Up @@ -72,21 +71,15 @@ impl KeystoreParams {
let password = if self.password_interactive {
#[cfg(not(target_os = "unknown"))]
{
let mut password = input_keystore_password()?;
let secret = std::str::FromStr::from_str(password.as_str())
.map_err(|()| "Error reading password")?;
password.zeroize();
Some(secret)
let password = input_keystore_password()?;
Some(SecretString::new(password))
}
#[cfg(target_os = "unknown")]
None
} else if let Some(ref file) = self.password_filename {
let mut password = fs::read_to_string(file)
let password = fs::read_to_string(file)
.map_err(|e| format!("{}", e))?;
let secret = std::str::FromStr::from_str(password.as_str())
.map_err(|()| "Error reading password")?;
password.zeroize();
Some(secret)
Some(SecretString::new(password))
} else {
self.password.clone()
};
Expand All @@ -104,10 +97,8 @@ impl KeystoreParams {
let (password_interactive, password) = (self.password_interactive, self.password.clone());

let pass = if password_interactive {
let mut password = rpassword::read_password_from_tty(Some("Key password: "))?;
let pass = Some(FromStr::from_str(&password).map_err(|()| "Error reading password")?);
password.zeroize();
pass
let password = rpassword::read_password_from_tty(Some("Key password: "))?;
Some(SecretString::new(password))
} else {
password
};
Expand Down