all files / core/security/digital-signature/ pdf-big-integer.js

26.09% Statements 12/46
0% Branches 0/14
20% Functions 2/10
27.27% Lines 12/44
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                                                                                                  
define(["require", "exports", "../../utils"], function (require, exports, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfBigInt = (function () {
        function _PdfBigInt(decimalStr) {
            if (decimalStr === void 0) { decimalStr = '0'; }
            this.digits = this._parseDecimalString(decimalStr);
        }
        _PdfBigInt.prototype._parseDecimalString = function (str) {
            return str.split('').reverse().map(function (d) { return parseInt(d, 10); });
        };
        _PdfBigInt.prototype._toString = function () {
            return this.digits.slice().reverse().join('').replace(/^0+/, '') || '0';
        };
        _PdfBigInt.prototype._toBigInt = function () {
            var str = this.digits.slice().reverse().join('').replace(/^0+/, '') || '0';
            var bigIntConstructor = utils_1._getBigInt();
            return bigIntConstructor(str);
        };
        _PdfBigInt.prototype._add = function (n) {
            var carry = n;
            for (var i = 0; i < this.digits.length || carry > 0; i++) {
                var sum = (this.digits[i] || 0) + carry;
                this.digits[i] = sum % 10;
                carry = Math.floor(sum / 10);
            }
        };
        _PdfBigInt.prototype._multiply = function () {
            var carry = 0;
            for (var i = 0; i < this.digits.length; i++) {
                var product = this.digits[i] * 256 + carry;
                this.digits[i] = product % 10;
                carry = Math.floor(product / 10);
            }
            while (carry > 0) {
                this.digits.push(carry % 10);
                carry = Math.floor(carry / 10);
            }
        };
        _PdfBigInt.prototype._bitLength = function () {
            var digits = this.digits.slice();
            var bits = 0;
            while (digits.length > 1 || digits[0] !== 0) {
                var carry = 0;
                for (var i = digits.length - 1; i >= 0; i--) {
                    var current = carry * 10 + digits[i];
                    digits[i] = Math.floor(current / 2);
                    carry = current % 2;
                }
                while (digits.length > 1 && digits[digits.length - 1] === 0) {
                    digits.pop();
                }
                bits++;
            }
            return bits;
        };
        return _PdfBigInt;
    }());
    exports._PdfBigInt = _PdfBigInt;
});