/* istanbul ignore next */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
define(["require", "exports", "../asn1/enumerator", "../asn1/basic-encoding-element", "../asn1/unique-encoding-element", "../asn1/identifier-mapping", "../asn1/utils", "./x509-cipher-handler", "./x509-extensions"], function (require, exports, enumerator_1, basic_encoding_element_1, unique_encoding_element_1, identifier_mapping_1, utils_1, x509_cipher_handler_1, x509_extensions_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _PdfX509Certificate = (function (_super) {
__extends(_PdfX509Certificate, _super);
function _PdfX509Certificate(certificate) {
var _this = _super.call(this) || this;
_this._keyUsage = [];
_this._structure = certificate;
var keyUsageOid = new identifier_mapping_1._PdfObjectIdentifier()._fromString('2.5.29.15');
var keyUsageExt = _this._getExtension(keyUsageOid);
if (keyUsageExt) {
var rawBytes = keyUsageExt._getValue();
var asn1Element = utils_1._isBasicEncodingElement(rawBytes)
? new basic_encoding_element_1._PdfBasicEncodingElement()
: new unique_encoding_element_1._PdfUniqueEncodingElement();
asn1Element._fromBytes(rawBytes);
var bitStringElement = asn1Element._construction === enumerator_1._ConstructionType.constructed
? asn1Element._getInner()
: asn1Element;
var bitBytes = bitStringElement._getValue();
var unusedBits = bitBytes[0];
var bits_1 = bitBytes.slice(1);
var length_1 = (bits_1.length * 8) - unusedBits;
_this._keyUsage = Array.from({ length: Math.max(9, length_1) }, function (value, i) {
return (bits_1[Math.floor(i / 8)] & (0x80 >> (i % 8))) !== 0;
});
}
else {
_this._keyUsage = null;
}
return _this;
}
_PdfX509Certificate.prototype._getExtensions = function () {
var signed = this._structure._getSignedCertificate();
return signed._getVersion() === 3 ? signed._extensions : new x509_extensions_1._PdfX509Extensions();
};
_PdfX509Certificate.prototype._getPublicKey = function () {
var signed = this._structure._getSignedCertificate();
return this._createKey(signed._publicKeyInformation);
};
_PdfX509Certificate.prototype._createKey = function (publicKeyInfo) {
var algOID = publicKeyInfo._algorithms._objectID.toString();
var publicKeyElement = new unique_encoding_element_1._PdfUniqueEncodingElement();
publicKeyElement._fromBytes(publicKeyInfo._publicKey._getBytes());
this._publicKeyBytes = publicKeyInfo._publicKey._data;
if (algOID === '1.2.840.113549.1.1.1') {
return this._parsePublicKey(publicKeyElement);
}
throw new Error('Unsupported Algorithm');
};
_PdfX509Certificate.prototype._parsePublicKey = function (publicKey) {
var seq = publicKey._getSequence();
if (!seq || seq.length < 2) {
throw new Error('Invalid RSA public key structure');
}
var modulus = seq[0]._getValue();
var exponent = seq[1]._getValue();
return new x509_cipher_handler_1._PdfRonCipherParameter(true, modulus, exponent);
};
_PdfX509Certificate.prototype._getTobeSignedCertificate = function () {
var signed = this._structure._getSignedCertificate();
return signed._getDistinguishEncoded();
};
_PdfX509Certificate.prototype._getEncoded = function () {
var asn1Element = this._structure._getDerEncoded();
return asn1Element;
};
_PdfX509Certificate.prototype._getEncodedString = function () {
return this._getEncoded();
};
return _PdfX509Certificate;
}(x509_extensions_1._PdfX509ExtensionBase));
exports._PdfX509Certificate = _PdfX509Certificate;
var _PdfX509Certificates = (function () {
function _PdfX509Certificates(certificates) {
this._hashValueSet = false;
this._certificate = certificates;
}
return _PdfX509Certificates;
}());
exports._PdfX509Certificates = _PdfX509Certificates;
});
|