all files / core/security/digital-signature/signature/ pdf-digest-handler.js

19.51% Statements 8/41
0% Branches 0/6
40% Functions 2/5
19.51% Lines 8/41
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                                                                                                    
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfDigestInformation = (function () {
        function _PdfDigestInformation(algorithm, digest) {
            this._algorithm = algorithm;
            this._digest = digest;
        }
        _PdfDigestInformation.prototype._getUniqueEncoded = function () {
            var algorithmBytes = this._algorithm._getEncoded();
            var digestBytes = this._digest;
            var algorithmLength = algorithmBytes.length;
            var digestLength = digestBytes.length;
            var contentLength = algorithmLength + digestLength + 1 + this._getLengthBytes(digestLength).length;
            var result = [];
            result.push(0x30);
            var lengthBytes = this._getLengthBytes(contentLength);
            if (lengthBytes.length === 1) {
                result.push(lengthBytes[0]);
            }
            else {
                result.push(0x80 | (lengthBytes.length - 1));
                for (var i = 1; i < lengthBytes.length; i++) {
                    result.push(lengthBytes[i]);
                }
            }
            result.push.apply(result, Array.from(algorithmBytes));
            result.push(0x04);
            var digestLengthBytes = this._getLengthBytes(digestLength);
            if (digestLengthBytes.length === 1) {
                result.push(digestLengthBytes[0]);
            }
            else {
                result.push(0x80 | (digestLengthBytes.length - 1));
                for (var i = 1; i < digestLengthBytes.length; i++) {
                    result.push(digestLengthBytes[i]);
                }
            }
            result.push.apply(result, Array.from(digestBytes));
            return new Uint8Array(result);
        };
        _PdfDigestInformation.prototype._getLengthBytes = function (length) {
            if (length < 128) {
                return [length];
            }
            var bytes = [];
            var tempLength = length;
            while (tempLength > 0) {
                bytes.unshift(tempLength & 0xFF);
                tempLength = Math.floor(tempLength / 256);
            }
            return [0x80 | bytes.length].concat(bytes);
        };
        return _PdfDigestInformation;
    }());
    exports._PdfDigestInformation = _PdfDigestInformation;
});