pub struct BootstrapToken(/* private fields */);Expand description
The bootstrap token: 64 lowercase hex digits proving entitlement to claim a node.
The node writes it to <state_dir>/bootstrap-token at first boot and never
serves it over HTTP; whoever can read that file is the owner. The value
is held in zeroising memory, has a redacting Debug, and is neither
Clone, Display nor Serialize. Reading a token also registers it
for redaction: for the rest of the process, everything written through
Output has the token (in either letter case, and its
base64 forms) replaced by <redacted>, including text a node sends back.
§Examples
use stratum_node_cli::BootstrapToken;
let dir = std::env::temp_dir().join(format!("stratum-token-doc-{}", std::process::id()));
std::fs::create_dir_all(&dir)?;
let path = dir.join("bootstrap-token");
std::fs::write(&path, format!("{}\n", "ab".repeat(32)))?;
let token = BootstrapToken::read_file(&path)?;
assert!(!format!("{token:?}").contains("abab"));Implementations§
Source§impl BootstrapToken
impl BootstrapToken
Sourcepub fn read_file(path: &Path) -> Result<Self, TokenFileError>
pub fn read_file(path: &Path) -> Result<Self, TokenFileError>
Reads the token from the node’s token file.
The file must be a regular file (not a symbolic link) holding 64 lowercase hex digits, optionally followed by a newline. Its mode is not checked: the file belongs to the node, and reading it at all is the proof of entitlement.
§Errors
Returns TokenFileError::File when the file cannot be read safely
and TokenFileError::Malformed when it does not hold a token. No
error carries any part of the file.