all files / core/security/digital-signature/signature/ signature-utilities.js

10.59% Statements 9/85
0% Branches 0/14
28.57% Functions 2/7
10.59% Lines 9/85
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102                                                                                                                                                                                          
define(["require", "exports", "./pdf-cipher-signer", "./pdf-object-identifiers"], function (require, exports, pdf_cipher_signer_1, pdf_object_identifiers_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfSignerUtilities = (function () {
        function _PdfSignerUtilities() {
            this._algorithms = new Map();
            this._objectIdentifiers = new Map();
            this._initializeAlgorithmMappings();
            this._initializeObjectIdentifierMappings();
        }
        _PdfSignerUtilities.prototype._initializeAlgorithmMappings = function () {
            var algorithmIdentifiers = new pdf_object_identifiers_1._NistObjectIdentifiers();
            var identifiers = new pdf_object_identifiers_1._PdfCryptographicObjectIdentifier();
            this._algorithms.set('MD2WITHRSA', 'MD2withRSA');
            this._algorithms.set('MD2WITHRSAENCRYPTION', 'MD2withRSA');
            this._algorithms.set(identifiers._messageDigest2WithRonCipherEncryption.id, 'MD2withRSA');
            this._algorithms.set(identifiers._raceEvaluationEncryption.id, 'RSA');
            this._algorithms.set('SHA1WITHRSA', 'SHA-1withRSA');
            this._algorithms.set('SHA1WITHRSAENCRYPTION', 'SHA-1withRSA');
            this._algorithms.set(identifiers._secureHash1WithRonCipherEncryption.id, 'SHA-1withRSA');
            this._algorithms.set('SHA-1WITHRSA', 'SHA-1withRSA');
            this._algorithms.set('SHA256WITHRSA', 'SHA-256withRSA');
            this._algorithms.set('SHA256WITHRSAENCRYPTION', 'SHA-256withRSA');
            this._algorithms.set(identifiers._secureHash256WithRonCipherEncryption.id, 'SHA-256withRSA');
            this._algorithms.set('SHA-256WITHRSA', 'SHA-256withRSA');
            this._algorithms.set('SHA384WITHRSA', 'SHA-384withRSA');
            this._algorithms.set('SHA384WITHRSAENCRYPTION', 'SHA-384withRSA');
            this._algorithms.set(identifiers._secureHash384WithRonCipherEncryption.id, 'SHA-384withRSA');
            this._algorithms.set('SHA-384WITHRSA', 'SHA-384withRSA');
            this._algorithms.set('SHA512WITHRSA', 'SHA-512withRSA');
            this._algorithms.set('SHA-512WITHRSA', 'SHA-512withRSA');
            this._algorithms.set(identifiers._secureHash512WithRonCipherEncryption.id, 'SHA-512withRSA');
            this._algorithms.set('SHA1WITHRSAANDMGF1', 'SHA-1withRSAandMGF1');
            this._algorithms.set('SHA-1WITHRSAANDMGF1', 'SHA-1withRSAandMGF1');
            this._algorithms.set('SHA1WITHRSA/PSS', 'SHA-1withRSAandMGF1');
            this._algorithms.set('SHA-1WITHRSA/PSS', 'SHA-1withRSAandMGF1');
            this._algorithms.set('SHA256WITHRSAANDMGF1', 'SHA-256withRSAandMGF1');
            this._algorithms.set('SHA-256WITHRSAANDMGF1', 'SHA-256withRSAandMGF1');
            this._algorithms.set('SHA256WITHRSA/PSS', 'SHA-256withRSAandMGF1');
            this._algorithms.set('SHA-256WITHRSA/PSS', 'SHA-256withRSAandMGF1');
            this._algorithms.set('SHA384WITHRSAANDMGF1', 'SHA-384withRSAandMGF1');
            this._algorithms.set('SHA-384WITHRSAANDMGF1', 'SHA-384withRSAandMGF1');
            this._algorithms.set('SHA384WITHRSA/PSS', 'SHA-384withRSAandMGF1');
            this._algorithms.set('SHA-384WITHRSA/PSS', 'SHA-384withRSAandMGF1');
            this._algorithms.set('SHA512WITHRSAANDMGF1', 'SHA-512withRSAandMGF1');
            this._algorithms.set('SHA-512WITHRSAANDMGF1', 'SHA-512withRSAandMGF1');
            this._algorithms.set('SHA512WITHRSA/PSS', 'SHA-512withRSAandMGF1');
            this._algorithms.set('SHA-512WITHRSA/PSS', 'SHA-512withRSAandMGF1');
            this._algorithms.set('DSAWITHSHA256', 'SHA-256withDSA');
            this._algorithms.set('DSAWITHSHA-256', 'SHA-256withDSA');
            this._algorithms.set('SHA256/DSA', 'SHA-256withDSA');
            this._algorithms.set('SHA-256/DSA', 'SHA-256withDSA');
            this._algorithms.set('SHA256WITHDSA', 'SHA-256withDSA');
            this._algorithms.set('SHA-256WITHDSA', 'SHA-256withDSA');
            this._algorithms.set(algorithmIdentifiers._digitalSignatureWithSecureHash256AlgorithmIdentifier.id, 'SHA-256withDSA');
            this._algorithms.set('RIPEMD160WITHRSA', 'RIPEMD160withRSA');
            this._algorithms.set('RIPEMD160WITHRSAENCRYPTION', 'RIPEMD160withRSA');
            this._algorithms.set(algorithmIdentifiers._ronCipherWithRaceEvaluationAlgorithmIdentifier.id, 'RIPEMD160withRSA');
        };
        _PdfSignerUtilities.prototype._initializeObjectIdentifierMappings = function () {
            var algorithmIdentifiers = new pdf_object_identifiers_1._NistObjectIdentifiers();
            var identifiers = new pdf_object_identifiers_1._PdfCryptographicObjectIdentifier();
            this._objectIdentifiers.set('SHA-1withRSA', identifiers._secureHash1WithRonCipherEncryption);
            this._objectIdentifiers.set('SHA-256withRSA', identifiers._secureHash1WithRonCipherEncryption);
            this._objectIdentifiers.set('SHA-384withRSA', identifiers._secureHash256WithRonCipherEncryption);
            this._objectIdentifiers.set('SHA-512withRSA', identifiers._secureHash512WithRonCipherEncryption);
            this._objectIdentifiers.set('RIPEMD160withRSA', algorithmIdentifiers._ronCipherWithRaceEvaluationAlgorithmIdentifier.id);
        };
        _PdfSignerUtilities.prototype._getSigner = function (algorithm) {
            var lower = algorithm.toLowerCase();
            var mechanism = algorithm;
            var found = false;
            this._algorithms.forEach(function (value, key) {
                if (!found && key.toLowerCase() === lower) {
                    mechanism = value;
                    found = true;
                }
            });
            if (mechanism === 'SHA-1withRSA') {
                return new pdf_cipher_signer_1._PdfRmdSigner('sha1');
            }
            else if (mechanism === 'SHA-256withRSA') {
                return new pdf_cipher_signer_1._PdfRmdSigner('sha256');
            }
            else if (mechanism === 'SHA-384withRSA') {
                return new pdf_cipher_signer_1._PdfRmdSigner('sha384');
            }
            else if (mechanism === 'SHA-512withRSA') {
                return new pdf_cipher_signer_1._PdfRmdSigner('sha512');
            }
            else if (mechanism === 'RIPEMD160withRSA') {
                return new pdf_cipher_signer_1._PdfRmdSigner('md5');
            }
            else {
                throw new Error("Signer " + algorithm + " not recognised.");
            }
        };
        return _PdfSignerUtilities;
    }());
    exports._PdfSignerUtilities = _PdfSignerUtilities;
});