Interface ContextAware

All Known Implementing Classes:
AesCipherContext, ChaChaCipherContext

public interface ContextAware
Optional service-provider interface for cryptographic primitives that need to share or persist per-session parameters using a 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 CtxInterface as a structured key–value store and avoid ad-hoc parameter passing.

Thread safety

The thread-safety of this interface depends on the provided CtxInterface implementation. Callers should not assume concurrent mutation is safe unless explicitly documented.
Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the context currently in use.
    void
    Attaches a context object that will be used to read and write per-session parameters.
  • Method Details

    • setContext

      void setContext(CtxInterface ctx)
      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 - if ctx is null
    • context

      CtxInterface context()
      Returns the context currently in use.

      This method must never return null after the first successful invocation of setContext(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 null after the context has been set or created