(ctx *cli.Context, key interface{})
| 339 | } |
| 340 | |
| 341 | func 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 | |
| 369 | func convertToDER(ctx *cli.Context, key interface{}) (b []byte, err error) { |
| 370 | switch k := key.(type) { |
no test coverage detected
searching dependent graphs…