@@ -145,6 +145,7 @@ interface SignatureParameters {
145145interface CustomError {
146146 message : string
147147 errors ?: any [ ]
148+ error ?: string
148149 signatureOid ?: string
149150 oid ?: string
150151 name ?: string
@@ -832,7 +833,7 @@ interface IMessageDigest {
832833 algorithm : string
833834 update : ( msg : string | ByteStringBuffer , encoding ?: string ) => IMessageDigest
834835 digest : ( ) => ByteStringBuffer
835- create : ( ) => IMessageDigest
836+ create ? : ( ) => IMessageDigest
836837}
837838
838839interface HashFunction {
@@ -1221,6 +1222,15 @@ export function createCertificate(): Certificate {
12211222 }
12221223 return false
12231224 } ,
1225+ getExtension : function ( name : string ) {
1226+ for ( let i = 0 ; i < cert . extensions . length ; ++ i ) {
1227+ const ext = cert . extensions [ i ]
1228+ if ( ext . name === name || ext . id === name ) {
1229+ return ext
1230+ }
1231+ }
1232+ return null
1233+ }
12241234 }
12251235
12261236 return cert
@@ -1733,7 +1743,7 @@ export function createCertificationRequest(): CertificationRequest {
17331743 getAttribute : function ( sn : string ) {
17341744 return _getAttribute ( csr , sn )
17351745 } ,
1736- addAttribute : function ( attr : Attribute ) {
1746+ addAttribute : function ( attr ) {
17371747 _fillMissingFields ( [ attr ] )
17381748 csr . attributes . push ( attr )
17391749 } ,
@@ -1817,7 +1827,7 @@ export function createCertificationRequest(): CertificationRequest {
18171827 let md = csr . md
18181828 if ( md === null ) {
18191829 md = _createSignatureDigest ( {
1820- signatureOid : csr . signatureOid ,
1830+ signatureOid : csr . signatureOid || '' ,
18211831 type : 'certification request' ,
18221832 } )
18231833
@@ -2351,12 +2361,12 @@ function _fillMissingExtensionFields(e: CertificateExtension, options: any = {})
23512361 * @param params The signature parametrs object
23522362 * @return ASN.1 object representing signature parameters
23532363 */
2354- function _signatureParametersToAsn1 ( oid : string , params : SignatureParameters ) {
2364+ function _signatureParametersToAsn1 ( oid : string , params ? : SignatureParameters ) {
23552365 switch ( oid ) {
23562366 case oids [ 'RSASSA-PSS' ] :
23572367 const parts = [ ]
23582368
2359- if ( params . hash ?. algorithmOid !== undefined ) {
2369+ if ( params ? .hash ?. algorithmOid !== undefined ) {
23602370 parts . push ( asn1 . create ( asn1 . Class . CONTEXT_SPECIFIC , 0 , true , [
23612371 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [
23622372 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( params . hash . algorithmOid ) . getBytes ( ) ) ,
@@ -2365,7 +2375,7 @@ function _signatureParametersToAsn1(oid: string, params: SignatureParameters) {
23652375 ] ) )
23662376 }
23672377
2368- if ( params . mgf ?. algorithmOid !== undefined ) {
2378+ if ( params ? .mgf ?. algorithmOid !== undefined ) {
23692379 parts . push ( asn1 . create ( asn1 . Class . CONTEXT_SPECIFIC , 1 , true , [
23702380 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [
23712381 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( params . mgf . algorithmOid ) . getBytes ( ) ) ,
@@ -2377,7 +2387,7 @@ function _signatureParametersToAsn1(oid: string, params: SignatureParameters) {
23772387 ] ) )
23782388 }
23792389
2380- if ( params . saltLength !== undefined ) {
2390+ if ( params ? .saltLength !== undefined ) {
23812391 parts . push ( asn1 . create ( asn1 . Class . CONTEXT_SPECIFIC , 2 , true , [
23822392 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . INTEGER , false , asn1 . integerToDer ( params . saltLength ) . getBytes ( ) ) ,
23832393 ] ) )
@@ -2560,7 +2570,7 @@ export function getTBSCertificate(cert: Certificate): any {
25602570 *
25612571 * @return the asn1 CertificationRequestInfo.
25622572 */
2563- export function getCertificationRequestInfo ( csr : CertificationRequest ) {
2573+ export function getCertificationRequestInfo ( csr : CertificationRequest ) : Asn1Object {
25642574 // CertificationRequestInfo
25652575 const cri = asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [
25662576 // version
@@ -2605,9 +2615,9 @@ export function certificateToAsn1(cert: Certificate): Asn1Object {
26052615 // AlgorithmIdentifier (signature algorithm)
26062616 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [
26072617 // algorithm
2608- asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( cert . signatureOid ) . getBytes ( ) ) ,
2618+ asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( cert . signatureOid || '' ) . getBytes ( ) ) ,
26092619 // parameters
2610- _signatureParametersToAsn1 ( cert . signatureOid , cert . signatureParameters ) ,
2620+ _signatureParametersToAsn1 ( cert . signatureOid || '' , cert . signatureParameters ) ,
26112621 ] ) ,
26122622 // SignatureValue
26132623 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . BITSTRING , false , String . fromCharCode ( 0x00 ) + cert . signature ) ,
@@ -2701,9 +2711,9 @@ export function certificationRequestToAsn1(csr: CertificationRequest): Asn1Objec
27012711 // AlgorithmIdentifier (signature algorithm)
27022712 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . SEQUENCE , true , [
27032713 // algorithm
2704- asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( csr . signatureOid ) . getBytes ( ) ) ,
2714+ asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . OID , false , asn1 . oidToDer ( csr . signatureOid || '' ) . getBytes ( ) ) ,
27052715 // parameters
2706- _signatureParametersToAsn1 ( csr . signatureOid , csr . signatureParameters ) ,
2716+ _signatureParametersToAsn1 ( csr . signatureOid || '' , csr . signatureParameters ) ,
27072717 ] ) ,
27082718 // signature
27092719 asn1 . create ( asn1 . Class . UNIVERSAL , asn1 . Type . BITSTRING , false , String . fromCharCode ( 0x00 ) + csr . signature ) ,
@@ -2713,8 +2723,7 @@ export function certificationRequestToAsn1(csr: CertificationRequest): Asn1Objec
27132723/**
27142724 * Creates a CA store.
27152725 *
2716- * @param certs an optional array of certificate objects or PEM-formatted
2717- * certificate strings to add to the CA store.
2726+ * @param certs an optional array of certificate objects or PEM-formatted certificate strings to add to the CA store.
27182727 *
27192728 * @return the CA store.
27202729 */
0 commit comments