(ctx *cli.Context)
| 156 | } |
| 157 | |
| 158 | func encryptAction(ctx *cli.Context) error { |
| 159 | if err := errs.NumberOfArguments(ctx, 0); err != nil { |
| 160 | return err |
| 161 | } |
| 162 | |
| 163 | data, err := utils.ReadAll(os.Stdin) |
| 164 | if err != nil { |
| 165 | return err |
| 166 | } |
| 167 | |
| 168 | // Validate parameters |
| 169 | alg, err := getRecipientAlg(ctx, ctx.String("alg")) |
| 170 | if err != nil { |
| 171 | return err |
| 172 | } |
| 173 | |
| 174 | enc, err := getContentEncryptionAlg(ctx, ctx.String("enc")) |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | |
| 179 | var isPBES2 bool |
| 180 | switch alg { |
| 181 | case jose.PBES2_HS256_A128KW, jose.PBES2_HS384_A192KW, jose.PBES2_HS512_A256KW: |
| 182 | isPBES2 = true |
| 183 | } |
| 184 | |
| 185 | key := ctx.String("key") |
| 186 | jwks := ctx.String("jwks") |
| 187 | kid := ctx.String("kid") |
| 188 | typ := ctx.String("typ") |
| 189 | cty := ctx.String("cty") |
| 190 | isSubtle := ctx.Bool("subtle") |
| 191 | |
| 192 | switch { |
| 193 | case isPBES2 && key != "": |
| 194 | return errs.MutuallyExclusiveFlags(ctx, "alg "+ctx.String("alg"), "key") |
| 195 | case isPBES2 && jwks != "": |
| 196 | return errs.MutuallyExclusiveFlags(ctx, "alg "+ctx.String("alg"), "jwks") |
| 197 | case !isPBES2 && key == "" && jwks == "": |
| 198 | return errs.RequiredOrFlag(ctx, "key", "jwk") |
| 199 | case key != "" && jwks != "": |
| 200 | return errs.MutuallyExclusiveFlags(ctx, "key", "jwks") |
| 201 | case jwks != "" && kid == "": |
| 202 | return errs.RequiredWithFlag(ctx, "kid", "jwks") |
| 203 | } |
| 204 | |
| 205 | // Add parse options |
| 206 | var options []jose.Option |
| 207 | options = append(options, jose.WithUse("enc")) |
| 208 | if len(alg) > 0 { |
| 209 | options = append(options, jose.WithAlg(string(alg))) |
| 210 | } |
| 211 | if kid != "" { |
| 212 | options = append(options, jose.WithKid(kid)) |
| 213 | } |
| 214 | if isSubtle { |
| 215 | options = append(options, jose.WithSubtle(true)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…