Skip to main content

Aes256GcmCipher

Struct Aes256GcmCipher 

Source
pub struct Aes256GcmCipher { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Source

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.

Source

pub fn active_key_id(&self) -> &str

The id of the key that seals.

Source

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.

Source

pub fn into_arc(self) -> Arc<Aes256GcmCipher> ⓘ

The cipher as the store takes it.

Trait Implementations§

Source§

impl ContentCipher for Aes256GcmCipher

Source§

fn seal<'a>( &'a self, plaintext: Vec<u8>, context: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, A2aError>> + Send + 'a>>

Encrypts plaintext, authenticating context with it. Read more
Source§

fn open<'a>( &'a self, sealed: Vec<u8>, context: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, A2aError>> + Send + 'a>>

Decrypts what seal returned for the same context. Read more
Source§

impl Debug for Aes256GcmCipher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PushConfigCipher for Aes256GcmCipher

Available on crate features postgres or sqlite only.
Source§

fn seal<'a>( &'a self, plaintext: Vec<u8>, context: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, A2aError>> + Send + 'a>>

Encrypts plaintext, authenticating context with it. Read more
Source§

fn open<'a>( &'a self, sealed: Vec<u8>, context: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, A2aError>> + Send + 'a>>

Decrypts what seal returned for the same context. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more