MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / compute_hmac

Function compute_hmac

nodedb/src/control/security/siem.rs:202–218  ·  view source on GitHub ↗

Compute HMAC-SHA256 signature for webhook payload.

(secret: &str, message: &str)

Source from the content-addressed store, hash-verified

200
201/// Compute HMAC-SHA256 signature for webhook payload.
202fn compute_hmac(secret: &str, message: &str) -> String {
203 use hmac::{Hmac, Mac};
204 use sha2::Sha256;
205
206 type HmacSha256 = Hmac<Sha256>;
207
208 let Ok(mut mac) = HmacSha256::new_from_slice(secret.as_bytes()) else {
209 return String::new();
210 };
211 mac.update(message.as_bytes());
212 let result = mac.finalize();
213 result
214 .into_bytes()
215 .iter()
216 .map(|b| format!("{b:02x}"))
217 .collect()
218}
219
220#[cfg(test)]
221mod tests {

Callers 2

build_webhook_payloadMethod · 0.70
hmac_consistencyFunction · 0.70

Calls 5

collectMethod · 0.80
as_bytesMethod · 0.45
updateMethod · 0.45
finalizeMethod · 0.45
iterMethod · 0.45

Tested by 1

hmac_consistencyFunction · 0.56