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
Convenience base class for concrete
CryptoAlgorithm implementations.
AbstractCryptoAlgorithm streamlines two common tasks during algorithm
construction:
- Binding roles to runtime factories via
capability(AlgorithmFamily, KeyUsage, Class, Class, Class, ContextFactoryKS, Supplier), which registers aroletogether with its expectedCryptoContexttype, acceptedKeytype, optionalContextSpectype, the constructor factory, and a default spec supplier. - Publishing descriptive capabilities by automatically creating and
adding a
Capabilityrecord 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 Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCryptoAlgorithm(String id, String displayName) Constructs an algorithm with default priority (0) and provider"default".protectedAbstractCryptoAlgorithm(String id, String displayName, String providerName) Constructs an algorithm with default priority (0) and an explicit provider name. -
Method Summary
Modifier and TypeMethodDescriptionprotected <C extends CryptoContext, K extends Key, S extends ContextSpec>
voidcapability(AlgorithmFamily family, KeyUsage role, Class<C> ctxType, Class<K> keyType, Class<S> specType, ContextFactoryKS<C, K, S> factory, Supplier<? extends S> defaultSpec) Declares a capability for this algorithm and binds a runtime factory for the given role.Methods inherited from class CryptoAlgorithm
addCapability, asymmetricKeyPairGenerator, bindContext, createContext, displayName, id, keyOperations, listCapabilities, parameterSets, priority, privateKeyImporter, providerName, publicKeyImporter, registerAsymmetricKeyPairGenerator, registerPrivateKeyImporter, registerPublicKeyImporter, registerSymmetricKeyGenerator, registerSymmetricKeyImporter, requiresStatefulSigning, roles, supports, symmetricKeyGenerator, symmetricKeyImporter
-
Constructor Details
-
AbstractCryptoAlgorithm
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- ifidordisplayNameisnull
-
AbstractCryptoAlgorithm
Constructs an algorithm with default priority (0) and an explicit provider name.- Parameters:
id- canonical, provider-independent identifierdisplayName- human-friendly name for logs and diagnosticsproviderName- provider label (e.g.,"JCA","BC","default")- Throws:
NullPointerException- if any argument isnull
-
-
Method Details
-
capability
protected <C extends CryptoContext, K extends Key, S extends ContextSpec> void capability(AlgorithmFamily family, KeyUsage role, Class<C> ctxType, Class<K> keyType, Class<S> specType, ContextFactoryKS<C, K, S> factory, Supplier<? extends S> defaultSpec) Declares a capability for this algorithm and binds a runtime factory for the given role.This single call performs two actions atomically:
- Runtime binding: delegates to
CryptoAlgorithm.bindContext(KeyUsage, Class, Class, Class, ContextFactoryKS, Supplier)so thatCryptoAlgorithm.createContext(KeyUsage, Key, ContextSpec)can construct the appropriateCryptoContextwhen invoked. - Metadata publication: creates a
Capabilitydescribing this role (algorithm id,family, role, context/key/spec types, and default spec supplier) and adds it to the algorithm’s advertised capabilities, discoverable viaCryptoAlgorithm.listCapabilities().
Validation
Type checks happen at creation time (viabind) and again whenCryptoAlgorithm.createContext(KeyUsage, Key, ContextSpec)is called. If a factory returns a context not assignable toctxType, anIllegalStateExceptionwill be thrown.- Type Parameters:
C- context typeK- key typeS- spec type- Parameters:
family- high-level algorithm family classificationrole- supportedKeyUsagerole (e.g.,ENCRYPT,VERIFY)ctxType- concreteCryptoContexttype constructed byfactorykeyType- acceptedKeytype for this rolespecType- acceptedContextSpectype (may be a marker type)factory- constructor that builds a context for (key, spec)defaultSpec- supplier of the default spec used when callers passnull; capability metadata resolves one stable value during registration, while runtime creation retains the supplier contract- Throws:
NullPointerException- if any class, factory, supplier, or metadata default value isnull
- Runtime binding: delegates to
-