Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 7x 5x 4x 77x 18x 14x 18x 17x 9x 1x 12x 1x 1x 5x 2x 1x 2x 22x 22x 22x 22x 12x 10x 22x 5x 15x 5x 5x 2x 9x 6x 3x 3x 5x 5x 7x 7x 1x 2x 2x 1x 1x | import { SecurityLevel } from "./cia";
/**
* Format security level string for display
*
* @param level - Security level to format
* @returns Formatted security level string
*/
export function formatSecurityLevel(level?: string): string {
if (!level) return "None";
// Handle special case for "Very High"
if (level.toUpperCase() === "VERY HIGH") return "Very High";
// First character uppercase, rest lowercase
return level.charAt(0).toUpperCase() + level.slice(1).toLowerCase();
}
/**
* Convert security level to numeric value
*
* @param level - Security level to convert
* @returns Numeric value (0-4)
*/
export function getSecurityLevelValue(level: SecurityLevel): number {
switch (level) {
case "None": return 0;
case "Low": return 1;
case "Moderate": return 2;
case "High": return 3;
case "Very High": return 4;
default: return 0;
}
}
/**
* Get security level based on numeric value
*
* @param value - Numeric value to convert
* @returns Corresponding security level
*/
export function getSecurityLevelFromValue(value: number): SecurityLevel {
switch (value) {
case 0: return "None";
case 1: return "Low";
case 2: return "Moderate";
case 3: return "High";
case 4: return "Very High";
default: return "None";
}
}
/**
* Calculate overall security level based on component levels
*
* ## Business Perspective
*
* This function provides organizations with a consolidated view of their
* security posture across all three components of the CIA triad.
* It helps in strategic decision-making and resource allocation. 💼
*
* @param availabilityLevel - Availability security level
* @param integrityLevel - Integrity security level
* @param confidentialityLevel - Confidentiality security level
* @returns Overall security level
*/
export function calculateOverallSecurityLevel(
availabilityLevel: SecurityLevel,
integrityLevel: SecurityLevel,
confidentialityLevel: SecurityLevel
): SecurityLevel {
// Convert levels to numeric values
const availValue = getSecurityLevelValue(availabilityLevel);
const integValue = getSecurityLevelValue(integrityLevel);
const confidValue = getSecurityLevelValue(confidentialityLevel);
// Special case: All levels are the same
if (availabilityLevel === integrityLevel && integrityLevel === confidentialityLevel) {
return availabilityLevel;
}
// Special case for mixed security levels that include "None"
const hasNone = availabilityLevel === "None" || integrityLevel === "None" || confidentialityLevel === "None";
if (hasNone) {
// Count how many "None" values we have
const noneCount = [availabilityLevel, integrityLevel, confidentialityLevel]
.filter(level => level === "None").length;
// If all are "None", return "None"
Iif (noneCount === 3) {
return "None";
}
// If majority are "None", return "None"
if (noneCount >= 2) {
return "None";
}
// If only one is "None", check the other two
// If both remaining levels are High or above, return Low (cap at Low)
// Otherwise, calculate the average of non-None values
const nonNoneValues = [availValue, integValue, confidValue].filter(val => val > 0);
const avgNonNoneValue = nonNoneValues.reduce((sum, val) => sum + val, 0) / nonNoneValues.length;
// Cap at Low if the average would be higher
Eif (avgNonNoneValue > 1) {
return "Low";
}
return "None";
}
// Calculate average and round it to nearest integer
const avgValue = Math.round((availValue + integValue + confidValue) / 3);
// Convert back to SecurityLevel
return getSecurityLevelFromValue(avgValue);
}
/**
* Calculate risk level based on security levels
*
* @param availabilityLevel - Availability security level
* @param integrityLevel - Integrity security level
* @param confidentialityLevel - Confidentiality security level
* @returns Risk level (Critical, High, Medium, Low, Minimal)
*/
export function calculateRiskLevel(
availabilityLevel: SecurityLevel,
integrityLevel: SecurityLevel,
confidentialityLevel: SecurityLevel
): string {
// Calculate overall security level first
const overallLevel = calculateOverallSecurityLevel(
availabilityLevel,
integrityLevel,
confidentialityLevel
);
// Map security levels to risk levels
switch (overallLevel) {
case "None": return "Critical";
case "Low": return "High";
case "Moderate": return "Medium";
case "High": return "Low";
case "Very High": return "Minimal";
default: return "Unknown";
}
}
|