PLCheckSignatureByteRange

Signature utilities

Description

Checks the two signed ranges surrounding a hexadecimal signature value, using the read-only PDFlibCMSRead unit available in every edition

Syntax

type
  TPLSignatureByteRange = array[0..3] of Int64;
  TPLSignatureRangeRead = function(Offset: Int64; Buffer: Pointer;
    Count: Integer): Integer of object;

function PLCheckSignatureByteRange(Source: TStream;
  const Contents: AnsiString; const ByteRange: TPLSignatureByteRange;
  out ContentsGapValid, RevisionEndValid: Boolean;
  out SignedRevisionLength: Int64): Boolean; overload;

function PLCheckSignatureByteRange(ReadRange: TPLSignatureRangeRead;
  DocumentLength: Int64; const Contents: AnsiString;
  const ByteRange: TPLSignatureByteRange;
  out ContentsGapValid, RevisionEndValid: Boolean;
  out SignedRevisionLength: Int64): Boolean; overload;

Parameters

SourceA borrowed seekable stream whose position is restored after every read; the function neither closes nor writes it
ReadRange, DocumentLengthAn alternative reader method and the source length; the method must return the number of bytes read from the requested offset and manage its own state
ContentsThe decoded signature bytes including any reservation padding; this parameter is binary data, not Unicode or hexadecimal text
ByteRangeFour values describing two ranges; the first offset must be zero, the gap must be positive, and the second range must end within the document
ContentsGapValidTrue after the excluded gap is confirmed to be a hexadecimal string decoding to Contents; PDF whitespace and a final odd digit with an implicit low zero nibble are accepted
RevisionEndValidTrue when the signed boundary ends in an EOF marker followed only by PDF whitespace
SignedRevisionLengthThe end offset of the second range after basic bounds validation, or zero when those initial bounds are invalid

Return values

ResultTrue when the bounds, hexadecimal gap and EOF boundary checks pass

Scope

This helper does not parse cross-reference sections, locate the gap by dictionary ownership, verify a digest or validate a CMS signature, certificate path, revocation status or trusted time

The reader overload bounds individual reads to 64 KiB and the EOF window to 4 KiB; callers processing untrusted inputs should impose their own total gap and work budgets, as the Enterprise PDF/A audit does

Stream and reader exceptions propagate to the caller; the stream overload attempts to restore the borrowed position even when a read raises an exception

The Enterprise verifier uses the same check before its separate cryptographic verification; the helper itself is a Pascal unit function with no DLL or ActiveX forwarding entry point