@@ -36,11 +36,11 @@ export const extractExpirationDate = (certData: string): Date | null => {
3636 }
3737
3838 // Skip the outer certificate sequence
39- if ( der [ offset ++ ] !== 0x30 ) throw new Error ( "Expected sequence" ) ;
39+ if ( der [ offset ++ ] !== 0x30 ) return null ;
4040 ( { offset } = readLength ( offset ) ) ;
4141
4242 // Skip tbsCertificate sequence
43- if ( der [ offset ++ ] !== 0x30 ) throw new Error ( "Expected tbsCertificate" ) ;
43+ if ( der [ offset ++ ] !== 0x30 ) return null ;
4444 ( { offset } = readLength ( offset ) ) ;
4545
4646 // Check for optional version field (context-specific tag [0])
@@ -52,15 +52,14 @@ export const extractExpirationDate = (certData: string): Date | null => {
5252
5353 // Skip serialNumber, signature, issuer
5454 for ( let i = 0 ; i < 3 ; i ++ ) {
55- if ( der [ offset ] !== 0x30 && der [ offset ] !== 0x02 )
56- throw new Error ( "Unexpected structure" ) ;
55+ if ( der [ offset ] !== 0x30 && der [ offset ] !== 0x02 ) return null ;
5756 offset ++ ;
5857 const fieldLen = readLength ( offset ) ;
5958 offset = fieldLen . offset + fieldLen . length ;
6059 }
6160
6261 // Validity sequence (notBefore and notAfter)
63- if ( der [ offset ++ ] !== 0x30 ) throw new Error ( "Expected validity sequence" ) ;
62+ if ( der [ offset ++ ] !== 0x30 ) return null ;
6463 const validityLen = readLength ( offset ) ;
6564 offset = validityLen . offset ;
6665
@@ -138,11 +137,11 @@ export const extractCommonName = (certData: string): string | null => {
138137 }
139138
140139 // Skip the outer certificate sequence
141- if ( der [ offset ++ ] !== 0x30 ) throw new Error ( "Expected sequence" ) ;
140+ if ( der [ offset ++ ] !== 0x30 ) return null ;
142141 ( { offset } = readLength ( offset ) ) ;
143142
144143 // Skip tbsCertificate sequence
145- if ( der [ offset ++ ] !== 0x30 ) throw new Error ( "Expected tbsCertificate" ) ;
144+ if ( der [ offset ++ ] !== 0x30 ) return null ;
146145 ( { offset } = readLength ( offset ) ) ;
147146
148147 // Check for optional version field (context-specific tag [0])
@@ -165,7 +164,7 @@ export const extractCommonName = (certData: string): string | null => {
165164 offset = skipField ( offset ) ;
166165
167166 // Subject sequence - where we find the CN
168- if ( der [ offset ++ ] !== 0x30 ) throw new Error ( "Expected subject sequence" ) ;
167+ if ( der [ offset ++ ] !== 0x30 ) return null ;
169168 const subjectLen = readLength ( offset ) ;
170169 const subjectEnd = subjectLen . offset + subjectLen . length ;
171170 offset = subjectLen . offset ;
0 commit comments