TPLSignatureRangeRead

Security and signatures

Description

TPLSignatureRangeRead is the random-access read callback used by PLCheckSignatureByteRange and PLAuditSignatureSource when the document is not a TStream. Each call asks for Count bytes at an absolute offset and returns how many bytes were actually stored.

The type is declared Of Object, so only a method of an instance can be assigned; the usual implementation is a small class that wraps a stream, saves its position, seeks, reads and restores the position. The stream overloads of both helpers are exactly that wrapper.

Syntax

Delphi

TPLSignatureRangeRead = Function(Offset: Int64; Buffer: Pointer;
  Count: Integer): Integer Of Object;

Parameters

OffsetAbsolute byte offset from the start of the document; never negative
BufferDestination buffer that must accept Count bytes
CountNumber of bytes requested; never negative

Return values

CountThe full request was satisfied; the audits require exact reads
Less than CountA short read; the byte-range check fails and the source audit stops as incomplete
0Nothing was read, which callers treat as a failure rather than as end of data

Remarks

Requests are random rather than sequential: the source audit caches 4 KiB slices, moves backwards and re-reads, so a forward-only reader will fail.

Both helpers compare the return value with the request and stop on any difference, so a callback that silently clips at the end of the document cannot produce a partial success.

An exception raised by the callback propagates out of PLCheckSignatureByteRange; PLAuditSignatureSource catches it and returns an incomplete report with the exception text in Reason.

The callback runs on the calling thread, and the same instance must therefore be usable from whichever thread starts the audit.

See also

PLCheckSignatureByteRange, PLAuditSignatureSource