Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
miko37x committed May 28, 2024
1 parent a8f1b4c commit 7b7a350
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 309 deletions.
12 changes: 0 additions & 12 deletions lib/cvss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export function CVSS(cvss: string | CvssVectorObject) {
* @returns {string} returns one of the five possible ratings
*/
function getTemporalRating() {
if (!(util.getVersion(vector) === "3.0" || util.getVersion(vector) === "3.1"))
throw "This function is not supported for this cvss version";
return util.getRating(getTemporalScore());
}

Expand All @@ -64,8 +62,6 @@ export function CVSS(cvss: string | CvssVectorObject) {
* @returns {string} returns one of the five possible ratings
*/
function getEnvironmentalRating() {
if (!(util.getVersion(vector) === "3.0" || util.getVersion(vector) === "3.1"))
throw "This function is not supported for this cvss version";
return util.getRating(getEnvironmentalScore());
}

Expand Down Expand Up @@ -104,8 +100,6 @@ export function CVSS(cvss: string | CvssVectorObject) {
* @returns {number} Temporal Score
*/
function getTemporalScore() {
if (!(util.getVersion(vector) === "3.0" || util.getVersion(vector) === "3.1"))
throw "This function is not supported for this cvss version";
return score.getTemporalScore(vector);
}

Expand All @@ -116,8 +110,6 @@ export function CVSS(cvss: string | CvssVectorObject) {
* @returns {number} Environmental Score
*/
function getEnvironmentalScore() {
if (!(util.getVersion(vector) === "3.0" || util.getVersion(vector) === "3.1"))
throw "This function is not supported for this cvss version";
return score.getEnvironmentalScore(vector);
}

Expand Down Expand Up @@ -155,8 +147,6 @@ export function CVSS(cvss: string | CvssVectorObject) {
* @returns {number} Impact sub score
*/
function getImpactSubScore() {
if (!(util.getVersion(vector) === "3.0" || util.getVersion(vector) === "3.1"))
throw "This function is not supported for this cvss version";
return score.getImpactSubScore(vector);
}

Expand All @@ -170,8 +160,6 @@ export function CVSS(cvss: string | CvssVectorObject) {
* @returns {number} Exploitability sub score
*/
function getExploitabilitySubScore() {
if (!(util.getVersion(vector) === "3.0" || util.getVersion(vector) === "3.1"))
throw "This function is not supported for this cvss version";
return score.getExploitabilitySubScore(vector);
}

Expand Down
22 changes: 22 additions & 0 deletions lib/cvss_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Attack Vector",
abbr: "AV",
mandatory: true,
metrics: [
{ name: "Network", abbr: "N", numerical: 0.85 },
{ name: "Adjacent", abbr: "A", numerical: 0.62 },
Expand All @@ -16,6 +17,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Attack Complexity",
abbr: "AC",
mandatory: true,
metrics: [
{ name: "Low", abbr: "L", numerical: 0.77 },
{ name: "High", abbr: "H", numerical: 0.44 }
Expand All @@ -24,6 +26,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Privileges Required",
abbr: "PR",
mandatory: true,
metrics: [
{ name: "None", abbr: "N", numerical: { changed: 0.85, unchanged: 0.85 } },
{ name: "Low", abbr: "L", numerical: { changed: 0.68, unchanged: 0.62 } },
Expand All @@ -33,6 +36,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "User Interaction",
abbr: "UI",
mandatory: true,
metrics: [
{ name: "None", abbr: "N", numerical: 0.85 },
{ name: "Required", abbr: "R", numerical: 0.62 }
Expand All @@ -41,6 +45,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Scope",
abbr: "S",
mandatory: true,
metrics: [
{ name: "Unchanged", abbr: "U" },
{ name: "Changed", abbr: "C" }
Expand All @@ -49,6 +54,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Confidentiality",
abbr: "C",
mandatory: true,
metrics: [
{ name: "None", abbr: "N", numerical: 0 },
{ name: "Low", abbr: "L", numerical: 0.22 },
Expand All @@ -58,6 +64,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Integrity",
abbr: "I",
mandatory: true,
metrics: [
{ name: "None", abbr: "N", numerical: 0 },
{ name: "Low", abbr: "L", numerical: 0.22 },
Expand All @@ -67,6 +74,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Availability",
abbr: "A",
mandatory: true,
metrics: [
{ name: "None", abbr: "N", numerical: 0 },
{ name: "Low", abbr: "L", numerical: 0.22 },
Expand All @@ -76,6 +84,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Exploit Code Maturity",
abbr: "E",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "High", abbr: "H", numerical: 1 },
Expand All @@ -87,6 +96,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Remediation Level",
abbr: "RL",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "Unavailable", abbr: "U", numerical: 1 },
Expand All @@ -98,6 +108,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Report Confidence",
abbr: "RC",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "Confirmed", abbr: "C", numerical: 1 },
Expand All @@ -108,6 +119,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Confidentiality Req.",
abbr: "CR",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "High", abbr: "H", numerical: 1.5 },
Expand All @@ -118,6 +130,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Integrity Req.",
abbr: "IR",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "High", abbr: "H", numerical: 1.5 },
Expand All @@ -128,6 +141,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Availability Req.",
abbr: "AR",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "High", abbr: "H", numerical: 1.5 },
Expand All @@ -138,6 +152,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Attack Vector",
abbr: "MAV",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "Network", abbr: "N", numerical: 0.85 },
Expand All @@ -149,6 +164,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Attack Complexity",
abbr: "MAC",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "Low", abbr: "L", numerical: 0.77 },
Expand All @@ -158,6 +174,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Privileges Required",
abbr: "MPR",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: { changed: 1, unchanged: 1 } },
{ name: "None", abbr: "N", numerical: { changed: 0.85, unchanged: 0.85 } },
Expand All @@ -168,6 +185,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified User Interaction",
abbr: "MUI",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "None", abbr: "N", numerical: 0.85 },
Expand All @@ -177,6 +195,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Scope",
abbr: "MS",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X" },
{ name: "Unchanged", abbr: "U" },
Expand All @@ -186,6 +205,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Confidentiality",
abbr: "MC",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "None", abbr: "N", numerical: 0 },
Expand All @@ -196,6 +216,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Integrity",
abbr: "MI",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "None", abbr: "N", numerical: 0 },
Expand All @@ -206,6 +227,7 @@ export const definitions: CvssVersionDefinition = {
{
name: "Modified Availability",
abbr: "MA",
mandatory: false,
metrics: [
{ name: "Not Defined", abbr: "X", numerical: 1 },
{ name: "None", abbr: "N", numerical: 0 },
Expand Down
Loading

0 comments on commit 7b7a350

Please sign in to comment.