File: jwa.go

package info (click to toggle)
golang-github-lestrrat-go-jwx 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,872 kB
  • sloc: sh: 222; makefile: 86; perl: 62
file content (78 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main

import (
	"fmt"
	"os"

	"github.com/lestrrat-go/jwx/v2/jwa"
	"github.com/urfave/cli/v2"
)

func init() {
	topLevelCommands = append(topLevelCommands, makeJwaCmd())
}

func makeJwaCmd() *cli.Command {
	var cmd cli.Command
	cmd.Name = "jwa"
	cmd.Usage = "List available algorithms and types"
	cmd.Flags = []cli.Flag{
		&cli.BoolFlag{
			Name:    "key-type",
			Aliases: []string{"k"},
		},
		&cli.BoolFlag{
			Name:    "elliptic-curve",
			Aliases: []string{"E"},
		},
		&cli.BoolFlag{
			Name:    "key-encryption",
			Aliases: []string{"K"},
		},
		&cli.BoolFlag{
			Name:    "content-encryption",
			Aliases: []string{"C"},
		},
		&cli.BoolFlag{
			Name:    "signature",
			Aliases: []string{"S"},
		},
	}
	cmd.Action = func(c *cli.Context) error {
		output := os.Stdout

		if c.Bool("key-type") {
			for _, alg := range jwa.KeyTypes() {
				fmt.Fprintf(output, "%s\n", alg)
			}
			return nil
		}
		if c.Bool("elliptic-curve") {
			for _, alg := range jwa.EllipticCurveAlgorithms() {
				fmt.Fprintf(output, "%s\n", alg)
			}
			return nil
		}
		if c.Bool("key-encryption") {
			for _, alg := range jwa.KeyEncryptionAlgorithms() {
				fmt.Fprintf(output, "%s\n", alg)
			}
			return nil
		}
		if c.Bool("content-encryption") {
			for _, alg := range jwa.ContentEncryptionAlgorithms() {
				fmt.Fprintf(output, "%s\n", alg)
			}
			return nil
		}
		if c.Bool("signature") {
			for _, alg := range jwa.SignatureAlgorithms() {
				fmt.Fprintf(output, "%s\n", alg)
			}
			return nil
		}
		cli.ShowCommandHelpAndExit(c, "jwa", 1)
		return nil // should not reach here
	}
	return &cmd
}