UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

72 lines (71 loc) 2.57 kB
/** * Builds the internal DER-encoded DigestInfo structure for a given AlgorithmIdentifier and digest. * * @private */ var _PdfDigestInformation = /** @class */ (function () { function _PdfDigestInformation(algorithm, digest) { this._algorithm = algorithm; this._digest = digest; } /** * Encodes the DigestInfo structure as DER: SEQUENCE { AlgorithmIdentifier, OCTET STRING digest }. * * @private * @returns {Uint8Array} The DER-encoded DigestInfo bytes. */ _PdfDigestInformation.prototype._getUniqueEncoded = function () { var algorithmBytes = this._algorithm._getEncoded(); var digestBytes = this._digest; var algorithmLength = algorithmBytes.length; var digestLength = digestBytes.length; var contentLength = algorithmLength + digestLength + 1 + this._getLengthBytes(digestLength).length; var result = []; result.push(0x30); var lengthBytes = this._getLengthBytes(contentLength); if (lengthBytes.length === 1) { result.push(lengthBytes[0]); } else { result.push(0x80 | (lengthBytes.length - 1)); for (var i = 1; i < lengthBytes.length; i++) { result.push(lengthBytes[i]); } } result.push.apply(result, Array.from(algorithmBytes)); result.push(0x04); var digestLengthBytes = this._getLengthBytes(digestLength); if (digestLengthBytes.length === 1) { result.push(digestLengthBytes[0]); } else { result.push(0x80 | (digestLengthBytes.length - 1)); for (var i = 1; i < digestLengthBytes.length; i++) { result.push(digestLengthBytes[i]); } } result.push.apply(result, Array.from(digestBytes)); return new Uint8Array(result); }; /** * Encodes a length using DER definite-length rules. * * @private * @param {number} length The content length to encode. * @returns {number[]} The DER-encoded length bytes. */ _PdfDigestInformation.prototype._getLengthBytes = function (length) { if (length < 128) { return [length]; } var bytes = []; var tempLength = length; while (tempLength > 0) { bytes.unshift(tempLength & 0xFF); tempLength = Math.floor(tempLength / 256); } return [0x80 | bytes.length].concat(bytes); }; return _PdfDigestInformation; }()); export { _PdfDigestInformation };