(ctx *cli.Context, b []byte)
| 310 | } |
| 311 | |
| 312 | func 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 | |
| 341 | func convertToPEM(ctx *cli.Context, key interface{}) (b []byte, err error) { |
| 342 | opts := []pemutil.Options{ |
no test coverage detected
searching dependent graphs…