Trim password from file (#2503)
* trim password * indicate trimming in doc
This commit is contained in:
parent
d9ca01cb6b
commit
5f0ed9ddce
@ -44,7 +44,8 @@ Account Options:
|
|||||||
ACCOUNTS is a comma-delimited list of addresses.
|
ACCOUNTS is a comma-delimited list of addresses.
|
||||||
Implies --no-signer. (default: {flag_unlock:?})
|
Implies --no-signer. (default: {flag_unlock:?})
|
||||||
--password FILE Provide a file containing a password for unlocking
|
--password FILE Provide a file containing a password for unlocking
|
||||||
an account. (default: {flag_password:?})
|
an account. Leading and trailing whitespace is trimmed.
|
||||||
|
(default: {flag_password:?})
|
||||||
--keys-iterations NUM Specify the number of iterations to use when
|
--keys-iterations NUM Specify the number of iterations to use when
|
||||||
deriving key from the password (bigger is more
|
deriving key from the password (bigger is more
|
||||||
secure) (default: {flag_keys_iterations}).
|
secure) (default: {flag_keys_iterations}).
|
||||||
|
@ -273,9 +273,10 @@ pub fn password_prompt() -> Result<String, String> {
|
|||||||
pub fn password_from_file<P>(path: P) -> Result<String, String> where P: AsRef<Path> {
|
pub fn password_from_file<P>(path: P) -> Result<String, String> where P: AsRef<Path> {
|
||||||
let mut file = try!(File::open(path).map_err(|_| "Unable to open password file."));
|
let mut file = try!(File::open(path).map_err(|_| "Unable to open password file."));
|
||||||
let mut file_content = String::new();
|
let mut file_content = String::new();
|
||||||
try!(file.read_to_string(&mut file_content).map_err(|_| "Unable to read password file."));
|
match file.read_to_string(&mut file_content) {
|
||||||
// remove eof
|
Ok(_) => Ok(file_content.trim().into()),
|
||||||
Ok((&file_content[..file_content.len() - 1]).to_owned())
|
Err(_) => Err("Unable to read password file.".into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads passwords from files. Treats each line as a separate password.
|
/// Reads passwords from files. Treats each line as a separate password.
|
||||||
@ -294,10 +295,13 @@ pub fn passwords_from_files(files: Vec<String>) -> Result<Vec<String>, String> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use devtools::RandomTempPath;
|
||||||
use util::{U256};
|
use util::{U256};
|
||||||
use ethcore::client::{Mode, BlockID};
|
use ethcore::client::{Mode, BlockID};
|
||||||
use ethcore::miner::PendingSet;
|
use ethcore::miner::PendingSet;
|
||||||
use super::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_address, to_addresses, to_price, geth_ipc_path, to_bootnodes};
|
use super::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_address, to_addresses, to_price, geth_ipc_path, to_bootnodes, password_from_file};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_duration() {
|
fn test_to_duration() {
|
||||||
@ -380,6 +384,14 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_password() {
|
||||||
|
let path = RandomTempPath::new();
|
||||||
|
let mut file = File::create(path.as_path()).unwrap();
|
||||||
|
file.write_all(b"a bc ").unwrap();
|
||||||
|
assert_eq!(password_from_file(path).unwrap().as_bytes(), b"a bc");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(feature = "dev", allow(float_cmp))]
|
#[cfg_attr(feature = "dev", allow(float_cmp))]
|
||||||
fn test_to_price() {
|
fn test_to_price() {
|
||||||
|
Loading…
Reference in New Issue
Block a user