From b5bf40450de4d4aaf13225a9d245e33c8af7db70 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 7 Feb 2022 12:19:10 -0500 Subject: s/v2Scores/Scores/ --- cvss/v2scores.go | 32 ++++++++++++++++---------------- cvss/v2scores_test.go | 8 ++++---- cvss/v2vector.go | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'cvss') diff --git a/cvss/v2scores.go b/cvss/v2scores.go index 990b805..3100b19 100644 --- a/cvss/v2scores.go +++ b/cvss/v2scores.go @@ -4,43 +4,43 @@ import ( "math" ) -// CVSS v2 base, temporal, and environmental scores. -type v2Scores struct { - base Score // base score - temporal Score // temporal score - env Score // environmental score +// CVSS score set. +type Scores struct { + Base Score `json:"base"` // base score + Temporal Score `json:"temporal"` // temporal score + Env Score `json:"env"` // environmental score } -// Create new CVSS v2Scores from floats. -func newV2ScoresFromFloats(base, temporal, env float64) (v2Scores, error) { +// Create new score set from floats. +func NewScores(base, temporal, env float64) (Scores, error) { // convert base from float to Score baseScore, err := NewScore(base) if err != nil { - return v2Scores{}, err + return Scores{}, err } // convert temporal from float to Score tempScore, err := NewScore(temporal) if err != nil { - return v2Scores{}, err + return Scores{}, err } // convert env from float to Score envScore, err := NewScore(env) if err != nil { - return v2Scores{}, err + return Scores{}, err } // return success - return v2Scores { - base: baseScore, - temporal: tempScore, - env: envScore, + return Scores { + Base: baseScore, + Temporal: tempScore, + Env: envScore, }, nil } // Create new v2 scores from v2 vector. -func newV2Scores(v v2Vector) (v2Scores, error) { +func newScoresFromV2Vector(v v2Vector) (Scores, error) { // CVSS v2 (https://www.first.org/cvss/v2/guide 3.2.1) // // Impact = 10.41*(1-(1-ConfImpact)*(1-IntegImpact)*(1-AvailImpact)) @@ -262,5 +262,5 @@ func newV2Scores(v v2Vector) (v2Scores, error) { } // build and return result - return newV2ScoresFromFloats(baseScore, tempScore, envScore) + return NewScores(baseScore, tempScore, envScore) } diff --git a/cvss/v2scores_test.go b/cvss/v2scores_test.go index 0d6ab87..f35904c 100644 --- a/cvss/v2scores_test.go +++ b/cvss/v2scores_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -func TestNewV2ScoresFromFloats(t *testing.T) { +func TestNewScores(t *testing.T) { // test out of bound errors failTests := []struct { name string // test name @@ -23,7 +23,7 @@ func TestNewV2ScoresFromFloats(t *testing.T) { for _, test := range(failTests) { t.Run(test.name, func(t *testing.T) { - got, err := newV2ScoresFromFloats(test.vals[0], test.vals[1], test.vals[2]) + got, err := NewScores(test.vals[0], test.vals[1], test.vals[2]) if err == nil { t.Errorf("got %v, exp error", got) } @@ -31,7 +31,7 @@ func TestNewV2ScoresFromFloats(t *testing.T) { } } -func TestNewV2Scores(t *testing.T) { +func TestNewScoresFromV2Vector(t *testing.T) { // test vectors from section 3.3 passTests := []struct { name string // test name @@ -211,7 +211,7 @@ func TestNewV2Scores(t *testing.T) { for _, test := range(passTests) { t.Run(test.name, func(t *testing.T) { // build expected result - exp, err := newV2ScoresFromFloats(test.exps[0], test.exps[1], test.exps[2]) + exp, err := NewScores(test.exps[0], test.exps[1], test.exps[2]) if err != nil { t.Error(err) return diff --git a/cvss/v2vector.go b/cvss/v2vector.go index 14a4afb..e015544 100644 --- a/cvss/v2vector.go +++ b/cvss/v2vector.go @@ -42,8 +42,8 @@ func (v v2Vector) Metrics() []Metric { } // Return numerical scores for this vector. -func (v v2Vector) Scores() (v2Scores, error) { - return newV2Scores(v) +func (v v2Vector) Scores() (Scores, error) { + return newScoresFromV2Vector(v) } // Create CVSS 2.0 vector from string. -- cgit v1.2.3