Interface ContextAware
- All Known Implementing Classes:
AesCipherContext, ChaChaCipherContext
CtxInterface.
Many cryptographic algorithms require auxiliary values in addition to the key, such as initialization vectors (IVs), nonces, salts, or additional authenticated data (AAD). Implementations that support external parameter passing can expose this interface so higher layers can provide or retrieve these values through a shared context.
Typical parameters
- Initialization vectors (IV) for block cipher modes such as CBC or GCM.
- Nonces for stream ciphers or AEAD schemes.
- Salts for password-based key derivation functions.
- Additional authenticated data (AAD) for AEAD constructions.
Design guidelines
- Implementations should fail fast if required parameters are missing in the provided context.
- Contexts may be reused across operations, but values should be scoped to the session or algorithm instance.
- Implementations should treat
CtxInterfaceas a structured key–value store and avoid ad-hoc parameter passing.
Thread safety
The thread-safety of this interface depends on the providedCtxInterface implementation. Callers should not assume
concurrent mutation is safe unless explicitly documented.- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptioncontext()Returns the context currently in use.voidsetContext(CtxInterface ctx) Attaches a context object that will be used to read and write per-session parameters.
-
Method Details
-
setContext
Attaches a context object that will be used to read and write per-session parameters.Typical values include initialization vectors (IV), nonces, salts, or additional authenticated data (AAD). Implementations may throw if the context is missing required values or contains invalid entries.
- Parameters:
ctx- non-null parameter context- Throws:
NullPointerException- ifctxisnull
-
context
CtxInterface context()Returns the context currently in use.This method must never return
nullafter the first successful invocation ofsetContext(CtxInterface)or after a context has been created internally by the implementation.Implementations must honour this post-condition: return a non-null context once one has been established. Implementations that violate it silently break callers that depend on the non-null guarantee without triggering a compile-time or early runtime error.
- Returns:
- the active parameter context; never
nullafter the context has been set or created
-