var fs   = require('fs');
var q    = require('q');
var sysu = require('util');

var resolve = require('./resolve');

function loadCredentials(credentials) {

	// Prepare PKCS#12 data if available
	var pfxPromise = resolve(credentials.pfx || credentials.pfxData);

	// Prepare Certificate data if available.
	var certPromise = resolve(credentials.cert || credentials.certData);

	// Prepare Key data if available
	var keyPromise = resolve(credentials.key || credentials.keyData);

	// Prepare Certificate Authority data if available.
	var caPromises = [];
	if (credentials.ca != null && !sysu.isArray(credentials.ca)) {
		credentials.ca = [ credentials.ca ];
	}
	for(var i in credentials.ca) {
		var ca = credentials.ca[i];
		caPromises.push(resolve(ca));
	}
	if (caPromises.length == 0) {
		delete caPromises;
	}
	else {
		caPromises = q.all(caPromises);
	}

	return q.all([pfxPromise, certPromise, keyPromise, caPromises])
		.spread(function(pfx, cert, key, ca) {
			return { pfx: pfx, cert: cert, key: key, ca: ca };
	});
}

module.exports = loadCredentials;
var fs   = require('fs');
var q    = require('q');
var sysu = require('util');

var resolve = require('./resolve');

function loadCredentials(credentials) {

	// Prepare PKCS#12 data if available
	var pfxPromise = resolve(credentials.pfx || credentials.pfxData);

	// Prepare Certificate data if available.
	var certPromise = resolve(credentials.cert || credentials.certData);

	// Prepare Key data if available
	var keyPromise = resolve(credentials.key || credentials.keyData);

	// Prepare Certificate Authority data if available.
	var caPromises = [];
	if (credentials.ca != null && !sysu.isArray(credentials.ca)) {
		credentials.ca = [ credentials.ca ];
	}
	for(var i in credentials.ca) {
		var ca = credentials.ca[i];
		caPromises.push(resolve(ca));
	}
	if (caPromises.length == 0) {
		delete caPromises;
	}
	else {
		caPromises = q.all(caPromises);
	}

	return q.all([pfxPromise, certPromise, keyPromise, caPromises])
		.spread(function(pfx, cert, key, ca) {
			return { pfx: pfx, cert: cert, key: key, ca: ca, passphrase: credentials.passphrase };
	});
}

module.exports = loadCredentials;
Include passphrase for validation and connection
Include passphrase for validation and connection
