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

Function issue_token_bytes

nodedb-cluster/src/auth/join_token.rs:52–65  ·  view source on GitHub ↗

Issue a new HMAC-SHA256 join token for `for_node` that expires at `expiry_unix_secs`. Returns the raw token bytes (hex-encode for printing or transmission). Use [`token_to_hex`] to produce the hex string.

(
    secret: &[u8; 32],
    for_node: u64,
    expiry_unix_secs: u64,
)

Source from the content-addressed store, hash-verified

50///
51/// Use [`token_to_hex`] to produce the hex string.
52pub fn issue_token_bytes(
53 secret: &[u8; 32],
54 for_node: u64,
55 expiry_unix_secs: u64,
56) -> Result<[u8; TOKEN_BYTE_LEN], TokenError> {
57 let mut buf = [0u8; TOKEN_BYTE_LEN];
58 buf[..8].copy_from_slice(&for_node.to_le_bytes());
59 buf[8..16].copy_from_slice(&expiry_unix_secs.to_le_bytes());
60 let mut mac = <Hmac<Sha256>>::new_from_slice(secret).map_err(|_| TokenError::HmacKeyLength)?;
61 mac.update(&buf[..TOKEN_HEADER_LEN]);
62 let tag = mac.finalize().into_bytes();
63 buf[TOKEN_HEADER_LEN..].copy_from_slice(&tag);
64 Ok(buf)
65}
66
67/// Convenience: issue a token and return it as a lowercase hex string.
68pub fn issue_token(

Callers 1

issue_tokenFunction · 0.85

Calls 2

updateMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected