Skip to content

Commit

Permalink
distinguish between version 3.0 and 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
miko37x committed May 21, 2024
1 parent 97750f0 commit a8f1b4c
Show file tree
Hide file tree
Showing 8 changed files with 758 additions and 1,020 deletions.
29 changes: 26 additions & 3 deletions lib/cvss.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CvssVectorObject } from "./types";
import { util } from "./util";
import { score } from "./score";
import { score as score3_0 } from "./score_3_0";
import { score as score4_0 } from "./score_4_0";

/**
* Creates a new CVSS object
Expand All @@ -9,7 +10,7 @@ import { score } from "./score";
*/
export function CVSS(cvss: string | CvssVectorObject) {
const vector = util.parseVectorObjectToString(cvss);

const score = util.getVersion(vector) === "4.0" ? score4_0 : score3_0;
/**
* Retrieves an object of vector's metrics
* Calls a function from util.js
Expand Down Expand Up @@ -44,19 +45,27 @@ export function CVSS(cvss: string | CvssVectorObject) {
* Calculates the Temporal Rating of the given vector
* Calls a function from util.js
*
* Only available for cvss 3.0 and 3.1
*
* @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());
}

/**
* Calculates the Environmental Rating of the given vector
* Calls a function from util.js
*
* Only available for cvss 3.0 and 3.1
*
* @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 @@ -90,19 +99,25 @@ export function CVSS(cvss: string | CvssVectorObject) {

/**
* Parses the vector to the temporal score
* Only available for cvss 3.0 and 3.1
*
* @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);
}

/**
* Parses the vector to the environmental score
* Only available for cvss 3.0 and 3.1
*
* @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 @@ -134,10 +149,14 @@ export function CVSS(cvss: string | CvssVectorObject) {
*
* Scope Unchanged 6.42 × ISCBase
* Scope Changed 7.52 × [ISCBase − 0.029] − 3.25 × [ISCBase - 0.02]15
* *
*
* Only available for cvss 3.0 and 3.1
*
* @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 @@ -146,9 +165,13 @@ export function CVSS(cvss: string | CvssVectorObject) {
*
* 8.22 x AttackVector x AttackComplexity x PrivilegeRequired x UserInteraction
*
* Only available for cvss 3.0 and 3.1
*
* @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
Loading

0 comments on commit a8f1b4c

Please sign in to comment.