From 09157369b30da939a9096aa50514fe4441dbc489 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 30 Nov 2010 15:59:59 -0800 Subject: [PATCH] style --- lib/crypto.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/crypto.js b/lib/crypto.js index fe5e712d9b..9eb2e37380 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -3600,8 +3600,12 @@ try { function Credentials (method) { + if (!(this instanceof Credentials)) { + return new Credentials(method); + } + if (!crypto) { - throw new Error('node.js not compiled with openssl crypto support.'); + throw new Error('node.js not compiled with openssl crypto support.'); } this.context = new SecureContext(); @@ -3615,28 +3619,34 @@ function Credentials (method) { this.shouldVerify = false; } +exports.Credentials = Credentials; + + +exports.createCredentials = function (options) { + if (!options) options = {}; + var c = new Credentials(options.method); -exports.createCredentials = function (cred) { - if (!cred) cred={}; - var c = new Credentials(cred.method); - if (cred.key) c.context.setKey(cred.key); - 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; - if ( (typeof(cred.ca) == 'object') && cred.ca.length ) { - for(var i = 0, len = cred.ca.length; i < len; i++) - c.context.addCACert(cred.ca[i]); + if ( (typeof(options.ca) == 'object') && options.ca.length ) { + for (var i = 0, len = options.ca.length; i < len; i++) { + c.context.addCACert(options.ca[i]); + } } else { - c.context.addCACert(cred.ca); + c.context.addCACert(options.ca); } } else { for (var i = 0, len = RootCaCerts.length; i < len; i++) { c.context.addCACert(RootCaCerts[i]); } } + return c; }; -exports.Credentials = Credentials; exports.Hash = Hash;