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,
)
| 50 | /// |
| 51 | /// Use [`token_to_hex`] to produce the hex string. |
| 52 | pub 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. |
| 68 | pub fn issue_token( |
no test coverage detected