UNPKG

@syncfusion/ej2-pdf

Version:

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

76 lines (75 loc) 3.2 kB
import { _ConstructionType, _TagClassType, _UniversalType } from '../asn1/enumerator'; import { _PdfUniqueEncodingElement } from '../asn1/unique-encoding-element'; import { _PdfAlgorithms } from './x509-algorithm'; import { _PdfUniqueBitString } from './x509-bit-string-handler'; import { _PdfPublicKeyInformation } from './x509-certificate-key'; import { _PdfX509Extensions } from './x509-extensions'; import { _PdfX509Name } from './x509-name'; import { _PdfX509Time } from './x509-time'; /** * Parsed representation of an X.509 signed certificate (tbsCertificate + signature metadata). * * @private */ var _PdfSignedCertificate = /** @class */ (function () { function _PdfSignedCertificate(sequenceElement) { this._sequence = sequenceElement._getSequence(); var seqStart = 0; if (this._sequence[0]._getTagNumber() === 0 && this._sequence[0]._tagClass === 2) { this._version = 2; } else { seqStart = -1; this._version = 0; } this._serialNumber = this._sequence[seqStart + 1]._getValue(); this._signature = new _PdfAlgorithms(this._sequence[seqStart + 2]); this._issuer = new _PdfX509Name(this._sequence[seqStart + 3]._getSequence()); var dates = this._sequence[seqStart + 4]._getSequence(); this._startDate = new _PdfX509Time(dates[0]); this._endDate = new _PdfX509Time(dates[1]); this._subject = new _PdfX509Name(this._sequence[seqStart + 5]._getSequence()); this._publicKeyInformation = new _PdfPublicKeyInformation()._getPublicKeyInformation(this._sequence[seqStart + 6]); var base = seqStart + 6; for (var i = this._sequence.length - 1; i > base; i--) { var extra = this._sequence[i]; var derString = new _PdfUniqueBitString(); switch (extra._getTagNumber()) { case 1: this._issuerID = derString._getUniqueBitStringFromTag(extra, false); break; case 2: this._subjectID = derString._getUniqueBitStringFromTag(extra, false); break; case 3: this._extensions = new _PdfX509Extensions()._getInstance(extra); break; } } } /** * Get the human-readable certificate version (1,2,3...). * * @private * @returns {number} The certificate version number. */ _PdfSignedCertificate.prototype._getVersion = function () { return this._version + 1; }; /** * Return the DER-encoded bytes that represent this entire certificate. * * @private * @returns {Uint8Array} DER-encoded certificate bytes. */ _PdfSignedCertificate.prototype._getDistinguishEncoded = function () { var der = new _PdfUniqueEncodingElement(); der._tagClass = _TagClassType.universal; der._construction = _ConstructionType.constructed; der._setTagNumber(_UniversalType.sequence); der._setSequence(this._sequence); return der._toBytes(); }; return _PdfSignedCertificate; }()); export { _PdfSignedCertificate };