Class TagTrailerDataContentBuilder<T>
java.lang.Object
zeroecho.sdk.builders.TagTrailerDataContentBuilder<T>
- Type Parameters:
T- the engine-specific verification type parameter used byTagEngine
- All Implemented Interfaces:
DataContentBuilder<DataContent>
public final class TagTrailerDataContentBuilder<T>
extends Object
implements DataContentBuilder<DataContent>
Builder for
DataContent pipelines that attach or verify an
authentication tag at end of stream.
A TagTrailerDataContentBuilder composes with a TagEngine to
produce DataContent instances for two complementary flows:
- Encrypt (produce): the wrapped engine emits
[body][tag]when EOF is reached. - Decrypt (verify): the trailer is stripped from input, supplied to
TagEngine.setExpectedTag(byte[]), and the body is streamed through the engine for verification.
Construction
- Use the single-engine constructor if only one stream will be built from this instance.
- Prefer the factory constructor (for example, with
TagEngineBuilder) to obtain a freshTagEngineper stream and avoid state reuse.
Verification behavior
throwOnMismatch()- default; verification failures surface asIOExceptionfrom the returned stream when EOF finalizes verification.flagInContext(CtxInterface, Key)- instead of throwing, the engine records aBooleanunder the providedKeyin the suppliedCtxInterface.
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionTagTrailerDataContentBuilder(Supplier<? extends TagEngine<T>> engineFactory) Creates a builder with an engine factory.TagTrailerDataContentBuilder(TagEngine<T> engine) Creates a builder bound to a fixed engine instance. -
Method Summary
Modifier and TypeMethodDescriptionbufferSize(int bytes) Sets the internal I/O buffer size used when stripping the trailer.build(boolean encrypt) Builds aDataContentpipeline for the selected direction.flagInContext(CtxInterface ctx, Key<Boolean> verifyKey) Configures decryption to flag the verification outcome in the provided context instead of throwing.Configures decryption to throw on verification mismatch.
-
Constructor Details
-
TagTrailerDataContentBuilder
Creates a builder bound to a fixed engine instance.This form ties the builder to a single-use engine. Prefer
TagTrailerDataContentBuilder(Supplier)when multiple streams are expected.- Parameters:
engine- preconstructed engine instance; must not benull- Throws:
NullPointerException- ifengineisnull
-
TagTrailerDataContentBuilder
Creates a builder with an engine factory.A fresh engine is obtained for each built stream. See
TagEngineBuilderfor standard factories.- Parameters:
engineFactory- supplier producing a newTagEngine; must not benull- Throws:
NullPointerException- ifengineFactoryisnull
-
-
Method Details
-
bufferSize
Sets the internal I/O buffer size used when stripping the trailer.- Parameters:
bytes- buffer size in bytes; must be at least 1- Returns:
- this builder for chaining
- Throws:
IllegalArgumentException- ifbytes < 1
-
throwOnMismatch
Configures decryption to throw on verification mismatch.This is the default. The underlying engine is set up to raise
IOExceptionat EOF when the computed tag does not equal the expected tag.- Returns:
- this builder for chaining
-
flagInContext
Configures decryption to flag the verification outcome in the provided context instead of throwing.On mismatch,
Boolean.FALSEis stored underverifyKey; on success,Boolean.TRUEis stored.- Parameters:
ctx- context for recording the result; must not benullverifyKey- key under which to record the verification result; must not benull- Returns:
- this builder for chaining
- Throws:
NullPointerException- ifctxorverifyKeyisnull
-
build
Builds aDataContentpipeline for the selected direction.- Encrypt: the engine appends the tag trailer after body bytes.
- Decrypt: the trailer is stripped, supplied to the engine, and the body is streamed and verified.
- Specified by:
buildin interfaceDataContentBuilder<T>- Parameters:
encrypt-trueto build the encrypting path,falsefor the decrypting path- Returns:
- the configured
DataContentpipeline
-