pub struct SessionToken(/* private fields */);Expand description
A 256-bit random session token for socket authentication.
Implementations§
Source§impl SessionToken
impl SessionToken
Sourcepub fn from_hex(hex: &str) -> Result<Self, Error>
pub fn from_hex(hex: &str) -> Result<Self, Error>
Decode a hex-encoded token string.
§Errors
Returns an error if the hex string is not exactly 64 characters or contains invalid hex digits.
Sourcepub fn write_to_file(&self, path: &Path) -> Result<()>
pub fn write_to_file(&self, path: &Path) -> Result<()>
Write the token to a file with owner-only permissions (0o600).
On Unix, this uses write-then-rename atomicity: writes to a temporary
file at 0o600 (via OpenOptions::mode to avoid a TOCTOU permissions
window), then atomically renames it to the target path. This prevents
a racing read_from_file from seeing a truncated/empty file during
daemon restarts.
§Errors
Returns an error if the file cannot be written or permissions cannot be set.
Sourcepub fn read_from_file(path: &Path) -> Result<Self>
pub fn read_from_file(path: &Path) -> Result<Self>
Read and decode a token from a file.
§Errors
Returns an error if the file cannot be read or contains invalid hex.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SessionToken
impl RefUnwindSafe for SessionToken
impl Send for SessionToken
impl Sync for SessionToken
impl Unpin for SessionToken
impl UnsafeUnpin for SessionToken
impl UnwindSafe for SessionToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more