Wrap `bundle_bytes` in an `AuthenticatedJoinBundle`.
(
bundle_bytes: Vec<u8>,
cluster_secret: &[u8; 32],
token_hash: &[u8; 32],
)
| 57 | |
| 58 | /// Wrap `bundle_bytes` in an `AuthenticatedJoinBundle`. |
| 59 | pub fn seal_bundle( |
| 60 | bundle_bytes: Vec<u8>, |
| 61 | cluster_secret: &[u8; 32], |
| 62 | token_hash: &[u8; 32], |
| 63 | ) -> Result<AuthenticatedJoinBundle, BundleError> { |
| 64 | let key = derive_mac_key(cluster_secret, token_hash); |
| 65 | let mut mac = <Hmac<Sha256>>::new_from_slice(&key).map_err(|_| BundleError::HmacKeyLength)?; |
| 66 | mac.update(&bundle_bytes); |
| 67 | let tag: [u8; 32] = mac.finalize().into_bytes().into(); |
| 68 | Ok(AuthenticatedJoinBundle { |
| 69 | version: WireVersion::CURRENT, |
| 70 | bundle: bundle_bytes, |
| 71 | mac: tag, |
| 72 | }) |
| 73 | } |
| 74 | |
| 75 | /// Verify the MAC on `sealed` and return the inner bundle bytes. |
| 76 | /// |