Constant-time verify `tag` against HMAC-SHA256 over `data` with `key`. Returns `Err` on mismatch.
(key: &MacKey, data: &[u8], tag: &[u8; MAC_LEN])
| 100 | /// Constant-time verify `tag` against HMAC-SHA256 over `data` with `key`. |
| 101 | /// Returns `Err` on mismatch. |
| 102 | pub fn verify_hmac(key: &MacKey, data: &[u8], tag: &[u8; MAC_LEN]) -> Result<()> { |
| 103 | let mut mac = <Hmac<Sha256> as Mac>::new_from_slice(key.as_bytes()) |
| 104 | .expect("HMAC-SHA256 accepts any key length"); |
| 105 | mac.update(data); |
| 106 | mac.verify_slice(tag).map_err(|_| ClusterError::Codec { |
| 107 | detail: "frame MAC verification failed".into(), |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | #[cfg(test)] |
| 112 | mod tests { |