Skip to content

Commit

Permalink
cmd/ethkey: fix flags
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Jun 1, 2018
1 parent f140092 commit 5a0aa16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
20 changes: 9 additions & 11 deletions cmd/ethkey/changepassphrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"gopkg.in/urfave/cli.v1"
)

var newPassphraseFlag = cli.StringFlag{
Name: "newpassowrdfile",
Usage: "the file that contains the new passphrase for the keyfile",
}

var commandChangePassphrase = cli.Command{
Name: "changepassphrase",
Usage: "change the passphrase on a keyfile",
Expand All @@ -18,10 +23,7 @@ var commandChangePassphrase = cli.Command{
Change the passphrase of a keyfile.`,
Flags: []cli.Flag{
passphraseFlag,
cli.StringFlag{
Name: "newpassfile",
Usage: "the file that contains the new passphrase for the keyfile",
},
newPassphraseFlag,
},
Action: func(ctx *cli.Context) error {
keyfilepath := ctx.Args().First()
Expand All @@ -42,22 +44,18 @@ Change the passphrase of a keyfile.`,
// Get a new passphrase.
fmt.Println("Please provide a new passphrase")
var newPhrase string
// Look for the --newpassfile flag.
if passFile := ctx.String(passphraseFlag.Name); passFile != "" {
if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" {
content, err := ioutil.ReadFile(passFile)
if err != nil {
utils.Fatalf("Failed to read new passphrase file '%s': %v",
passFile, err)
utils.Fatalf("Failed to read new passphrase file '%s': %v", passFile, err)
}
newPhrase = strings.TrimRight(string(content), "\r\n")
} else {
// If not present, ask for new passphrase.
newPhrase = promptPassphrase(true)
}

// Encrypt the key with the new passphrase.
newJson, err := keystore.EncryptKey(key, newPhrase,
keystore.StandardScryptN, keystore.StandardScryptP)
newJson, err := keystore.EncryptKey(key, newPhrase, keystore.StandardScryptN, keystore.StandardScryptP)
if err != nil {
utils.Fatalf("Error encrypting with new passphrase: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {
// Commonly used command line flags.
var (
passphraseFlag = cli.StringFlag{
Name: "passfile",
Name: "passwordfile",
Usage: "the file that contains the passphrase for the keyfile",
}
jsonFlag = cli.BoolFlag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/ethkey/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func promptPassphrase(confirmation bool) string {
return passphrase
}

// getPassPhrase obtains a passphrase given by the user. It first checks the
// 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 --passfile flag.
// Look for the --passwordfile flag.
passphraseFile := ctx.String(passphraseFlag.Name)
if passphraseFile != "" {
content, err := ioutil.ReadFile(passphraseFile)
Expand Down

0 comments on commit 5a0aa16

Please sign in to comment.