File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,15 @@ import (
1414 "io/ioutil"
1515 "os"
1616 "regexp"
17+ "sort"
1718 "strings"
1819
1920 "github.com/golang-jwt/jwt/v4"
2021)
2122
2223var (
2324 // Options
24- flagAlg = flag .String ("alg" , "" , "signing algorithm identifier" )
25+ flagAlg = flag .String ("alg" , "" , algHelp () )
2526 flagKey = flag .String ("key" , "" , "path to key file or '-' to read from stdin" )
2627 flagCompact = flag .Bool ("compact" , false , "output compact JSON" )
2728 flagDebug = flag .Bool ("debug" , false , "print out all kinds of debug data" )
@@ -307,6 +308,25 @@ func isNone() bool {
307308 return * flagAlg == "none"
308309}
309310
311+ func algHelp () string {
312+ algs := jwt .GetAlgorithms ()
313+ sort .Strings (algs )
314+
315+ var b strings.Builder
316+ b .WriteString ("signing algorithm identifier, one of\n " )
317+ for i , alg := range algs {
318+ if i > 0 {
319+ if i % 7 == 0 {
320+ b .WriteString (",\n " )
321+ } else {
322+ b .WriteString (", " )
323+ }
324+ }
325+ b .WriteString (alg )
326+ }
327+ return b .String ()
328+ }
329+
310330type ArgList map [string ]string
311331
312332func (l ArgList ) String () string {
Original file line number Diff line number Diff line change @@ -33,3 +33,14 @@ func GetSigningMethod(alg string) (method SigningMethod) {
3333 }
3434 return
3535}
36+
37+ // GetAlgorithms returns a list of registered "alg" names
38+ func GetAlgorithms () (algs []string ) {
39+ signingMethodLock .RLock ()
40+ defer signingMethodLock .RUnlock ()
41+
42+ for alg := range signingMethods {
43+ algs = append (algs , alg )
44+ }
45+ return
46+ }
You can’t perform that action at this time.
0 commit comments