pub struct Aes256GcmCipher { /* private fields */ }encryption only.Expand description
AES-256-GCM (NIST SP 800-38D) through ring, over a keyring: one active
key seals, every key in the ring opens, so a key can be rotated without
re-encrypting what is stored.
A sealed value is the key id’s length (one byte), the key id, a 96-bit nonce and the ciphertext with its 128-bit tag. The key id is not secret and not in the associated data: it only selects the key, and under any other key the tag does not verify.
§The nonce budget
Each value gets a fresh nonce from the operating system’s generator. SP
800-38D §8.3 bounds a key used with random nonces to 2^32 seals; past
it, the chance of two values sharing a nonce, which exposes both
plaintexts’ XOR and lets an attacker forge values, is no longer
negligible. The budget is per key, so it is shared by every process
holding the key and by push configs sealed with the same ring.
EncryptedTaskStore seals the parts a write
stores: on an in-place artifact or status write, only the new ones, so an
artifact streamed in n chunks costs about n seals (until 2026-10-18,
about n²/2; release audit F7).
seal_count says how many this cipher has made.
The budget is enforced per cipher: past DEFAULT_SEAL_LIMIT (2^32),
or the limit set with with_seal_limit, a seal
fails, and with it the store’s write, rather than risk a repeated nonce.
A warning is logged at half the limit and at nine tenths. The count starts
at zero with each cipher, and the true budget is per key across every
process and restart that seals with it, so a deployment of several
replicas, or one that restarts, should set the limit to its share of
2^32 and rotate the active key well before any process reaches it.
With the sqlite or postgres feature, also a PushConfigCipher, so
the SQL push-config stores’ with_cipher can take the same ring.
§Key material
new and with_key zero the copy of the
key they are handed once ring has expanded it. [u8; 32] is Copy,
so the caller’s own copy is the caller’s to zero (hold it in
zeroize::Zeroizing), and a move may leave copies on the stack this
type cannot reach. ring holds the expanded key for as long as the
cipher lives, and this type cannot zero that either.
Implementations§
Source§impl Aes256GcmCipher
impl Aes256GcmCipher
Sourcepub fn new(
key_id: impl Into<String>,
key: [u8; 32],
) -> Result<Aes256GcmCipher, A2aError>
pub fn new( key_id: impl Into<String>, key: [u8; 32], ) -> Result<Aes256GcmCipher, A2aError>
A cipher sealing with key under the id key_id.
§Errors
A2aError::invalid_params when key_id is empty or longer than
MAX_KEY_ID_LEN bytes.
Sourcepub const fn with_seal_limit(self, limit: u64) -> Aes256GcmCipher
pub const fn with_seal_limit(self, limit: u64) -> Aes256GcmCipher
Refuses to seal past limit values (default DEFAULT_SEAL_LIMIT):
this process’s share of the active key’s budget. See the nonce budget
above.
Sourcepub fn with_key(
self,
key_id: impl Into<String>,
key: [u8; 32],
) -> Result<Aes256GcmCipher, A2aError>
pub fn with_key( self, key_id: impl Into<String>, key: [u8; 32], ) -> Result<Aes256GcmCipher, A2aError>
Adds key under key_id, for opening values sealed with it; the
active key is unchanged. To rotate, build the cipher with the new key
and add the old ones with this.
§Errors
A2aError::invalid_params when key_id is empty, longer than
MAX_KEY_ID_LEN bytes, or already in the ring.
Sourcepub fn active_key_id(&self) -> &str
pub fn active_key_id(&self) -> &str
The id of the key that seals.
Sourcepub fn seal_count(&self) -> u64
pub fn seal_count(&self) -> u64
How many values this cipher has sealed since it was built, under any key; see the nonce budget above.
Sourcepub fn into_arc(self) -> Arc<Aes256GcmCipher> ⓘ
pub fn into_arc(self) -> Arc<Aes256GcmCipher> ⓘ
The cipher as the store takes it.
Trait Implementations§
Source§impl ContentCipher for Aes256GcmCipher
impl ContentCipher for Aes256GcmCipher
Source§impl Debug for Aes256GcmCipher
impl Debug for Aes256GcmCipher
Auto Trait Implementations§
impl !Freeze for Aes256GcmCipher
impl Forget for Aes256GcmCipher
impl Move for Aes256GcmCipher
impl RefUnwindSafe for Aes256GcmCipher
impl Send for Aes256GcmCipher
impl Sync for Aes256GcmCipher
impl Unpin for Aes256GcmCipher
impl UnsafeUnpin for Aes256GcmCipher
impl UnwindSafe for Aes256GcmCipher
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].