Class AbstractCryptoAlgorithm

java.lang.Object
zeroecho.core.CryptoAlgorithm
zeroecho.core.alg.AbstractCryptoAlgorithm
Direct Known Subclasses:
AesAlgorithm, BikeAlgorithm, ChaCha20Poly1305Algorithm, ChaChaAlgorithm, CmceAlgorithm, DhAlgorithm, EcdhAlgorithm, EcdsaAlgorithm, Ed25519Algorithm, Ed448Algorithm, ElgamalAlgorithm, FrodoAlgorithm, HmacAlgorithm, HqcAlgorithm, KyberAlgorithm, LmsAlgorithm, MldsaAlgorithm, NtruAlgorithm, NtrulPrimeAlgorithm, RsaAlgorithm, SaberAlgorithm, Sha2Sha3Algorithm, SlhDsaAlgorithm, SntruPrimeAlgorithm, SphincsPlusAlgorithm, XdhAlgorithm, XmssAlgorithm, XWingAlgorithm

public abstract class AbstractCryptoAlgorithm extends CryptoAlgorithm
Convenience base class for concrete CryptoAlgorithm implementations.

AbstractCryptoAlgorithm streamlines two common tasks during algorithm construction:

  1. Binding roles to runtime factories via capability(AlgorithmFamily, KeyUsage, Class, Class, Class, ContextFactoryKS, Supplier), which registers a role together with its expected CryptoContext type, accepted Key type, optional ContextSpec type, the constructor factory, and a default spec supplier.
  2. Publishing descriptive capabilities by automatically creating and adding a Capability record that higher layers can inspect for feature discovery, documentation, or automated selection.

Typical usage

public final class AesGcmAlgorithm extends AbstractCryptoAlgorithm {
  public AesGcmAlgorithm() {
    super("AES/GCM", "AES-GCM", "JCA");

    capability(
        AlgorithmFamily.SYMMETRIC,
        KeyUsage.ENCRYPT,
        AeadEncryptContext.class,
        javax.crypto.SecretKey.class,
        AeadSpec.class,
        (key, spec) -> new JcaAesGcmEncryptContext(key, spec),
        AeadSpec::withRandomNonce);

    capability(
        AlgorithmFamily.SYMMETRIC,
        KeyUsage.DECRYPT,
        AeadDecryptContext.class,
        javax.crypto.SecretKey.class,
        AeadSpec.class,
        (key, spec) -> new JcaAesGcmDecryptContext(key, spec),
        AeadSpec::withRandomNonce);
  }
}

Thread-safety

Instances are immutable once constructed and safe to share across threads. The contexts created by registered factories are not necessarily thread-safe.
Since:
1.0
  • Constructor Details

    • AbstractCryptoAlgorithm

      protected AbstractCryptoAlgorithm(String id, String displayName)
      Constructs an algorithm with default priority (0) and provider "default".
      Parameters:
      id - canonical, provider-independent identifier (e.g., "AES/GCM")
      displayName - human-friendly name for logs and diagnostics
      Throws:
      NullPointerException - if id or displayName is null
    • AbstractCryptoAlgorithm

      protected AbstractCryptoAlgorithm(String id, String displayName, String providerName)
      Constructs an algorithm with default priority (0) and an explicit provider name.
      Parameters:
      id - canonical, provider-independent identifier
      displayName - human-friendly name for logs and diagnostics
      providerName - provider label (e.g., "JCA", "BC", "default")
      Throws:
      NullPointerException - if any argument is null
  • Method Details