all files / core/security/digital-signature/x509/ x509-bit-string-handler.js

27.08% Statements 13/48
0% Branches 0/24
20% Functions 2/10
27.08% Lines 13/48
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                                                                                                                      
define(["require", "exports", "../asn1/enumerator", "../asn1/unique-encoding-element"], function (require, exports, enumerator_1, unique_encoding_element_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfUniqueBitString = (function () {
        function _PdfUniqueBitString(data, pad) {
            this._data = new Uint8Array(0);
            this._extraBits = 0;
            this._table = [
                '0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
            ];
            if (data && data.length > 0) {
                this._data = data;
                this._extraBits = typeof pad === 'number' ? pad : 0;
            }
        }
        _PdfUniqueBitString.prototype._fromAbstractSyntaxOctets = function (bytes) {
            return new _PdfUniqueBitString(bytes.subarray(1), bytes[0]);
        };
        _PdfUniqueBitString.prototype._getBytes = function () {
            return this._data;
        };
        _PdfUniqueBitString.prototype._getUniqueEncoded = function () {
            var output = new Uint8Array(this._data.length + 1);
            output[0] = this._extraBits;
            output.set(this._data, 1);
            return output;
        };
        _PdfUniqueBitString.prototype._equals = function (other) {
            if (!(other instanceof _PdfUniqueBitString)) {
                return false;
            }
            if (this._extraBits !== other._extraBits) {
                return false;
            }
            if (this._data.length !== other._data.length) {
                return false;
            }
            for (var i = 0; i < this._data.length; i++) {
                if (this._data[i] !== other._data[i]) {
                    return false;
                }
            }
            return true;
        };
        _PdfUniqueBitString.prototype._getUniqueBitStringFromTag = function (tag, isExplicit) {
            var asn1 = tag._getInner();
            var derString = new _PdfUniqueBitString();
            if (isExplicit || asn1 instanceof _PdfUniqueBitString) {
                return derString._getUniqueBitString(asn1);
            }
            return derString._fromAbstractSyntaxOctets(asn1._getOctetString());
        };
        _PdfUniqueBitString.prototype._getUniqueBitString = function (obj) {
            if (obj === null || typeof obj === 'undefined') {
                return null;
            }
            if (obj instanceof _PdfUniqueBitString) {
                return obj;
            }
            throw new Error('Invalid Entry');
        };
        _PdfUniqueBitString.prototype._getAbstractSyntax = function () {
            var element = new unique_encoding_element_1._PdfUniqueEncodingElement(enumerator_1._TagClassType.universal, enumerator_1._ConstructionType.primitive, enumerator_1._UniversalType.bitString);
            element._setValue(this._getUniqueEncoded());
            return element;
        };
        return _PdfUniqueBitString;
    }());
    exports._PdfUniqueBitString = _PdfUniqueBitString;
});