This commit is contained in:
Ryan Dahl 2010-11-30 15:59:59 -08:00
parent e15e214747
commit 09157369b3

View File

@ -3600,6 +3600,10 @@ try {
function Credentials (method) { function Credentials (method) {
if (!(this instanceof Credentials)) {
return new Credentials(method);
}
if (!crypto) { if (!crypto) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('node.js not compiled with openssl crypto support.');
} }
@ -3615,28 +3619,34 @@ function Credentials (method) {
this.shouldVerify = false; this.shouldVerify = false;
} }
exports.Credentials = Credentials;
exports.createCredentials = function (cred) {
if (!cred) cred={}; exports.createCredentials = function (options) {
var c = new Credentials(cred.method); if (!options) options = {};
if (cred.key) c.context.setKey(cred.key); var c = new Credentials(options.method);
if (cred.cert) c.context.setCert(cred.cert);
if (cred.ca) { if (options.key) c.context.setKey(options.key);
if (options.cert) c.context.setCert(options.cert);
if (options.ca) {
c.shouldVerify = true; c.shouldVerify = true;
if ( (typeof(cred.ca) == 'object') && cred.ca.length ) { if ( (typeof(options.ca) == 'object') && options.ca.length ) {
for(var i = 0, len = cred.ca.length; i < len; i++) for (var i = 0, len = options.ca.length; i < len; i++) {
c.context.addCACert(cred.ca[i]); c.context.addCACert(options.ca[i]);
}
} else { } else {
c.context.addCACert(cred.ca); c.context.addCACert(options.ca);
} }
} else { } else {
for (var i = 0, len = RootCaCerts.length; i < len; i++) { for (var i = 0, len = RootCaCerts.length; i < len; i++) {
c.context.addCACert(RootCaCerts[i]); c.context.addCACert(RootCaCerts[i]);
} }
} }
return c; return c;
}; };
exports.Credentials = Credentials;
exports.Hash = Hash; exports.Hash = Hash;