cmd/ethkey: fix flags

This commit is contained in:
Felix Lange 2018-06-01 11:59:32 +02:00
parent f140092a16
commit 5a0aa16040
3 changed files with 12 additions and 14 deletions

View file

@ -10,6 +10,11 @@ import (
"gopkg.in/urfave/cli.v1" "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{ var commandChangePassphrase = cli.Command{
Name: "changepassphrase", Name: "changepassphrase",
Usage: "change the passphrase on a keyfile", Usage: "change the passphrase on a keyfile",
@ -18,10 +23,7 @@ var commandChangePassphrase = cli.Command{
Change the passphrase of a keyfile.`, Change the passphrase of a keyfile.`,
Flags: []cli.Flag{ Flags: []cli.Flag{
passphraseFlag, passphraseFlag,
cli.StringFlag{ newPassphraseFlag,
Name: "newpassfile",
Usage: "the file that contains the new passphrase for the keyfile",
},
}, },
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
keyfilepath := ctx.Args().First() keyfilepath := ctx.Args().First()
@ -42,22 +44,18 @@ Change the passphrase of a keyfile.`,
// Get a new passphrase. // Get a new passphrase.
fmt.Println("Please provide a new passphrase") fmt.Println("Please provide a new passphrase")
var newPhrase string var newPhrase string
// Look for the --newpassfile flag. if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" {
if passFile := ctx.String(passphraseFlag.Name); passFile != "" {
content, err := ioutil.ReadFile(passFile) content, err := ioutil.ReadFile(passFile)
if err != nil { if err != nil {
utils.Fatalf("Failed to read new passphrase file '%s': %v", utils.Fatalf("Failed to read new passphrase file '%s': %v", passFile, err)
passFile, err)
} }
newPhrase = strings.TrimRight(string(content), "\r\n") newPhrase = strings.TrimRight(string(content), "\r\n")
} else { } else {
// If not present, ask for new passphrase.
newPhrase = promptPassphrase(true) newPhrase = promptPassphrase(true)
} }
// Encrypt the key with the new passphrase. // Encrypt the key with the new passphrase.
newJson, err := keystore.EncryptKey(key, newPhrase, newJson, err := keystore.EncryptKey(key, newPhrase, keystore.StandardScryptN, keystore.StandardScryptP)
keystore.StandardScryptN, keystore.StandardScryptP)
if err != nil { if err != nil {
utils.Fatalf("Error encrypting with new passphrase: %v", err) utils.Fatalf("Error encrypting with new passphrase: %v", err)
} }

View file

@ -47,7 +47,7 @@ func init() {
// Commonly used command line flags. // Commonly used command line flags.
var ( var (
passphraseFlag = cli.StringFlag{ passphraseFlag = cli.StringFlag{
Name: "passfile", Name: "passwordfile",
Usage: "the file that contains the passphrase for the keyfile", Usage: "the file that contains the passphrase for the keyfile",
} }
jsonFlag = cli.BoolFlag{ jsonFlag = cli.BoolFlag{

View file

@ -49,11 +49,11 @@ func promptPassphrase(confirmation bool) string {
return passphrase 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 // --passfile command line flag and ultimately prompts the user for a
// passphrase. // passphrase.
func getPassphrase(ctx *cli.Context) string { func getPassphrase(ctx *cli.Context) string {
// Look for the --passfile flag. // Look for the --passwordfile flag.
passphraseFile := ctx.String(passphraseFlag.Name) passphraseFile := ctx.String(passphraseFlag.Name)
if passphraseFile != "" { if passphraseFile != "" {
content, err := ioutil.ReadFile(passphraseFile) content, err := ioutil.ReadFile(passphraseFile)