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

Function convertToPEM

command/crypto/key/format.go:341–367  ·  view source on GitHub ↗
(ctx *cli.Context, key interface{})

Source from the content-addressed store, hash-verified

339}
340
341func convertToPEM(ctx *cli.Context, key interface{}) (b []byte, err error) {
342 opts := []pemutil.Options{
343 pemutil.WithPKCS8(ctx.Bool("pkcs8")),
344 }
345
346 if !ctx.Bool("no-password") {
347 switch key.(type) {
348 case *ecdsa.PublicKey, *rsa.PublicKey, ed25519.PublicKey:
349 case *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey:
350 if passFile := ctx.String("password-file"); passFile != "" {
351 opts = append(opts, pemutil.WithPasswordFile(passFile))
352 } else {
353 opts = append(opts, pemutil.WithPasswordPrompt("Please enter the password to encrypt the private key", func(s string) ([]byte, error) {
354 return ui.PromptPassword(s, ui.WithValidateNotEmpty())
355 }))
356 }
357 default:
358 return nil, errors.Errorf("unsupported key type %T", key)
359 }
360 }
361
362 block, err := pemutil.Serialize(key, opts...)
363 if err != nil {
364 return nil, err
365 }
366 return pem.EncodeToMemory(block), nil
367}
368
369func convertToDER(ctx *cli.Context, key interface{}) (b []byte, err error) {
370 switch k := key.(type) {

Callers 1

formatActionFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…