MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Algorithm

Function Algorithm

ext/security/hmac/hmac.go:73–99  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
73func 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.

Callers 1

CommonAlgorithmsFunction · 0.85

Calls 3

normalizeAlgNameFunction · 0.85
addConstantMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected