define(["require", "exports", "./../asn1/enumerator", "../asn1/basic-encoding-element", "./x509-certificate", "./x509-certificate-structure"], function (require, exports, enumerator_1, basic_encoding_element_1, x509_certificate_1, x509_certificate_structure_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _PdfX509CertificateParser = (function () {
function _PdfX509CertificateParser() {
this._sDataObjectCount = 0;
}
_PdfX509CertificateParser.prototype._readDistinguishEncoderCertificate = function (bytes, isCertificateParsing) {
var structure = new x509_certificate_structure_1._PdfX509CertificateStructure();
var stream = new basic_encoding_element_1._PdfBasicEncodingElement();
stream._fromBytes(bytes);
var seq = stream._getSequence();
var tagNumber = seq[0]._getTagNumber();
if (seq.length > 1 && tagNumber === enumerator_1._UniversalType.objectIdentifier) {
var oid = seq[0]._getObjectIdentifier();
var dotDelimitedNotation = oid._getDotDelimitedNotation();
if (dotDelimitedNotation === '1.2.840.113549.1.7.2') {
if (seq.length >= 2) {
var inner = seq[1]._getInner();
var innerSequence = inner._getSequence();
var signedSequence = innerSequence;
for (var _i = 0, signedSequence_1 = signedSequence; _i < signedSequence_1.length; _i++) {
var element = signedSequence_1[_i];
if (element instanceof basic_encoding_element_1._PdfBasicEncodingElement && element._tagClass === enumerator_1._TagClassType.context
&& element._getTagNumber() === 0) {
var inner_1 = element._getInner(isCertificateParsing);
var innerSet = void 0;
if (isCertificateParsing) {
innerSet = inner_1._getSequence();
}
else {
innerSet = inner_1._getAbstractSetValue();
}
this._sData = innerSet;
break;
}
}
}
return this._getCertificate(isCertificateParsing);
}
}
return this._createX509Certificate(structure._getInstance(seq));
};
_PdfX509CertificateParser.prototype._getCertificate = function (isCertificateParsing) {
var structure = new x509_certificate_structure_1._PdfX509CertificateStructure();
if (this._sData) {
if (!isCertificateParsing) {
while (this._sDataObjectCount < this._sData.length) {
var obj = this._sData[this._sDataObjectCount++];
var tagNumber = obj._getTagNumber();
if (tagNumber === enumerator_1._UniversalType.sequence) {
return this._createX509Certificate(structure._getInstance(obj._getSequence()));
}
}
}
else {
return this._createX509Certificate(structure._getInstance(this._sData));
}
}
return null;
};
_PdfX509CertificateParser.prototype._createX509Certificate = function (structure) {
return new x509_certificate_1._PdfX509Certificate(structure);
};
_PdfX509CertificateParser.prototype._readCertificate = function (input, isCertificateParsing) {
if (isCertificateParsing === void 0) { isCertificateParsing = false; }
return this._readCertificateFromStream(input, isCertificateParsing);
};
_PdfX509CertificateParser.prototype._readCertificateFromStream = function (stream, isCertificateParsing) {
if (!stream || stream.length === 0) {
throw new Error('Input stream is empty or null');
}
if (this._currentStream !== stream) {
this._currentStream = stream;
this._sData = null;
this._sDataObjectCount = 0;
}
if (this._sData && this._sDataObjectCount < this._sData.length) {
return this._getCertificate();
}
var tag = stream[0];
if (tag < 0) {
return null;
}
return this._readDistinguishEncoderCertificate(stream, isCertificateParsing);
};
return _PdfX509CertificateParser;
}());
exports._PdfX509CertificateParser = _PdfX509CertificateParser;
});
|