Class CommonEdDSASignatureContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, SignatureContext, TagEngine<Signature>
- Direct Known Subclasses:
Ed25519SignatureContext, Ed448SignatureContext
Signature
for streaming sign and verify.
This class is a thin adapter over GenericJcaSignatureContext: it
wires the JCA signature name (for example, "Ed25519" or
"Ed448") and a fixed tag length, then delegates all
SignatureContext operations to the internal delegate. Concrete
subclasses such as Ed25519SignatureContext and
Ed448SignatureContext expose role-specific contexts for signing or
verifying.
Responsibilities
- Bind an EdDSA variant to a
CryptoAlgorithmand a key (PrivateKeyfor signing,PublicKeyfor verifying). - Delegate
SignatureContextandTagEnginebehavior to theGenericJcaSignatureContextinstance. - Enforce a fixed tag length appropriate for the algorithm (64 bytes for Ed25519, 114 bytes for Ed448).
Thread-safety
Instances are stateful and not guaranteed to be thread-safe. Use one context per signing or verification pipeline.
- Since:
- 1.0
-
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCommonEdDSASignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey, String jcaSignatureName, int tagLength) Constructs a signing context for the given EdDSA algorithm.protectedCommonEdDSASignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey, String jcaSignatureName, int tagLength) Constructs a verification context for the given EdDSA algorithm. -
Method Summary
Modifier and TypeMethodDescriptionReturns the algorithm associated with this context.voidclose()Releases resources associated with this context.Returns the core verification predicate used by this context.key()Returns the signing or verification key bound to this context.voidsetExpectedTag(byte[] expected) Sets the expected signature (tag) used in VERIFY mode.voidSets the verification approach used to compare the computed and expected signatures.intReturns the fixed tag (signature) length in bytes for this algorithm.wrap(InputStream upstream) Wraps an upstreamInputStreamso that all data read from it is processed by the underlying signature engine.
-
Constructor Details
-
CommonEdDSASignatureContext
protected CommonEdDSASignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey, String jcaSignatureName, int tagLength) throws GeneralSecurityException Constructs a signing context for the given EdDSA algorithm.The created context operates in SIGN mode. The JCA engine is obtained using the supplied
jcaSignatureName, and the produced signature length is fixed totagLength.- Parameters:
algorithm- associated algorithm descriptor; must not benullprivateKey- private key used for signing; must not benulljcaSignatureName- JCA signature name (for example,"Ed25519"or"Ed448"); must not benulltagLength- fixed signature length in bytes (64 for Ed25519, 114 for Ed448)- Throws:
GeneralSecurityException- if the JCA provider cannot initialize the signature engineNullPointerException- if any argument isnull
-
CommonEdDSASignatureContext
protected CommonEdDSASignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey, String jcaSignatureName, int tagLength) throws GeneralSecurityException Constructs a verification context for the given EdDSA algorithm.The created context operates in VERIFY mode. The JCA engine is obtained using the supplied
jcaSignatureName, and the expected signature length is fixed totagLength.- Parameters:
algorithm- associated algorithm descriptor; must not benullpublicKey- public key used for verification; must not benulljcaSignatureName- JCA signature name (for example,"Ed25519"or"Ed448"); must not benulltagLength- fixed signature length in bytes (64 for Ed25519, 114 for Ed448)- Throws:
GeneralSecurityException- if the JCA provider cannot initialize the signature engineNullPointerException- if any argument isnull
-
-
Method Details
-
algorithm
Returns the algorithm associated with this context.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- the
CryptoAlgorithmdescriptor
-
key
Returns the signing or verification key bound to this context.- Specified by:
keyin interfaceCryptoContext- Returns:
- the
Keyin use
-
close
public void close()Releases resources associated with this context.After calling
close(), further use of this context is undefined.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-
wrap
Wraps an upstreamInputStreamso that all data read from it is processed by the underlying signature engine.In SIGN mode the wrapped stream emits the original data followed by a detached signature trailer at end-of-stream. In VERIFY mode the wrapped stream emits only the body and performs verification at end-of-stream against the expected tag.
- Specified by:
wrapin interfaceTagEngine<Signature>- Parameters:
upstream- input stream supplying data to be signed or verified; must not benull- Returns:
- a wrapped stream that updates the signature engine on read
- Throws:
IOException- if stream wrapping fails
-
tagLength
-
setExpectedTag
public void setExpectedTag(byte[] expected) Sets the expected signature (tag) used in VERIFY mode.Passing
nullclears the expected tag.- Specified by:
setExpectedTagin interfaceTagEngine<Signature>- Parameters:
expected- the signature bytes to verify against, ornullto clear
-
setVerificationApproach
public void setVerificationApproach(ThrowingBiPredicate.VerificationBiPredicate<Signature> strategy) Sets the verification approach used to compare the computed and expected signatures.- Specified by:
setVerificationApproachin interfaceTagEngine<Signature>- Parameters:
strategy- verification predicate to apply in VERIFY mode; may be decorated to throw or flag
-
getVerificationCore
Returns the core verification predicate used by this context.The returned predicate typically delegates to
Signature.verify(byte[]).- Specified by:
getVerificationCorein interfaceTagEngine<Signature>- Returns:
- the base verification predicate
-