pub struct SessionId(/* private fields */);Expand description
Session identifier. axess-minted; cryptographic opacity is the
security contract. A session-id leak that revealed login time
would be a vulnerability for forensic correlation against
externally-observed events, so prefer Self::new (UUID v4
random) over time-prefixed variants.
§Logging discipline
SessionId derives std::fmt::Debug and std::fmt::Display
via define_id!; both formats produce the
full hyphenated UUID string. Treat session ids as credentials
in logs: a SessionId that lands in a structured-log line, an
observability pipeline, or a crash dump leaks a still-valid
authenticator. Redact at the emission boundary (a project-local
RedactedSessionId(SessionId) newtype, or manual masking of
middle bytes). axess-identity does not redact at the type
level because the full id form is needed at the storage and
authn-validation boundaries.
Backed by uuid::Uuid (16 bytes, Copy). UUID v4
random when minted via Self::new; v5 namespaced when
adopted from a non-UUID source via
Self::from_namespaced_str; bytes stored verbatim
when restored from persistence via Self::from_bytes.
Wire format under serde is the hyphenated UUID string;
under rkyv it’s the 16-byte archive layout.
Implementations§
Source§impl SessionId
impl SessionId
Sourcepub fn new<R>(rng: &R) -> SessionIdwhere
R: SecureRng,
pub fn new<R>(rng: &R) -> SessionIdwhere
R: SecureRng,
Mint a fresh UUID v4 from the supplied
SecureRng. Sets version 4 +
RFC 4122 variant bits per spec; the remaining 122
bits come from rng.
Sourcepub fn try_new(value: impl AsRef<str>) -> Result<SessionId, IdError>
pub fn try_new(value: impl AsRef<str>) -> Result<SessionId, IdError>
Construct from a string (which must be a valid hyphenated Uuid). Returns IdError::Empty for empty input or IdError::NotAUuid if parsing fails.
Sourcepub const fn from_bytes(bytes: [u8; 16]) -> SessionId
pub const fn from_bytes(bytes: [u8; 16]) -> SessionId
Construct from raw bytes verbatim (version and variant bits are not adjusted). For round-tripping persisted ids whose bytes already encode a valid Uuid.
Sourcepub fn from_random_bytes(bytes: [u8; 16]) -> SessionId
pub fn from_random_bytes(bytes: [u8; 16]) -> SessionId
Construct a UUID v4-shaped id from 16 random bytes (sets version + variant bits per RFC 4122).
Prefer Self::new. This constructor is for the
niche case where 16 random bytes have already been
drawn (e.g. from a fixed test seed buffer or an
external CSPRNG that doesn’t expose
SecureRng). When you have a
SecureRng in scope (production code always does,
tests should), Self::new(&mut rng) is the DST-correct
path: the only random source is the injected RNG, so
tests that mint identity remain reproducible across
runs.
Sourcepub fn from_namespaced_str(namespace: Uuid, name: &str) -> SessionId
pub fn from_namespaced_str(namespace: Uuid, name: &str) -> SessionId
Map a non-UUID adopter identifier (slug, OAuth subject,
integer-stringified, …) to a stable id via UUID v5.
Same (namespace, name) always produces the same id, so
services agree without coordination.
Sourcepub const fn as_bytes(&self) -> &[u8; 16]
pub const fn as_bytes(&self) -> &[u8; 16]
Borrow the raw 16-byte body. Zero-cost handoff to byte-shaped APIs.
Trait Implementations§
Source§impl Archive for SessionId
impl Archive for SessionId
Source§const COPY_OPTIMIZATION: CopyOptimization<SessionId>
const COPY_OPTIMIZATION: CopyOptimization<SessionId>
serialize. Read moreSource§type Archived = ArchivedSessionId
type Archived = ArchivedSessionId
Source§type Resolver = SessionIdResolver
type Resolver = SessionIdResolver
Source§impl<'de> Deserialize<'de> for SessionId
impl<'de> Deserialize<'de> for SessionId
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SessionId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SessionId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<'q, DB> Encode<'q, DB> for SessionId
Available on crate feature sqlx only.
impl<'q, DB> Encode<'q, DB> for SessionId
sqlx only.Source§fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Send + Sync>>
Source§fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
self into buf in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl Ord for SessionId
impl Ord for SessionId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for SessionId
impl PartialOrd for SessionId
Source§impl Serialize for SessionId
impl Serialize for SessionId
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Store<SessionId, SessionData> for MysqlSessionStore
Available on crate feature mysql only.
impl Store<SessionId, SessionData> for MysqlSessionStore
mysql only.Source§type Error = SqlStoreError
type Error = SqlStoreError
StoreError enum for
new backends; legacy wrappers may continue to surface
SqlStoreError / ValkeyStoreError / PostgresStoreError
until each is consolidated.Source§fn get(
&self,
key: &SessionId,
) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
key. Ok(None) when the key is absent
(including TTL-expired); Err only on backend failure.Source§fn put(
&self,
key: &SessionId,
value: &SessionData,
ttl: Duration,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key with the given TTL.Source§fn delete(
&self,
key: &SessionId,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key. Idempotent; does not error if absent.Source§fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
Ok(0); backends owning their own
row table (SQLite, Postgres, in-memory) actually delete.Source§impl Store<SessionId, SessionData> for PostgresSessionStore
Available on crate feature postgres only.
impl Store<SessionId, SessionData> for PostgresSessionStore
postgres only.Source§type Error = SqlStoreError
type Error = SqlStoreError
StoreError enum for
new backends; legacy wrappers may continue to surface
SqlStoreError / ValkeyStoreError / PostgresStoreError
until each is consolidated.Source§fn get(
&self,
key: &SessionId,
) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
key. Ok(None) when the key is absent
(including TTL-expired); Err only on backend failure.Source§fn put(
&self,
key: &SessionId,
value: &SessionData,
ttl: Duration,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key with the given TTL.Source§fn delete(
&self,
key: &SessionId,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key. Idempotent; does not error if absent.Source§fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
Ok(0); backends owning their own
row table (SQLite, Postgres, in-memory) actually delete.Source§impl Store<SessionId, SessionData> for SqliteSessionStore
Available on crate feature sqlite only.
impl Store<SessionId, SessionData> for SqliteSessionStore
sqlite only.Source§type Error = SqlStoreError
type Error = SqlStoreError
StoreError enum for
new backends; legacy wrappers may continue to surface
SqlStoreError / ValkeyStoreError / PostgresStoreError
until each is consolidated.Source§fn get(
&self,
key: &SessionId,
) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
key. Ok(None) when the key is absent
(including TTL-expired); Err only on backend failure.Source§fn put(
&self,
key: &SessionId,
value: &SessionData,
ttl: Duration,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key with the given TTL.Source§fn delete(
&self,
key: &SessionId,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key. Idempotent; does not error if absent.Source§fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
Ok(0); backends owning their own
row table (SQLite, Postgres, in-memory) actually delete.Source§impl Store<SessionId, SessionData> for ValkeySessionStore
Available on crate feature valkey only.
impl Store<SessionId, SessionData> for ValkeySessionStore
valkey only.Source§type Error = ValkeyStoreError
type Error = ValkeyStoreError
StoreError enum for
new backends; legacy wrappers may continue to surface
SqlStoreError / ValkeyStoreError / PostgresStoreError
until each is consolidated.Source§fn get(
&self,
key: &SessionId,
) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send
key. Ok(None) when the key is absent
(including TTL-expired); Err only on backend failure.Source§fn put(
&self,
key: &SessionId,
value: &SessionData,
ttl: Duration,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key with the given TTL.Source§fn delete(
&self,
key: &SessionId,
) -> impl Future<Output = Result<(), Self::Error>> + Send
fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send
key. Idempotent; does not error if absent.Source§fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send
Ok(0); backends owning their own
row table (SQLite, Postgres, in-memory) actually delete.impl Copy for SessionId
impl Eq for SessionId
impl StructuralPartialEq for SessionId
Auto Trait Implementations§
impl Freeze for SessionId
impl RefUnwindSafe for SessionId
impl Send for SessionId
impl Sync for SessionId
impl Unpin for SessionId
impl UnsafeUnpin for SessionId
impl UnwindSafe for SessionId
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, S> SerializeUnsized<S> for T
impl<T, S> SerializeUnsized<S> for T
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.