@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
144 lines (143 loc) • 5.32 kB
JavaScript
import { _PdfAbstractSyntaxElement } from '../asn1/abstract-syntax';
import { _PdfObjectIdentifier } from '../asn1/identifier-mapping';
/**
* Represents a single X.509 extension (critical flag + value element).
*
* @private
*/
var _PdfX509Extension = /** @class */ (function () {
function _PdfX509Extension(critical, value) {
this._value = value;
this._critical = critical;
}
return _PdfX509Extension;
}());
export { _PdfX509Extension };
/**
* Collection helper for X.509 extensions with lookup and sequencing utilities.
*
* @private
*/
var _PdfX509Extensions = /** @class */ (function () {
function _PdfX509Extensions(extensions, ordering) {
this._extensions = new Map();
this._ordering = [];
/**
* OID for authorityKeyIdentifier extension.
*
* @private
* @type {_PdfObjectIdentifier}
*/
this._authorityKeyIdentifier = new _PdfObjectIdentifier()._fromString('2.5.29.35');
/**
* OID for certificateRevocationListPoints extension.
*
* @private
* @type {_PdfObjectIdentifier}
*/
this._certificateRevocationListPoints = new _PdfObjectIdentifier()._fromString('2.5.29.31');
/**
* OID for authorityInfoAccess extension.
*
* @private
* @type {_PdfObjectIdentifier}
*/
this._authorityInfoAccess = new _PdfObjectIdentifier()._fromString('1.3.6.1.5.5.7.1.1');
if (extensions || ordering) {
var orderingList_1 = [];
extensions.forEach(function (_extension, objectIdentifier) {
orderingList_1.push(objectIdentifier);
});
this._ordering = ordering != null ? ordering : orderingList_1;
for (var _i = 0, _a = this._ordering; _i < _a.length; _i++) {
var objectIdentifier = _a[_i];
var extension = extensions.get(objectIdentifier);
if (extension) {
this._extensions.set(objectIdentifier, extension);
}
}
}
}
/**
* Build extensions collection from an ASN.1 sequence of extension entries.
*
* @private
* @param {_PdfAbstractSyntaxElement[]} sequence - ASN.1 extension sequence elements.
* @returns {_PdfX509Extensions} Constructed extensions container.
*/
_PdfX509Extensions.prototype._fromSequence = function (sequence) {
var extensionsMap = new Map();
for (var _i = 0, sequence_1 = sequence; _i < sequence_1.length; _i++) {
var element = sequence_1[_i];
var innerSeq = element._getSequence();
if (!innerSeq || innerSeq.length < 2 || innerSeq.length > 3) {
throw new Error('Bad sequence size');
}
var oid = innerSeq[0]._getObjectIdentifier().toString();
var isCritical = innerSeq.length === 3 ? innerSeq[1]._getBooleanValue() : false;
var value = innerSeq[innerSeq.length - 1];
extensionsMap.set(oid, new _PdfX509Extension(isCritical, value));
}
return new _PdfX509Extensions(extensionsMap);
};
/**
* Normalize or construct a `_PdfX509Extensions` instance from various inputs.
*
* @private
* @param {any} obj - Candidate extensions container or ASN.1 element.
* @returns {_PdfX509Extensions} The resolved extensions instance.
*/
_PdfX509Extensions.prototype._getInstance = function (obj) {
if (obj instanceof _PdfX509Extensions) {
return obj;
}
else if (obj instanceof _PdfAbstractSyntaxElement) {
var extension = new _PdfX509Extensions();
var sequence = obj._getSequence();
return extension._fromSequence(sequence[0]._getSequence());
}
else {
throw new Error('Unknown object in factory');
}
};
/**
* Lookup an extension by object identifier.
*
* @private
* @param {_PdfObjectIdentifier} objectIdentifier - OID to search for.
* @returns {_PdfX509Extension|null} The extension or null when not present.
*/
_PdfX509Extensions.prototype._getExtension = function (objectIdentifier) {
var key = objectIdentifier._encoding.toString().replace(/,/g, '.');
var ext = this._extensions.get(key);
return ext ? ext : null;
};
return _PdfX509Extensions;
}());
export { _PdfX509Extensions };
/**
* Base class for objects that expose X.509 extensions retrieval.
*
* @private
*/
var _PdfX509ExtensionBase = /** @class */ (function () {
function _PdfX509ExtensionBase() {
}
/**
* Convenience helper to retrieve a raw extension ASN.1 element by OID.
*
* @private
* @param {_PdfObjectIdentifier} objectIdentifier - OID to lookup.
* @returns {_PdfAbstractSyntaxElement} The extension value element or null.
*/
_PdfX509ExtensionBase.prototype._getExtension = function (objectIdentifier) {
var exts = this._getExtensions();
if (exts) {
var ext = exts._getExtension(objectIdentifier);
return ext ? ext._value : null;
}
return null;
};
return _PdfX509ExtensionBase;
}());
export { _PdfX509ExtensionBase };