all files / core/security/digital-signature/x509/ x509-extensions.js

29.51% Statements 18/61
0% Branches 0/25
33.33% Functions 4/12
29.51% Lines 18/61
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85                                                                                                                                      
define(["require", "exports", "../asn1/abstract-syntax", "../asn1/identifier-mapping"], function (require, exports, abstract_syntax_1, identifier_mapping_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfX509Extension = (function () {
        function _PdfX509Extension(critical, value) {
            this._value = value;
            this._critical = critical;
        }
        return _PdfX509Extension;
    }());
    exports._PdfX509Extension = _PdfX509Extension;
    var _PdfX509Extensions = (function () {
        function _PdfX509Extensions(extensions, ordering) {
            this._extensions = new Map();
            this._ordering = [];
            this._authorityKeyIdentifier = new identifier_mapping_1._PdfObjectIdentifier()._fromString('2.5.29.35');
            this._certificateRevocationListPoints = new identifier_mapping_1._PdfObjectIdentifier()._fromString('2.5.29.31');
            this._authorityInfoAccess = new identifier_mapping_1._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);
                    }
                }
            }
        }
        _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);
        };
        _PdfX509Extensions.prototype._getInstance = function (obj) {
            if (obj instanceof _PdfX509Extensions) {
                return obj;
            }
            else if (obj instanceof abstract_syntax_1._PdfAbstractSyntaxElement) {
                var extension = new _PdfX509Extensions();
                var sequence = obj._getSequence();
                return extension._fromSequence(sequence[0]._getSequence());
            }
            else {
                throw new Error('Unknown object in factory');
            }
        };
        _PdfX509Extensions.prototype._getExtension = function (objectIdentifier) {
            var key = objectIdentifier._encoding.toString().replace(/,/g, '.');
            var ext = this._extensions.get(key);
            return ext ? ext : null;
        };
        return _PdfX509Extensions;
    }());
    exports._PdfX509Extensions = _PdfX509Extensions;
    var _PdfX509ExtensionBase = (function () {
        function _PdfX509ExtensionBase() {
        }
        _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;
    }());
    exports._PdfX509ExtensionBase = _PdfX509ExtensionBase;
});