MCPcopy Index your code
hub / github.com/smallstep/cli / savePrivateKey

Function savePrivateKey

command/certificate/create.go:912–934  ·  view source on GitHub ↗

savePrivateKey saves the given key, asking the password if necessary.

(ctx *cli.Context, filename string, priv interface{}, insecure bool)

Source from the content-addressed store, hash-verified

910
911// savePrivateKey saves the given key, asking the password if necessary.
912func 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}

Callers 1

createActionFunction · 0.85

Calls 2

ReadPasswordFromFileFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…