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

Function verify_hmac_sha256

nodedb/src/control/security/jwt.rs:256–268  ·  view source on GitHub ↗

Verify HMAC-SHA256 signature.

(secret: &[u8], message: &[u8], expected_signature: &[u8])

Source from the content-addressed store, hash-verified

254
255/// Verify HMAC-SHA256 signature.
256fn verify_hmac_sha256(secret: &[u8], message: &[u8], expected_signature: &[u8]) -> bool {
257 use hmac::{Hmac, Mac};
258 use sha2::Sha256;
259
260 type HmacSha256 = Hmac<Sha256>;
261
262 let mut mac = match HmacSha256::new_from_slice(secret) {
263 Ok(m) => m,
264 Err(_) => return false,
265 };
266 mac.update(message);
267 mac.verify_slice(expected_signature).is_ok()
268}
269
270/// Verify RSA-SHA256 (RS256) signature using a DER-encoded public key.
271///

Callers 1

validateMethod · 0.85

Calls 2

is_okMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected