pub struct Aead { /* private fields */ }Expand description
A bound encryptor/decryptor holding the derived key.
Implementations§
Source§impl Aead
impl Aead
Sourcepub fn new(raw_key: &str) -> Result<Self>
pub fn new(raw_key: &str) -> Result<Self>
Build a codec from the raw configured key value (see derive_key).
Sourcepub fn is_ciphertext(value: &str) -> bool
pub fn is_ciphertext(value: &str) -> bool
True if value is one of our ciphertext tokens, in EITHER format (vs.
legacy plaintext).
Recognising both matters: if this matched only v1, then
Aead::maybe_decrypt would classify a bound token as legacy plaintext
and hand the raw ciphertext back to the caller as though it were the
value.
Sourcepub fn encrypt(&self, plaintext: &str) -> String
pub fn encrypt(&self, plaintext: &str) -> String
Encrypt into an unbound enc.v1.gcm.… token (AAD empty).
Panics if the OS CSPRNG is unavailable. This is a deliberate
divergence from crate::new_session_id, which falls back to a weak
entropy mix: a guessable session id is bad, but a REPEATED GCM nonce is
catastrophic — it leaks the XOR of two plaintexts and enables tag
forgery. There is no safe degraded mode here, so this fails loudly.
Sourcepub fn encrypt_bound(&self, plaintext: &str, aad: &[u8]) -> String
pub fn encrypt_bound(&self, plaintext: &str, aad: &[u8]) -> String
Encrypt into a bound enc.v2.gcm.… token.
aad names the row and column this ciphertext belongs to, so it
authenticates nowhere else — moving it to another row makes it
undecryptable rather than silently valid.
Sourcepub fn decrypt(&self, token: &str) -> Result<String>
pub fn decrypt(&self, token: &str) -> Result<String>
Decrypt an UNBOUND enc.v1.gcm.… token. A bound token is rejected here:
reading one through this path would drop the binding check silently.
Sourcepub fn decrypt_bound(&self, token: &str, aad: &[u8]) -> Result<String>
pub fn decrypt_bound(&self, token: &str, aad: &[u8]) -> Result<String>
Decrypt a bound enc.v2.gcm.… token, requiring aad to match the
binding it was sealed under.
An unbound v1 token is REJECTED rather than accepted-without-checking: otherwise the binding is opt-out and anything able to write the row would simply store the unbound form.
Sourcepub fn maybe_decrypt(&self, value: &str) -> Result<String>
pub fn maybe_decrypt(&self, value: &str) -> Result<String>
Migrate-on-read: decrypt if the value is one of our tokens, otherwise treat it as legacy plaintext and return it unchanged. Callers re-encrypt on the next write, transparently upgrading old rows.
Auto Trait Implementations§
impl Freeze for Aead
impl RefUnwindSafe for Aead
impl Send for Aead
impl Sync for Aead
impl Unpin for Aead
impl UnsafeUnpin for Aead
impl UnwindSafe for Aead
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
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