• File: ClientSSLSecurityPFX.js
  • Full Path: /var/www/nodejs/callDir/node_modules/soap/lib/security/ClientSSLSecurityPFX.js
  • Date Modified: 06/03/2024 5:11 PM
  • File size: 1.49 KB
  • MIME-type: text/plain
  • Charset: utf-8
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientSSLSecurityPFX = void 0;
const fs = require("fs");
const https = require("https");
const _ = require("lodash");
/**
 * activates SSL for an already existing client using a PFX cert
 *
 * @module ClientSSLSecurityPFX
 * @param {Buffer|String}   pfx
 * @param {String}   passphrase
 * @constructor
 */
class ClientSSLSecurityPFX {
    constructor(pfx, passphrase, defaults) {
        if (typeof passphrase === 'object') {
            defaults = passphrase;
        }
        if (pfx) {
            if (Buffer.isBuffer(pfx)) {
                this.pfx = pfx;
            }
            else if (typeof pfx === 'string') {
                this.pfx = fs.readFileSync(pfx);
            }
            else {
                throw new Error('supplied pfx file should be a buffer or a file location');
            }
        }
        if (passphrase) {
            if (typeof passphrase === 'string') {
                this.passphrase = passphrase;
            }
        }
        this.defaults = {};
        _.merge(this.defaults, defaults);
    }
    toXML() {
        return '';
    }
    addOptions(options) {
        options.pfx = this.pfx;
        if (this.passphrase) {
            options.passphrase = this.passphrase;
        }
        _.merge(options, this.defaults);
        options.httpsAgent = new https.Agent(options);
    }
}
exports.ClientSSLSecurityPFX = ClientSSLSecurityPFX;
//# sourceMappingURL=ClientSSLSecurityPFX.js.map