Skip to content

Commit 0915736

Browse files
committed
style
1 parent e15e214 commit 0915736

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

lib/crypto.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,8 +3600,12 @@ try {
36003600

36013601

36023602
function Credentials (method) {
3603+
if (!(this instanceof Credentials)) {
3604+
return new Credentials(method);
3605+
}
3606+
36033607
if (!crypto) {
3604-
throw new Error('node.js not compiled with openssl crypto support.');
3608+
throw new Error('node.js not compiled with openssl crypto support.');
36053609
}
36063610

36073611
this.context = new SecureContext();
@@ -3615,28 +3619,34 @@ function Credentials (method) {
36153619
this.shouldVerify = false;
36163620
}
36173621

3622+
exports.Credentials = Credentials;
3623+
3624+
3625+
exports.createCredentials = function (options) {
3626+
if (!options) options = {};
3627+
var c = new Credentials(options.method);
36183628

3619-
exports.createCredentials = function (cred) {
3620-
if (!cred) cred={};
3621-
var c = new Credentials(cred.method);
3622-
if (cred.key) c.context.setKey(cred.key);
3623-
if (cred.cert) c.context.setCert(cred.cert);
3624-
if (cred.ca) {
3629+
if (options.key) c.context.setKey(options.key);
3630+
3631+
if (options.cert) c.context.setCert(options.cert);
3632+
3633+
if (options.ca) {
36253634
c.shouldVerify = true;
3626-
if ( (typeof(cred.ca) == 'object') && cred.ca.length ) {
3627-
for(var i = 0, len = cred.ca.length; i < len; i++)
3628-
c.context.addCACert(cred.ca[i]);
3635+
if ( (typeof(options.ca) == 'object') && options.ca.length ) {
3636+
for (var i = 0, len = options.ca.length; i < len; i++) {
3637+
c.context.addCACert(options.ca[i]);
3638+
}
36293639
} else {
3630-
c.context.addCACert(cred.ca);
3640+
c.context.addCACert(options.ca);
36313641
}
36323642
} else {
36333643
for (var i = 0, len = RootCaCerts.length; i < len; i++) {
36343644
c.context.addCACert(RootCaCerts[i]);
36353645
}
36363646
}
3647+
36373648
return c;
36383649
};
3639-
exports.Credentials = Credentials;
36403650

36413651

36423652
exports.Hash = Hash;

0 commit comments

Comments
 (0)