pub struct StateEncryptionService { /* private fields */ }Expand description
AEAD encryption service for OAuth state and PKCE blobs.
Wire format: URL-safe base64 of [12-byte nonce || ciphertext || 16-byte tag].
The 32-byte key is never printed in fmt::Debug output.
Implementations§
Source§impl StateEncryptionService
impl StateEncryptionService
Sourcepub const fn from_raw_key(
key: &[u8; 32],
algorithm: EncryptionAlgorithm,
) -> Self
pub const fn from_raw_key( key: &[u8; 32], algorithm: EncryptionAlgorithm, ) -> Self
Construct from a raw 32-byte key slice.
Sourcepub fn from_hex_key(
hex: &str,
algorithm: EncryptionAlgorithm,
) -> Result<Self, KeyError>
pub fn from_hex_key( hex: &str, algorithm: EncryptionAlgorithm, ) -> Result<Self, KeyError>
Construct from a 64-character hex string (= 32 bytes).
§Errors
Returns KeyError::WrongLength if hex is not 64 chars.
Returns KeyError::InvalidHex if hex contains non-hex chars.
Sourcepub fn new_from_env(
var: &str,
algorithm: EncryptionAlgorithm,
) -> Result<Self, Error>
pub fn new_from_env( var: &str, algorithm: EncryptionAlgorithm, ) -> Result<Self, Error>
Load the key from an environment variable containing a 64-char hex string.
§Errors
Returns an error if the env var is absent or the value is not valid hex/length.
Sourcepub fn from_compiled_schema(
security_json: &Value,
) -> Result<Option<Arc<Self>>, Error>
pub fn from_compiled_schema( security_json: &Value, ) -> Result<Option<Arc<Self>>, Error>
Build from the security blob of a compiled schema, if enabled.
Returns Ok(None) when the state_encryption key is absent or enabled = false.
§Errors
Returns Err when enabled = true but the key environment variable is absent
or contains an invalid value. The server must refuse to start in this case.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<String, Error>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<String, Error>
Encrypt plaintext to a URL-safe base64 string.
A fresh random nonce is generated on every call.
§Errors
Returns an error only on internal cipher failure (essentially never).
Sourcepub fn decrypt(&self, encoded: &str) -> Result<Vec<u8>, DecryptionError>
pub fn decrypt(&self, encoded: &str) -> Result<Vec<u8>, DecryptionError>
Decrypt a URL-safe base64 string produced by Self::encrypt.
§Errors
DecryptionError::InvalidInput— empty / too-short / bad base64DecryptionError::AuthenticationFailed— tampered or wrong-key
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StateEncryptionService
impl RefUnwindSafe for StateEncryptionService
impl Send for StateEncryptionService
impl Sync for StateEncryptionService
impl Unpin for StateEncryptionService
impl UnsafeUnpin for StateEncryptionService
impl UnwindSafe for StateEncryptionService
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> 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