function ValidatePades: TPadesValidationResult;
Parses embedded signature dictionaries from the original loaded bytes, checks their structure for PAdES baseline compliance and keeps signature offsets separate from the expanded object-stream view used for catalogue and DSS lookup
Required signature entries are counted only at the top dictionary level so duplicate Contents, ByteRange, SubFilter, Filter or Type keys cannot be hidden by parser-selected values, whilst same-named keys in nested dictionaries and arrays remain independent
Signature discovery uses a linear lexical scan that skips stream bodies, strings, hexadecimal values and comments, decodes #xx name escapes, and remains independent of whether a nested dictionary appears before or after the signature entries
The excluded /ByteRange gap must equal the complete direct hexadecimal /Contents token, including its delimiters, and every covered revision must end at a complete PDF revision boundary
On Windows, ordinary detached CMS signatures are verified directly against the two original /ByteRange segments, including CMS signed attributes, the cryptographic signature value and the SHA-256 signing-certificate-v2 binding
Each signer also receives an algorithm profile parsed from CMS and X.509 identifiers, with ISO/TS 32002 checks for supported NIST and Brainpool curves, Ed25519, Ed448, digest congruence, named-curve parameters and SHAKE256 output length
Active to be TrueTPadesValidationResult record detailing the reached PAdES compliance level (B-B, B-T, B-LT, B-LTA) and a set of any detected validation issuesTPdf.ValidatePadesTrust and its TimeStampStatus, CmsSignatureStatus and CertificateTrustStatus values before relying on a level as evidenceTPadesValidationResult.Issues set can hold any of these TPadesValidationIssue values, grouped by theme; signature presence and dictionary cardinality: ppeiNoSignature (no signature dictionary carrying /ByteRange was found), ppeiDuplicateContents (duplicate /Contents key), ppeiDuplicateByteRange (duplicate /ByteRange key), ppeiDuplicateSubFilter (duplicate /SubFilter key), ppeiDuplicateFilter (duplicate /Filter key), ppeiDuplicateSignatureType (duplicate /Type key), ppeiMissingFilter (/Filter absent), ppeiBadFilter (/Filter has no valid name value), ppeiBadSignatureType (ordinary signature /Type is not Sig), ppeiBadDtsType (Document Time-stamp /Type is not DocTimeStamp); subfilter and byte range: ppeiBadSubFilter (/SubFilter is not a recognised PAdES subfilter), ppeiForbiddenSubFilter (legacy adbe.pkcs7.sha1 or adbe.x509.rsa_sha1), ppeiMissingByteRange (/ByteRange absent), ppeiBadByteRangeShape (not exactly four integers [0 a b c]), ppeiByteRangeNotCoveringFile (does not span the whole file minus /Contents); detached content: ppeiMissingContents (/Contents absent or zero-length), ppeiBadContentsShape (not a DER CMS SignedData or RFC3161 TimeStampToken), ppeiZeroPaddedContents (entirely zero bytes), ppeiForbiddenCertKey (/Cert present); CMS SignedData structure: ppeiNotSignedData (top-level SEQUENCE does not wrap id-signedData), ppeiBadSignedDataVersion (version field missing or out of range), ppeiSingleSignerViolation (signerInfos does not hold exactly one SignerInfo), ppeiDetachedContentViolation (encapContentInfo.eContent present); signed attributes and algorithms: ppeiMissingContentType (content-type signed attribute absent), ppeiMissingMessageDigest (message-digest signed attribute absent), ppeiMissingSigningCertificate (neither signing-certificate nor signing-certificate-v2), ppeiBadDigestAlgorithm (MD5 or SHA-1 used as digest), ppeiSignatureAlgorithmMismatch (elliptic curve, digest, or AlgorithmIdentifier mismatch); commitments and trust: ppeiReasonCommitmentConflict (/Reason present alongside commitment-type-indication), ppeiMissingTrustedTime (reserved: B-T derives from the presence of a timestamp, so a document without one stays at B-B and Result.Level reports that rather than a separate issue), ppeiMissingDss (catalogue /DSS absent), ppeiDssMissingCerts (/DSS /Certs absent or empty), ppeiMissingExtensions (catalogue /Extensions /ESIC Level 1 marker absent); document time-stamps: ppeiMissingDocTimeStamp (no Document Time-stamp signature dictionary), ppeiMissingExtensionsL2 (/Extensions /ESIC Level 2 marker absent), ppeiBadDtsSubFilter (a /DocTimeStamp dictionary carrying a /SubFilter other than ETSI.RFC3161), ppeiForbiddenDtsKey (clause 5.4.3 should-not keys present: /Name, /M, /Location, /ContactInfo), ppeiForbiddenDtsKeyStrict (clause 5.4.3 shall-not keys present: /Cert, /Reference, /Changes, /R, /Prop_AuthTime, /Prop_AuthType), ppeiBadDtsVersion (Document Time-stamp /V is present and not 0), ppeiMissingSigningTime (signature dictionary lacks a non-empty /M, clause 6.3 Table 1), ppeiForbiddenCmsSigningTime (CMS signed attributes carry the forbidden signing-time attribute), ppeiMissingSignedDataCertificates (SignedData.certificates absent or empty), ppeiCmsAlgorithmProtectionMismatch (present algorithm-protection does not match SignerInfo); DSS and VRI structure (clause 5.4.2): ppeiDssStructureMalformed (a DSS array element is not an indirect reference, or a /VRI value is not a dictionary the reader can follow), ppeiDssVriKeyMalformed (a /VRI key is not 40 base-16 digits, or is spelled in lower case), ppeiDssVriKeyUnmatched (a /VRI key matches the SHA-1 of no signature /Contents), ppeiDssVriEmptyArray (a Signature VRI Cert, CRL or OCSP array is present but empty), ppeiDssVriTuTsConflict (a Signature VRI carries both /TU and /TS), ppeiDssVriArrayNotInDss (a Signature VRI array names a stream that the matching document-level array does not), ppeiTooManySignatures (the document holds more than 32 signature dictionaries; only the first 32 are validated and trust validation reports the integrity as indeterminate)SourceStatus is pvssOriginalBytes when the original file, buffered memory or custom stream was inspected, pvssIncomplete for an unfinished progressive source, and pvssUnavailable when the original bytes were not retainedIsCompliant and IsCompliantAt return False unless SourceStatus is pvssOriginalBytesIntegrityStatus aggregates ordinary signature integrity whilst Signatures reports each ByteRange, CMS signature, algorithm policy, signer-certificate binding, system trust, revocation and timestamp state separatelyAlgorithmInfo exposes digest, signature, public-key and named-curve OIDs, whilst AlgorithmPolicyStatus distinguishes a valid profile, a malformed combination, an unsupported curve or algorithm, and unavailable certificate evidencepcsInvalid; SHA-1 and 112-bit digests such as SHA-224 are pcsIndeterminate because they are no longer agreed for current validation; a digestAlgorithm differing from the digest fixed by the signature algorithm, or an RSA algorithm on a non-RSA key, is pcsInvalid and raises ppeiSignatureAlgorithmMismatchid-shake256-lenppeiSignatureAlgorithmMismatch is raised when a recognised curve, digest, signature OID or required parameter combination disagreesIsCryptographicallyValid returns True only when original bytes were available, at least one ordinary signature was found, and every checked ordinary signature passed detached CMS and signer-certificate binding verificationCertificateTrustStatus uses cache-only Windows system trust evaluation; RevocationStatus and TimeStampStatus remain pcsNotChecked or pcsUnsupported until those independent checks have been performed%%EOF; later incremental DSS, timestamp or signature revisions do not make that earlier range structurally invalidFilter must occur exactly once and have a name value; an optional ordinary signature Type must be Sig, whilst a Document Time-stamp requires exactly one Type /DocTimeStamp and SubFilter /ETSI.RFC3161Contents value, extra excluded bytes or inconsistent signature type and subfilter values prevent promotion to PAdES B-BplUnknown; plNone is reserved for documents where no signature dictionary was detectedpcsUnsupported rather than being inferred from structural checks
var
Res: TPadesValidationResult;
begin
if not Pdf1.Active then Exit;
Res := Pdf1.ValidatePades;
if Res.IsCryptographicallyValid then
ShowMessage('PAdES signature integrity passed');
end;