Skip to content

Commit

Permalink
Fix splice usage pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
xltan committed Mar 7, 2024
1 parent ace03e1 commit e563353
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/CertificateChainValidationEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class CertificateChainValidationEngine {
}

// Now perform certificate verification checking
for (let i = 0; i < result.length; i++) {
for (let i = result.length - 1; i >= 0; i--) {
try {
const verificationResult = await certificate.verify(result[i], crypto);
if (verificationResult === false)
Expand Down Expand Up @@ -813,7 +813,7 @@ export class CertificateChainValidationEngine {
//#endregion

//#region Exclude certificate paths not ended with "trusted roots"
for (let i = 0; i < result.length; i++) {
for (let i = result.length - 1; i >= 0; i--) {
let found = false;

for (let j = 0; j < (result[i]).length; j++) {
Expand All @@ -832,7 +832,6 @@ export class CertificateChainValidationEngine {

if (!found) {
result.splice(i, 1);
i = 0;
}
}

Expand Down
28 changes: 15 additions & 13 deletions src/SignedCertificateTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,21 @@ export async function verifySCTsForCertificate(certificate: Certificate, issuerC
const stream = new bs.SeqStream();

//#region Remove certificate extension
for (let i = 0; certificate.extensions && i < certificate.extensions.length; i++) {
switch (certificate.extensions[i].extnID) {
case id_SignedCertificateTimestampList:
{
parsedValue = certificate.extensions[i].parsedValue;

if (!parsedValue || parsedValue.timestamps.length === 0)
throw new Error("Nothing to verify in the certificate");

certificate.extensions.splice(i, 1);
}
break;
default:
if (certificate.extensions) {
for (let i = certificate.extensions.length - 1; i >=0; i--) {
switch (certificate.extensions[i].extnID) {
case id_SignedCertificateTimestampList:
{
parsedValue = certificate.extensions[i].parsedValue;

if (!parsedValue || parsedValue.timestamps.length === 0)
throw new Error("Nothing to verify in the certificate");

certificate.extensions.splice(i, 1);
}
break;
default:
}
}
}
//#endregion
Expand Down

0 comments on commit e563353

Please sign in to comment.