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

Function open_bundle

nodedb-cluster/src/auth/bundle.rs:78–95  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

76///
77/// The comparison is constant-time via `hmac::Mac::verify_slice`.
78pub 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)]
98mod tests {

Callers 2

seal_and_open_roundtripFunction · 0.85

Calls 2

derive_mac_keyFunction · 0.85
updateMethod · 0.45

Tested by 2

seal_and_open_roundtripFunction · 0.68