| Type | Description |
|---|---|
TAsnTag | Universal tag constants (BOOLEAN, INTEGER, OCTET STRING, OID, SEQUENCE, SET, time and string forms) used by identifier construction and validation |
TAsnClass | Identifier class: asnClassUniversal, asnClassApplication, asnClassContextSpecific, or asnClassPrivate |
TAsnIdentifier | Identifier class, constructed flag, and 64-bit tag number, including high-tag-number form |
TDerTlv | Parsed TLV with Offset, HeaderLength, ContentOffset, ContentLength, NextOffset, and Identifier without copying the source buffer |
TDerWriter | Reusable DER output buffer and typed encoder |
TDerReader | Bounded reader with peek, advance, skip, expected-tag, child-window, slice, and typed decode operations |
TDerByteArrays | Dynamic array of TBytes used by ConcatMany and other multi-buffer helpers |
TDerValidationErrorKind | Validation error categories: dvekMalformedTlv, dvekTrailingData, depth, node, and content limits (dvekDepthLimit, dvekNodeLimit, dvekContentLimit), dvekUniversalForm, per-type canonical failures (dvekBoolean, dvekInteger, dvekBitString, dvekNull, dvekOid, dvekString, dvekTime), and dvekSetOrder |
TDerValidationError | Offset- and Depth-aware error record with Kind and human-readable message text |
TDerValidationErrors | Dynamic array of TDerValidationError returned inside TDerValidationResult |
TDerValidationOptions | Limits in MaxDepth, MaxNodes, MaxContentLength, MaxErrors, the RequireSingleRoot flag, optional ValidateSetOrder, and the Default class function |
TDerValidationResult | Validation status with IsValid, NodeCount, MaximumDepth, offset-aware Errors, plus ErrorCount and FirstError helpers |
| API | Description |
|---|---|
Clear, IsEmpty, Count, Capacity, Bytes, Finish | Reset or inspect buffered data, copy a snapshot, or transfer the completed array and reset the writer |
Reserve, Append, AppendMany, AppendByte | Grow once and append arrays, caller-owned buffers, multiple arrays, or one byte with overflow checks |
Wrap, WrapIdentifier, WrapConstructed | Wrap content with a raw identifier octet, any identifier class and 64-bit tag number, or a constructed identifier |
ContextSpecific, ApplicationSpecific, PrivateSpecific | Encode low or high tag numbers without truncating the identifier |
Sequence, SequenceOf, SetOf, SetOfSorted | Compose encoded values as SEQUENCE or SET containers; SetOfSorted sorts values by encoded bytes |
BooleanOf, IntegerOf, UnsignedIntegerOf, IntegerBytes, EnumeratedOf | Encode BOOLEAN, signed or unsigned INTEGER, validated arbitrary INTEGER content, and ENUMERATED values |
OctetString, OctetStringOf, BitString, Null, OID | Encode binary, bit-string, NULL, and object identifier values as standalone TLVs |
PrintableString, Ia5String, Utf8String | Encode the supported ASN.1 character string forms |
UTCTime, GeneralizedTime, UTCTimeOf, GeneralizedTimeOf, TimeOf | Encode canonical time text or UTC TDateTime values, with TimeOf selecting the correct DER time type |
AlgId, AlgIdWithParams | Build an AlgorithmIdentifier SEQUENCE with NULL or explicit parameters |
| API | Description |
|---|---|
Initialize, AtEnd, EffectiveLimit, Remaining | Initialise a reader and inspect its bounded window and remaining byte count |
TryReadTlvAt, PeekTlv | Parse low or high tag numbers and minimal definite lengths without changing Position |
ReadNextTlv, SkipTlv | Advance only after a complete valid TLV is available |
TryReadExpected | Advance only when class, constructed form, and tag number all match |
EnterConstructed | Create a child reader window over the same source array without copying content |
ContentBytes, EncodedBytes | Copy a validated content or complete TLV slice when ownership is required |
TryReadBoolean, TryReadUnsignedInteger, TryReadBitString | Decode canonical primitive values with range and unused-bit checks |
TryReadString, TryReadTime, TryReadNull | Decode validated UTF8String, PrintableString, IA5String, DER time, or NULL content |
ReadTlv, TryReadOID, ReadOID, TryReadInteger, ReadInteger | Provide compatibility access to raw TLV offsets plus object identifier and signed integer decoding |
function ValidateDer(const Data: TBytes): TDerValidationResult; overload;
function ValidateDer(const Data: TBytes; const Options: TDerValidationOptions): TDerValidationResult; overload;
ValidateDer checks identifier and length minimality, buffer bounds, universal primitive forms, BOOLEAN, INTEGER, ENUMERATED, BIT STRING, NULL, OBJECT IDENTIFIER, supported strings, and canonical time values
Default limits allow a maximum depth of 64, 100000 nodes, 64 MiB per content value, and 32 reported errors while requiring one root TLV
ValidateSetOrder is disabled by default because schema-free DER cannot distinguish every SET from SET OF; enable it for known SET OF containers such as CMS attribute collections
TDerValidationOptions.Default supplies the bounded defaults, while TDerValidationResult.ErrorCount and FirstError simplify diagnostic handling
function AsnIdentifier(TagClass: TAsnClass; TagNumber: UInt64; Constructed: Boolean = False): TAsnIdentifier;
function EncodeIdentifier(const Identifier: TAsnIdentifier): TBytes;
function ConcatBytes(const A, B: TBytes): TBytes;
function Concat3(const A, B, C: TBytes): TBytes;
function Concat4(const A, B, C, D: TBytes): TBytes;
function ConcatMany(const Values: TDerByteArrays): TBytes;
function EncodeOIDContent(const Dotted: AnsiString): TBytes;
function DerValidationErrorKindName(Kind: TDerValidationErrorKind): string;
| Function | Description |
|---|---|
AsnIdentifier | Builds a TAsnIdentifier from class, tag number, and constructed flag, used to drive TDerReader.TryReadExpected |
EncodeIdentifier | Encodes a TAsnIdentifier into its DER identifier bytes, including high-tag-number form |
ConcatBytes, Concat3, Concat4, ConcatMany | Concatenate two, three, four, or a dynamic array of TBytes into one allocation; used widely by the CMS builder |
EncodeOIDContent | Encodes a dotted-decimal OID string into its content bytes without the tag and length, so callers can inspect or re-wrap an OID |
DerValidationErrorKindName | Returns the display name of a TDerValidationErrorKind for diagnostics |
uses FPdfAsn1;
var
Child: TDerReader;
Data: TBytes;
Reader: TDerReader;
Tlv: TDerTlv;
Validation: TDerValidationResult;
Writer: TDerWriter;
begin
Writer := TDerWriter.Create;
try
Data := Writer.Sequence(Writer.UnsignedIntegerOf(42));
finally
Writer.Free;
end;
Validation := ValidateDer(Data);
if not Validation.IsValid then
raise EConvertError.Create(Validation.Errors[0].MessageText);
Reader.Initialize(Data);
if Reader.TryReadExpected(AsnIdentifier(asnClassUniversal, 16, True), Tlv) then
Reader.EnterConstructed(Tlv, Child);
end;
GeneralizedTime accepts optional fractional seconds only when the last fractional digit is non-zeroReadTlv, TryReadOID, and signed TryReadInteger remain available for existing callersFPdfAsn1 alongside the main PDFium Delphi Component units