@@ -202,40 +202,36 @@ function getCACertificatesAsStrings(type = 'default') {
202202}
203203
204204function getCACertificates ( options = undefined ) {
205- if ( typeof options === 'string' || options === undefined ) {
206- return getCACertificatesAsStrings ( options ) ;
207- }
205+ let type = 'default' ;
206+ let format = 'pem' ;
208207
209208 if ( typeof options === 'object' && options !== null ) {
210- const {
211- type = 'default' ,
212- format = 'pem' ,
213- } = options ;
214-
215- validateString ( type , 'type' ) ;
216- validateOneOf ( format , 'format' , [ 'pem' , 'der' , 'x509' , 'string' , 'buffer' ] ) ;
209+ ( { type = 'default' , format = 'pem' } = options ) ;
210+ } else if ( typeof options === 'string' || options === undefined ) {
211+ type = options ?? 'default' ;
212+ } else {
213+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'string' , 'object' ] , options ) ;
214+ }
217215
218- const certs = getCACertificatesAsStrings ( type ) ;
216+ validateString ( type , 'type' ) ;
217+ validateOneOf ( format , 'format' , [ 'pem' , 'der' , 'x509' , 'string' , 'buffer' ] ) ;
219218
220- if ( format === 'x509' ) {
221- return certs . map ( ( cert ) => new X509Certificate ( cert ) ) ;
222- }
219+ const certs = getCACertificatesAsStrings ( type ) ;
223220
224- if ( format === 'pem' || format === 'string' ) {
225- return certs ;
226- }
227-
228- const buffers = certs . map ( ( cert ) => {
229- const base64 = cert . replace ( / (?: \s | - - - - - B E G I N C E R T I F I C A T E - - - - - | - - - - - E N D C E R T I F I C A T E - - - - - ) + / g, '' ) ;
230- return Buffer . from ( base64 , 'base64' ) ;
231- } ) ;
221+ if ( format === 'pem' || format === 'string' ) {
222+ return certs ;
223+ }
232224
233- if ( format === 'der' || format === 'buffer' ) {
234- return buffers ;
235- }
225+ if ( format === 'x509' ) {
226+ return certs . map ( ( cert ) => new X509Certificate ( cert ) ) ;
236227 }
237228
238- throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'string' , 'object' ] , options ) ;
229+ const buffers = certs . map ( ( cert ) => {
230+ const base64 = cert . replace ( / (?: \s | - - - - - B E G I N C E R T I F I C A T E - - - - - | - - - - - E N D C E R T I F I C A T E - - - - - ) + / g, '' ) ;
231+ return Buffer . from ( base64 , 'base64' ) ;
232+ } ) ;
233+
234+ return buffers ;
239235}
240236
241237exports . getCACertificates = getCACertificates ;
0 commit comments