aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/ethkey/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/ethkey/utils.go')
-rw-r--r--cmd/ethkey/utils.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/cmd/ethkey/utils.go b/cmd/ethkey/utils.go
index 0e563bf92..6f60ebaf1 100644
--- a/cmd/ethkey/utils.go
+++ b/cmd/ethkey/utils.go
@@ -28,26 +28,14 @@ import (
"gopkg.in/urfave/cli.v1"
)
-// getPassPhrase obtains a passphrase given by the user. It first checks the
-// --passphrase command line flag and ultimately prompts the user for a
-// passphrase.
-func getPassPhrase(ctx *cli.Context, confirmation bool) string {
- // Look for the --passphrase flag.
- passphraseFile := ctx.String(passphraseFlag.Name)
- if passphraseFile != "" {
- content, err := ioutil.ReadFile(passphraseFile)
- if err != nil {
- utils.Fatalf("Failed to read passphrase file '%s': %v",
- passphraseFile, err)
- }
- return strings.TrimRight(string(content), "\r\n")
- }
-
- // Otherwise prompt the user for the passphrase.
+// 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 := console.Stdin.PromptPassword("Passphrase: ")
if err != nil {
utils.Fatalf("Failed to read passphrase: %v", err)
}
+
if confirmation {
confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
if err != nil {
@@ -57,9 +45,29 @@ func getPassPhrase(ctx *cli.Context, confirmation bool) string {
utils.Fatalf("Passphrases 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.
+func getPassphrase(ctx *cli.Context) string {
+ // Look for the --passwordfile flag.
+ passphraseFile := ctx.String(passphraseFlag.Name)
+ if passphraseFile != "" {
+ content, err := ioutil.ReadFile(passphraseFile)
+ if err != nil {
+ utils.Fatalf("Failed to read passphrase file '%s': %v",
+ passphraseFile, err)
+ }
+ return strings.TrimRight(string(content), "\r\n")
+ }
+
+ // Otherwise prompt the user for the passphrase.
+ return promptPassphrase(false)
+}
+
// signHash is a helper function that calculates a hash for the given message
// that can be safely used to calculate a signature from.
//