Skip to main content

BootstrapToken

Struct BootstrapToken 

Source
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

Source

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.

Trait Implementations§

Source§

impl Debug for BootstrapToken

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for BootstrapToken

§

impl Freeze for BootstrapToken
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for BootstrapToken

§

impl RefUnwindSafe for BootstrapToken

§

impl Send for BootstrapToken
where RawVecInner: Send,

§

impl Sync for BootstrapToken
where RawVecInner: Sync,

§

impl Unpin for BootstrapToken
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for BootstrapToken

§

impl UnwindSafe for BootstrapToken
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.