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

Function convertToSSH

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

Source from the content-addressed store, hash-verified

391}
392
393func 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
424func convertToJWK(ctx *cli.Context, key interface{}) ([]byte, error) {
425 b, err := json.Marshal(&jose.JSONWebKey{Key: key})

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…