Verify the MAC on `sealed` and return the inner bundle bytes. The comparison is constant-time via `hmac::Mac::verify_slice`.
(
sealed: &'a AuthenticatedJoinBundle,
cluster_secret: &[u8; 32],
token_hash: &[u8; 32],
)
| 76 | /// |
| 77 | /// The comparison is constant-time via `hmac::Mac::verify_slice`. |
| 78 | pub fn open_bundle<'a>( |
| 79 | sealed: &'a AuthenticatedJoinBundle, |
| 80 | cluster_secret: &[u8; 32], |
| 81 | token_hash: &[u8; 32], |
| 82 | ) -> Result<&'a [u8], BundleError> { |
| 83 | if sealed.version != WireVersion::CURRENT { |
| 84 | return Err(BundleError::VersionMismatch { |
| 85 | expected: WireVersion::CURRENT, |
| 86 | got: sealed.version, |
| 87 | }); |
| 88 | } |
| 89 | let key = derive_mac_key(cluster_secret, token_hash); |
| 90 | let mut mac = <Hmac<Sha256>>::new_from_slice(&key).map_err(|_| BundleError::HmacKeyLength)?; |
| 91 | mac.update(&sealed.bundle); |
| 92 | mac.verify_slice(&sealed.mac) |
| 93 | .map_err(|_| BundleError::MacMismatch)?; |
| 94 | Ok(&sealed.bundle) |
| 95 | } |
| 96 | |
| 97 | #[cfg(test)] |
| 98 | mod tests { |