savePrivateKey saves the given key, asking the password if necessary.
(ctx *cli.Context, filename string, priv interface{}, insecure bool)
| 910 | |
| 911 | // savePrivateKey saves the given key, asking the password if necessary. |
| 912 | func savePrivateKey(ctx *cli.Context, filename string, priv interface{}, insecure bool) error { |
| 913 | var err error |
| 914 | if insecure { |
| 915 | _, err = pemutil.Serialize(priv, pemutil.ToFile(filename, 0o600)) |
| 916 | return err |
| 917 | } |
| 918 | |
| 919 | var pass []byte |
| 920 | if passFile := ctx.String("password-file"); passFile != "" { |
| 921 | pass, err = utils.ReadPasswordFromFile(passFile) |
| 922 | if err != nil { |
| 923 | return errors.Wrap(err, "error reading encrypting password from file") |
| 924 | } |
| 925 | } else { |
| 926 | pass, err = ui.PromptPassword("Please enter the password to encrypt the private key", |
| 927 | ui.WithValidateNotEmpty()) |
| 928 | if err != nil { |
| 929 | return errors.Wrap(err, "error reading password") |
| 930 | } |
| 931 | } |
| 932 | _, err = pemutil.Serialize(priv, pemutil.WithPassword(pass), pemutil.ToFile(filename, 0o600)) |
| 933 | return err |
| 934 | } |
no test coverage detected
searching dependent graphs…