@@ -3600,8 +3600,12 @@ try {
3600
3600
3601
3601
3602
3602
function Credentials ( method ) {
3603
+ if ( ! ( this instanceof Credentials ) ) {
3604
+ return new Credentials ( method ) ;
3605
+ }
3606
+
3603
3607
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.' ) ;
3605
3609
}
3606
3610
3607
3611
this . context = new SecureContext ( ) ;
@@ -3615,28 +3619,34 @@ function Credentials (method) {
3615
3619
this . shouldVerify = false ;
3616
3620
}
3617
3621
3622
+ exports . Credentials = Credentials ;
3623
+
3624
+
3625
+ exports . createCredentials = function ( options ) {
3626
+ if ( ! options ) options = { } ;
3627
+ var c = new Credentials ( options . method ) ;
3618
3628
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 ) {
3625
3634
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
+ }
3629
3639
} else {
3630
- c . context . addCACert ( cred . ca ) ;
3640
+ c . context . addCACert ( options . ca ) ;
3631
3641
}
3632
3642
} else {
3633
3643
for ( var i = 0 , len = RootCaCerts . length ; i < len ; i ++ ) {
3634
3644
c . context . addCACert ( RootCaCerts [ i ] ) ;
3635
3645
}
3636
3646
}
3647
+
3637
3648
return c ;
3638
3649
} ;
3639
- exports . Credentials = Credentials ;
3640
3650
3641
3651
3642
3652
exports . Hash = Hash ;
0 commit comments