pub struct MultiKeyDecryptor { /* private fields */ }Expand description
An AeadDecryptor that holds multiple keys and applies CipherMatch /
KeyMatchStrength selection semantics.
This is the cipher analogue of
MultiKeyVerifier.
§Key selection
cipher_match follows KeyMatchStrength priority:
- A
ByKeyIdmatch (algorithm + kid) is definitive. - A single
ByAlgorithmmatch is used directly.
decrypt uses the optional CipherMatch to select
the correct key when available. When no CipherMatch is provided, keys are
tried in order.
Unlike MultiKeyVerifier, which
fails closed on ambiguity, trying every candidate is safe here: an AEAD tag
self-authenticates, so a wrong key fails decryption rather than risking
wrong-key acceptance. Try-all is standard practice for rotated symmetric
keys (e.g. cookie-key rotation).
§Errors
When no candidate matches the criteria, decryption fails with
DecryptError::NoMatchingKey without attempting decryption — this is
what lets RetryingDecryptor
trigger a key refresh. When candidates were attempted and all failed, the
last real failure is returned (non-retryable preferred over retryable),
matching the verifier’s dispatch discipline.
Implementations§
Source§impl MultiKeyDecryptor
impl MultiKeyDecryptor
Sourcepub fn new(decryptors: Vec<Arc<dyn AeadDecryptor>>) -> Self
pub fn new(decryptors: Vec<Arc<dyn AeadDecryptor>>) -> Self
Creates a new MultiKeyDecryptor from the given decryptors.
Trait Implementations§
Source§impl AeadDecryptor for MultiKeyDecryptor
impl AeadDecryptor for MultiKeyDecryptor
Source§fn cipher_match(&self, m: &CipherMatch<'_>) -> Option<KeyMatchStrength>
fn cipher_match(&self, m: &CipherMatch<'_>) -> Option<KeyMatchStrength>
Source§fn decrypt<'a>(
&'a self,
cipher_match: Option<&'a CipherMatch<'a>>,
nonce: &'a [u8],
ciphertext: &'a [u8],
tag: &'a [u8],
aad: &'a [u8],
) -> MaybeSendBoxFuture<'a, Result<Vec<u8>, DecryptError>>
fn decrypt<'a>( &'a self, cipher_match: Option<&'a CipherMatch<'a>>, nonce: &'a [u8], ciphertext: &'a [u8], tag: &'a [u8], aad: &'a [u8], ) -> MaybeSendBoxFuture<'a, Result<Vec<u8>, DecryptError>>
Source§fn try_refresh(&self) -> MaybeSendBoxFuture<'_, bool>
fn try_refresh(&self) -> MaybeSendBoxFuture<'_, bool>
JwsVerifier::try_refresh. Read more