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

Function parseJWK

command/crypto/key/format.go:312–339  ·  view source on GitHub ↗
(ctx *cli.Context, b []byte)

Source from the content-addressed store, hash-verified

310}
311
312func parseJWK(ctx *cli.Context, b []byte) (interface{}, error) {
313 // Decrypt key if encrypted.
314 if _, err := jose.ParseEncrypted(string(b)); err == nil {
315 opts := []jose.Option{
316 jose.WithPasswordPrompter("Please enter the password to decrypt the key", func(s string) ([]byte, error) {
317 return ui.PromptPassword(s)
318 }),
319 }
320 if passFile := ctx.String("password-file"); passFile != "" {
321 opts = append(opts, jose.WithPasswordFile(passFile))
322 }
323 b, err = jose.Decrypt(b, opts...)
324 if err != nil {
325 return nil, err
326 }
327 }
328
329 // Parse decrypted key
330 var jwk jose.JSONWebKey
331 if err := json.Unmarshal(b, &jwk); err != nil {
332 return nil, errors.Wrap(err, "error unmarshaling key")
333 }
334 if jwk.Key == nil {
335 return nil, errors.New("error parsing key: not found")
336 }
337
338 return jwk.Key, nil
339}
340
341func convertToPEM(ctx *cli.Context, key interface{}) (b []byte, err error) {
342 opts := []pemutil.Options{

Callers 3

inspectActionFunction · 0.85
formatActionFunction · 0.85
fingerprintActionFunction · 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…