pub struct SessionSecret(/* private fields */);Expand description
Server-held signing key. Wrap Vec<u8> so callers can’t
accidentally print it. Clone is opt-in so the same secret can
be shared across layers that use distinct cookie names + payload
shapes (e.g. tenancy operator + tenancy tenant + bare admin —
three layers, one key, three independent cookies).
Implementations§
Source§impl SessionSecret
impl SessionSecret
Sourcepub fn from_env_or_random() -> Self
pub fn from_env_or_random() -> Self
Read the secret from RUSTANGO_SESSION_SECRET (base64-encoded
32+ bytes). Falls back to a randomly generated secret with a
tracing::warn when the var is unset — sessions are then
invalidated on every server restart.
When the var IS set but unparseable (bad base64, fewer than
32 bytes), we ALSO print a loud eprintln! to stderr in
addition to the tracing::warn (history: operators who set
the var and forgot to run it through base64 quietly lost
session persistence on every redeploy).
Sourcepub fn from_env_or_disk(disk_path: &Path) -> Self
pub fn from_env_or_disk(disk_path: &Path) -> Self
Dev-friendly variant of Self::from_env_or_random that
persists the generated key to disk so sessions survive
server restarts even without RUSTANGO_SESSION_SECRET set.
Resolution order:
RUSTANGO_SESSION_SECRETenv var — production path.- Read
disk_pathif it exists and contains ≥ 32 bytes. - Generate a random key, atomically write it to
disk_path(creating parent directories as needed), and return it. - If the write fails, fall back to ephemeral random + a
tracing::warn!.
Used by the runserver boot path so dev cargo run cycles
don’t sign every operator out on every reload (#69).
Production deployments should still set
RUSTANGO_SESSION_SECRET so the secret lives in env / a
secret-manager rather than the filesystem.
Sourcepub fn try_from_env() -> Result<Self, SessionSecretError>
pub fn try_from_env() -> Result<Self, SessionSecretError>
Strict variant of Self::from_env_or_random: returns
Err(...) when the env var is set but unparseable or
too short. Use this from production boot paths where a
malformed secret should fail loudly instead of silently
downgrading to a random ephemeral key.
§Errors
SessionSecretError::BadBase64 when decode fails;
SessionSecretError::TooShort when the decoded bytes are
fewer than 32.
Sourcepub fn require_from_env() -> Result<Self, SessionSecretError>
pub fn require_from_env() -> Result<Self, SessionSecretError>
Strict variant for production boot: requires
RUSTANGO_SESSION_SECRET to be present, valid base64, and ≥ 32
bytes. Unlike Self::try_from_env, an unset var is an error
(SessionSecretError::Missing) rather than a silent random
key — an ephemeral key breaks multi-instance deployments and
masks a missing-secret misconfiguration. Used by
load_session_secret_for_tier on the prod tier.
§Errors
SessionSecretError::Missing when unset; BadBase64 /
TooShort per Self::try_from_env.
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Self
pub fn from_bytes(bytes: Vec<u8>) -> Self
Construct from raw bytes — useful for tests + callers that load the key from a custom source.
Trait Implementations§
Source§impl Clone for SessionSecret
impl Clone for SessionSecret
Source§fn clone(&self) -> SessionSecret
fn clone(&self) -> SessionSecret
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SessionSecret
impl RefUnwindSafe for SessionSecret
impl Send for SessionSecret
impl Sync for SessionSecret
impl Unpin for SessionSecret
impl UnsafeUnpin for SessionSecret
impl UnwindSafe for SessionSecret
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more