pub struct SessionKey(/* private fields */);Expand description
Secret key material used to sign and encrypt session cookies.
The wrapper deliberately does not expose the decoded bytes. Its backing
allocation is cleared when it is dropped, including after
build_session_config has transferred the material into axum_session.
Implementations§
Source§impl SessionKey
impl SessionKey
Sourcepub fn decode(encoded: &str) -> Result<Self, SessionKeyError>
pub fn decode(encoded: &str) -> Result<Self, SessionKeyError>
Decodes an exactly 64-byte key from standard or URL-safe base64.
Sourcepub fn from_environment() -> Result<Self, SessionKeyEnvironmentError>
pub fn from_environment() -> Result<Self, SessionKeyEnvironmentError>
Loads the conventional SESSION_KEY value or its SESSION_KEY_FILE
companion.
Non-debug builds require a persistent key. Debug builds generate a process-local cryptographic key when neither source is configured, so restarting the process invalidates its development sessions.
Sourcepub fn from_environment_or_create_development(
path: impl AsRef<Path>,
) -> Result<Self, SessionKeyEnvironmentError>
pub fn from_environment_or_create_development( path: impl AsRef<Path>, ) -> Result<Self, SessionKeyEnvironmentError>
Loads the configured key or persists one local development key at
path when no key is configured.
Release builds never create key material and retain the same mandatory
SESSION_KEY/SESSION_KEY_FILE contract as Self::from_environment.
Sourcepub fn generate_ephemeral() -> Result<Self, SessionKeyError>
pub fn generate_ephemeral() -> Result<Self, SessionKeyError>
Generates a process-local key for explicitly ephemeral sessions.