@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
254 lines (253 loc) • 8.18 kB
TypeScript
import { DigestAlgorithm } from '../../../enumerator';
import { PdfDocument } from '../../../pdf-document';
import { _PdfDictionary } from '../../../pdf-primitives';
import { _PdfCertificate } from '../pdf-certificate';
import { PdfSignature } from './pdf-signature';
import { _PdfCryptographicMessageSyntaxSigner } from './cryptographic-signer';
/**
* Helper class that builds and manages the PDF signature dictionary.
*
* @private
*/
export declare class _PdfSignatureDictionary {
/**
* @private
*/
_dictionary: _PdfDictionary;
private _document;
private _signature;
private _transParam;
private _signaturePermissionsDictionary;
private _cryptographicFilterType;
private _advanceFilterType;
private _requestForCommentsFilterType;
/**
* The byte position marking the end of the first signed range.
*
* @private
* @type {number}
*/
_firstRangeLength: number;
/**
* The starting index of the second range within the file buffer.
*
* @private
* @type {number}
*/
_secondRangeIndex: number;
/**
* Byte position where the ByteRange array begins in the written PDF.
*
* @private
* @type {number}
*/
_startPositionByteRange: number;
/**
* Estimated buffer size used for padding signatures.
*/
private _estimatedSize;
/**
* Certificate helper parsed from the signature contents or provided externally.
*
* @private
* @type {_PdfCertificate}
*/
_certificate: _PdfCertificate;
/**
* Cross-reference table writer used to emit bytes into the PDF stream.
*
*/
private _crossReference;
/**
* Internal CMS/PKCS#7 signer/parser used to build signed data structures.
*
* @private
* @type {_PdfCryptographicMessageSyntaxSigner}
*/
_cmsSigner: _PdfCryptographicMessageSyntaxSigner;
constructor(dictionary: _PdfDictionary, signature: PdfSignature);
constructor(document: PdfDocument, signature: PdfSignature);
/**
* Parse a PDF 'Contents' value into raw bytes.
*
* @private
* @param {any} contents - The raw contents value from the PDF dictionary.
* @returns {Uint8Array} The decoded byte array or undefined.
*/
_parsePdfContents(contents: any): Uint8Array;
/**
* Determine the digest algorithm used by the embedded CMS signer.
*
* @private
* @returns {DigestAlgorithm} The detected digest algorithm.
*/
_parseDigestAlgorithm(): DigestAlgorithm;
/**
* Read a direct string value from the signature dictionary by key.
*
* @private
* @param {string} key - The dictionary key to read.
* @returns {string} The stored string value, or undefined.
*/
_parseDirect(key: string): string;
/**
* Parse the signing date ('M' entry) from the signature dictionary.
*
* @private
* @returns {Date} The parsed signing date, or undefined.
*/
_parseSignedDate(): Date;
/**
* Convert a PDF date string (e.g. "D:YYYYMMDDHHmmSSOHH'mm'") into a Date object.
*
* @private
* @param {string} v - The PDF date string to parse.
* @returns {Date} The parsed Date or undefined if parsing failed.
*/
_parsePdfDate(v: string): Date;
/**
* Save the internal dictionary and signature-related entries into the buffer.
*
* @private
* @param {number[]} buffer - The output byte buffer to write into.
* @returns {void} nothing.
*/
_dictionarySave(buffer: number[]): void;
/**
* Add digest-related reference entries when the signature is a certifying signature.
*
* @private
* @param {number[]} buffer - The output buffer to append to.
* @returns {void} nothing.
*/
_addDigest(buffer: number[]): void;
/**
* Add required signature dictionary entries (Type, Filter, SubFilter, Date, etc.).
*
* @private
* @returns {void} nothing.
*/
_addRequiredItems(): void;
/**
* Determine whether message-digest processing is allowed for this signature.
*
* @private
* @returns {boolean} True when message-digest processing is permitted.
*/
_allowMessageDigestProcessing(): boolean;
/**
* Add optional entries such as Reason, Location, ContactInfo and Name/Prop_Build.
*
* @private
* @returns {void} nothing.
*/
_addOptionalItems(): void;
/**
* Build the /Reference structure used for DocMDP-style permissions.
*
* @private
* @returns {void} nothing.
*/
_addReference(): void;
/**
* Add the Type entry to the dictionary, choosing DocTimeStamp for timestamps.
*
* @private
* @returns {void} nothing.
*/
_addType(): void;
/**
* Format and add the signing date ('M' entry) to the signature dictionary.
*
* @private
* @returns {void} nothing.
*/
_addDate(): void;
/**
* Add a default Filter entry for the signature dictionary.
*
* @private
* @returns {void} nothing.
*/
_addFilter(): void;
/**
* Add the SubFilter entry depending on timestamp/standard selection.
*
* @private
* @returns {void} nothing.
*/
_addSubFilter(): void;
/**
* Compute the combined length of pending uint8 chunks in the cross-reference.
*
* @private
* @returns {number} The accumulated length of cached chunks.
*/
_getLength(): number;
/**
* Reserve space in the PDF for the /Contents entry and record byte positions.
*
* @private
* @param {number[]} buffer - The output buffer being written to.
* @returns {void} nothing.
*/
_addContents(buffer: number[]): void;
/**
* Reserve and write the /ByteRange array placeholder into the output buffer.
*
* @private
* @param {number[]} buffer - The output buffer to write into.
* @returns {void} nothing.
*/
_addRange(buffer: number[]): void;
/**
* Finalize the saved document by patching ByteRange and embedding the signature.
*
* @private
* @param {Uint8Array} buffer - The complete document buffer to update.
* @returns {void} nothing.
*/
_documentSaved(buffer: Uint8Array): void;
/**
* Build and return the PKCS#7/CAdES/CMS content bytes for the supplied data.
*
* @private
* @param {Uint8Array} data - The data to be signed.
* @returns {Uint8Array} The encoded CMS/PKCS#7 signed content.
*/
_getCryptographicStandardContent(data: Uint8Array): Uint8Array;
/**
* Write a string representation into the provided buffer at the given start position.
*
* @private
* @param {Uint8Array} buffer - The buffer to write into.
* @param {string} str - The string to encode and save.
* @param {number} startPosition - The offset where the string should be written.
* @returns {number} The next write position after the saved string.
*/
_saveRangeItem(buffer: Uint8Array, str: string, startPosition: number): number;
/**
* Async variant of `_documentSaved` which finalizes and embeds the signature.
*
* @private
* @param {Uint8Array} buffer - The document buffer to update.
* @returns {Promise<void>} A promise that resolves when the operation completes.
*/
_documentSavedAsync(buffer: Uint8Array): Promise<void>;
/**
* Async variant of `_getCryptographicStandardContent` that may call external callbacks.
*
* @private
* @param {Uint8Array} data - The data to sign.
* @returns {Promise<Uint8Array>} The signed content bytes.
*/
_getCryptographicStandardContentAsync(data: Uint8Array): Promise<Uint8Array>;
/**
* Create timestamp-only PKCS#7/CMS content asynchronously for timestamp signatures.
*
* @private
* @param {Uint8Array} data - The timestamped data.
* @returns {Promise<Uint8Array>} The encoded timestamped content.
*/
_getCryptographicStandardTimestampContentAsync(data: Uint8Array): Promise<Uint8Array>;
}