@@ -7,7 +7,7 @@ use account_utils::{
77 recursively_find_voting_keystores, PasswordStorage , ValidatorDefinition ,
88 ValidatorDefinitions , CONFIG_FILENAME ,
99 } ,
10- ZeroizeString , STDIN_INPUTS_FLAG ,
10+ STDIN_INPUTS_FLAG ,
1111} ;
1212use clap:: { Arg , ArgAction , ArgMatches , Command } ;
1313use clap_utils:: FLAG_HEADER ;
@@ -16,6 +16,7 @@ use std::fs;
1616use std:: path:: PathBuf ;
1717use std:: thread:: sleep;
1818use std:: time:: Duration ;
19+ use zeroize:: Zeroizing ;
1920
2021pub const CMD : & str = "import" ;
2122pub const KEYSTORE_FLAG : & str = "keystore" ;
@@ -148,7 +149,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
148149 // Skip keystores that already exist, but exit early if any operation fails.
149150 // Reuses the same password for all keystores if the `REUSE_PASSWORD_FLAG` flag is set.
150151 let mut num_imported_keystores = 0 ;
151- let mut previous_password: Option < ZeroizeString > = None ;
152+ let mut previous_password: Option < Zeroizing < String > > = None ;
152153
153154 for src_keystore in & keystore_paths {
154155 let keystore = Keystore :: from_json_file ( src_keystore)
@@ -182,14 +183,17 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
182183
183184 let password = match keystore_password_path. as_ref ( ) {
184185 Some ( path) => {
185- let password_from_file: ZeroizeString = fs:: read_to_string ( path)
186+ let password_from_file: Zeroizing < String > = fs:: read_to_string ( path)
186187 . map_err ( |e| format ! ( "Unable to read {:?}: {:?}" , path, e) ) ?
187188 . into ( ) ;
188- password_from_file. without_newlines ( )
189+ password_from_file
190+ . trim_end_matches ( [ '\r' , '\n' ] )
191+ . to_string ( )
192+ . into ( )
189193 }
190194 None => {
191195 let password_from_user = read_password_from_user ( stdin_inputs) ?;
192- if password_from_user. as_ref ( ) . is_empty ( ) {
196+ if password_from_user. is_empty ( ) {
193197 eprintln ! ( "Continuing without password." ) ;
194198 sleep ( Duration :: from_secs ( 1 ) ) ; // Provides nicer UX.
195199 break None ;
@@ -314,7 +318,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
314318/// Otherwise, returns the keystore error.
315319fn check_password_on_keystore (
316320 keystore : & Keystore ,
317- password : & ZeroizeString ,
321+ password : & Zeroizing < String > ,
318322) -> Result < bool , String > {
319323 match keystore. decrypt_keypair ( password. as_ref ( ) ) {
320324 Ok ( _) => {
0 commit comments