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

Function seal_bundle

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

Wrap `bundle_bytes` in an `AuthenticatedJoinBundle`.

(
    bundle_bytes: Vec<u8>,
    cluster_secret: &[u8; 32],
    token_hash: &[u8; 32],
)

Source from the content-addressed store, hash-verified

57
58/// Wrap `bundle_bytes` in an `AuthenticatedJoinBundle`.
59pub 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///

Calls 3

derive_mac_keyFunction · 0.85
updateMethod · 0.45
finalizeMethod · 0.45