@@ -20,7 +20,7 @@ use std::str::FromStr;
2020use rpassword;
2121
2222use ccore:: AccountProvider ;
23- use ckey:: { FullAddress , Private } ;
23+ use ckey:: { FullAddress , Password , Private } ;
2424use ckeystore:: accounts_dir:: RootDiskDirectory ;
2525use ckeystore:: KeyStore ;
2626use clap:: ArgMatches ;
@@ -46,7 +46,7 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
4646 match matches. subcommand ( ) {
4747 ( "create" , _) => {
4848 if let Some ( password) = read_password_and_confirm ( ) {
49- let ( address, _) = ap. new_account_and_public ( password. as_ref ( ) ) . expect ( "Cannot create account" ) ;
49+ let ( address, _) = ap. new_account_and_public ( & password) . expect ( "Cannot create account" ) ;
5050 println ! (
5151 "{}" ,
5252 FullAddress :: create_version0( network_id, address) . expect( "The network id is hardcoded to 0x11" )
@@ -60,8 +60,8 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
6060 let json_path = matches. value_of ( "JSON_PATH" ) . expect ( "JSON_PATH arg is required and its index is 1" ) ;
6161 match fs:: read ( json_path) {
6262 Ok ( json) => {
63- let password = rpassword :: prompt_password_stdout ( "Password: " ) . unwrap ( ) ;
64- match ap. import_wallet ( json. as_slice ( ) , password. as_ref ( ) ) {
63+ let password = prompt_password ( "Password: " ) ;
64+ match ap. import_wallet ( json. as_slice ( ) , & password) {
6565 Ok ( address) => {
6666 println ! (
6767 "{}" ,
@@ -84,7 +84,7 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
8484 match Private :: from_str ( key) {
8585 Ok ( private) => {
8686 if let Some ( password) = read_password_and_confirm ( ) {
87- match ap. insert_account ( private, password. as_ref ( ) ) {
87+ match ap. insert_account ( private, & password) {
8888 Ok ( address) => println ! (
8989 "{}" ,
9090 FullAddress :: create_version0( network_id, address)
@@ -114,8 +114,8 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
114114 let key = matches. value_of ( "ADDRESS" ) . expect ( "ADDRESS arg is required and its index is 1" ) ;
115115 match FullAddress :: from_str ( key) {
116116 Ok ( full_address) => {
117- let password = rpassword :: prompt_password_stdout ( "Password: " ) . unwrap ( ) ;
118- match ap. remove_account ( full_address. address , password. as_ref ( ) ) {
117+ let password = prompt_password ( "Password: " ) ;
118+ match ap. remove_account ( full_address. address , & password) {
119119 Ok ( _) => println ! ( "{} is deleted" , full_address) ,
120120 Err ( e) => return Err ( format ! ( "{:?}" , e) ) ,
121121 }
@@ -128,9 +128,9 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
128128 let key = matches. value_of ( "ADDRESS" ) . expect ( "ADDRESS arg is required and its index is 1" ) ;
129129 match FullAddress :: from_str ( key) {
130130 Ok ( full_address) => {
131- let old_password = rpassword :: prompt_password_stdout ( "Old Password: " ) . unwrap ( ) ;
131+ let old_password = prompt_password ( "Old Password: " ) ;
132132 if let Some ( new_password) = read_password_and_confirm ( ) {
133- match ap. change_password ( full_address. address , old_password. as_ref ( ) , new_password. as_ref ( ) ) {
133+ match ap. change_password ( full_address. address , & old_password, & new_password) {
134134 Ok ( _) => println ! ( "Password has changed" ) ,
135135 Err ( e) => return Err ( format ! ( "{:?}" , e) ) ,
136136 }
@@ -146,11 +146,15 @@ pub fn run_account_command(matches: ArgMatches) -> Result<(), String> {
146146 }
147147}
148148
149- fn read_password_and_confirm ( ) -> Option < String > {
149+ fn prompt_password ( prompt : & str ) -> Password {
150+ Password :: from ( rpassword:: prompt_password_stdout ( prompt) . unwrap ( ) )
151+ }
152+
153+ fn read_password_and_confirm ( ) -> Option < Password > {
150154 let first = rpassword:: prompt_password_stdout ( "Password: " ) . unwrap ( ) ;
151155 let second = rpassword:: prompt_password_stdout ( "Confirm Password: " ) . unwrap ( ) ;
152156 if first == second {
153- Some ( first)
157+ Some ( Password :: from ( first) )
154158 } else {
155159 None
156160 }
0 commit comments