Initial curated CertScope source from fe2bbe3ca5c98bf64be26a09c6c58ee805a7f87e

This commit is contained in:
Public Source Publisher committed 2026-10-01 01:30:09 +02:00
commit 7348faf6c0
65 files changed
+12509

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import type { Category, Finding, InspectionScore } from "./types";
const CATEGORY_ORDER: Category[] = ["dns", "tls", "http"];
function clamp(value: number) {
return Math.max(0, Math.min(100, Math.round(value)));
}
/**
* Scores are calculated per category first, then averaged equally. This keeps
* one category's findings from being charged again against the global score.
*/
export function score(findings: Finding[]): InspectionScore {
const categories: Record<Category, number> = { dns: 100, tls: 100, http: 100 };
for (const finding of findings) {
const impact = Number.isFinite(finding.scoreImpact) ? Math.min(0, finding.scoreImpact) : 0;
categories[finding.category] = clamp(categories[finding.category] + impact);
}
const overall = clamp(CATEGORY_ORDER.reduce((sum, category) => sum + categories[category], 0) / CATEGORY_ORDER.length);
return { overall, deductions: 100 - overall, categories };
}