(ctx *cli.Context, key interface{})
| 391 | } |
| 392 | |
| 393 | func convertToSSH(ctx *cli.Context, key interface{}) ([]byte, error) { |
| 394 | switch key.(type) { |
| 395 | case *ecdsa.PublicKey, *rsa.PublicKey, ed25519.PublicKey: |
| 396 | k, err := ssh.NewPublicKey(key) |
| 397 | if err != nil { |
| 398 | return nil, errors.Wrap(err, "error converting public key") |
| 399 | } |
| 400 | return ssh.MarshalAuthorizedKey(k), nil |
| 401 | case *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey: |
| 402 | opts := []pemutil.Options{ |
| 403 | pemutil.WithOpenSSH(true), |
| 404 | } |
| 405 | if !ctx.Bool("no-password") { |
| 406 | if passFile := ctx.String("password-file"); passFile != "" { |
| 407 | opts = append(opts, pemutil.WithPasswordFile(passFile)) |
| 408 | } else { |
| 409 | opts = append(opts, pemutil.WithPasswordPrompt("Please enter the password to encrypt the private key", func(s string) ([]byte, error) { |
| 410 | return ui.PromptPassword(s, ui.WithValidateNotEmpty()) |
| 411 | })) |
| 412 | } |
| 413 | } |
| 414 | block, err := pemutil.Serialize(key, opts...) |
| 415 | if err != nil { |
| 416 | return nil, err |
| 417 | } |
| 418 | return pem.EncodeToMemory(block), nil |
| 419 | default: |
| 420 | return nil, errors.Errorf("unsupported key type %T", key) |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | func convertToJWK(ctx *cli.Context, key interface{}) ([]byte, error) { |
| 425 | b, err := json.Marshal(&jose.JSONWebKey{Key: key}) |
no test coverage detected
searching dependent graphs…