Algorithm registers a crypto.Hash algorithm with optional aliases (e.g. Algorithm(crypto.SHA256, "HS256")), exposing constant declarations (e.g., hmac.SHA256, hmac.HS256) in CEL and enabling it for HMAC operations.
(h crypto.Hash, aliases ...string)
| 71 | // (e.g. Algorithm(crypto.SHA256, "HS256")), |
| 72 | // exposing constant declarations (e.g., hmac.SHA256, hmac.HS256) in CEL and enabling it for HMAC operations. |
| 73 | func Algorithm(h crypto.Hash, aliases ...string) Option { |
| 74 | return func(l *hmacLib) *hmacLib { |
| 75 | if l.customAlgorithms == nil { |
| 76 | l.customAlgorithms = make(map[string]crypto.Hash) |
| 77 | } |
| 78 | name := h.String() |
| 79 | normName := normalizeAlgName(name) |
| 80 | l.customAlgorithms[normName] = h |
| 81 | l.customAlgorithms[name] = h |
| 82 | for _, alias := range aliases { |
| 83 | l.customAlgorithms[normalizeAlgName(alias)] = h |
| 84 | l.customAlgorithms[alias] = h |
| 85 | } |
| 86 | |
| 87 | if normName != "" { |
| 88 | l.addConstant("hmac."+normName, normName) |
| 89 | } |
| 90 | for _, alias := range aliases { |
| 91 | constAlias := normalizeAlgName(alias) |
| 92 | if constAlias != "" { |
| 93 | l.addConstant("hmac."+constAlias, normName) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return l |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // CommonAlgorithms registers the most common HMAC hash algorithms (SHA256, SHA384, SHA512, SHA224, SHA512/256, SHA512/224) |
| 102 | // along with their JOSE/JWT aliases (HS256, HS384, HS512, HS224, HS512/256, HS512/224) using Algorithm options by proxy. |
no test coverage detected