pub struct RequestStateCodec { /* private fields */ }Expand description
HMAC-SHA256 codec for opaque, expiring MRTR requestState values.
Construct the codec with the same key and TTL on every server instance
that may receive a retry. Use encode_for and
decode_for when an authenticated subject is
available; subject binding prevents one user from replaying another user’s
continuation token. Binding is intentionally explicit: authentication
middleware may place any application-defined principal type in request
extensions, so the transport-neutral codec cannot safely infer one.
Implementations§
Source§impl RequestStateCodec
impl RequestStateCodec
Sourcepub fn new(
key: impl AsRef<[u8]>,
ttl: Duration,
) -> Result<Self, RequestStateError>
pub fn new( key: impl AsRef<[u8]>, ttl: Duration, ) -> Result<Self, RequestStateError>
Create a codec from a shared key and token TTL.
The key must contain at least 32 bytes of entropy. Configuration secrets should be decoded to raw bytes before calling this constructor.
Sourcepub fn with_max_token_bytes(self, max_token_bytes: usize) -> Self
pub fn with_max_token_bytes(self, max_token_bytes: usize) -> Self
Set the maximum accepted and emitted token size.
Sourcepub fn encode<T: Serialize>(
&self,
state: &T,
) -> Result<String, RequestStateError>
pub fn encode<T: Serialize>( &self, state: &T, ) -> Result<String, RequestStateError>
Encode state without authorization-subject binding.
Sourcepub fn encode_for<T: Serialize>(
&self,
subject: impl Into<String>,
state: &T,
) -> Result<String, RequestStateError>
pub fn encode_for<T: Serialize>( &self, subject: impl Into<String>, state: &T, ) -> Result<String, RequestStateError>
Encode state bound to an authenticated subject identifier.
Sourcepub fn decode<T: DeserializeOwned>(
&self,
token: &str,
) -> Result<T, RequestStateError>
pub fn decode<T: DeserializeOwned>( &self, token: &str, ) -> Result<T, RequestStateError>
Verify and decode state that was not subject-bound.
Sourcepub fn decode_for<T: DeserializeOwned>(
&self,
token: &str,
subject: &str,
) -> Result<T, RequestStateError>
pub fn decode_for<T: DeserializeOwned>( &self, token: &str, subject: &str, ) -> Result<T, RequestStateError>
Verify and decode state for the current authenticated subject.
Trait Implementations§
Source§impl Clone for RequestStateCodec
impl Clone for RequestStateCodec
Source§fn clone(&self) -> RequestStateCodec
fn clone(&self) -> RequestStateCodec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more