cmd: abstract getPassPhrase functions into one (#21219)

* [cmd] Abstract `getPassPhrase` functions into one.

* cmd/ethkey: fix compilation failure

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
This commit is contained in:
Binacs
2020-06-30 15:56:40 +08:00
committed by GitHub
parent c13df14581
commit dd91c7ce6a
6 changed files with 146 additions and 85 deletions

View File

@ -23,32 +23,10 @@ import (
"strings"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console/prompt"
"github.com/ethereum/go-ethereum/crypto"
"gopkg.in/urfave/cli.v1"
)
// promptPassphrase prompts the user for a passphrase. Set confirmation to true
// to require the user to confirm the passphrase.
func promptPassphrase(confirmation bool) string {
passphrase, err := prompt.Stdin.PromptPassword("Password: ")
if err != nil {
utils.Fatalf("Failed to read password: %v", err)
}
if confirmation {
confirm, err := prompt.Stdin.PromptPassword("Repeat password: ")
if err != nil {
utils.Fatalf("Failed to read password confirmation: %v", err)
}
if passphrase != confirm {
utils.Fatalf("Passwords do not match")
}
}
return passphrase
}
// getPassphrase obtains a passphrase given by the user. It first checks the
// --passfile command line flag and ultimately prompts the user for a
// passphrase.
@ -65,7 +43,7 @@ func getPassphrase(ctx *cli.Context, confirmation bool) string {
}
// Otherwise prompt the user for the passphrase.
return promptPassphrase(confirmation)
return utils.GetPassPhrase("", confirmation)
}
// signHash is a helper function that calculates a hash for the given message