aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-01-31 16:42:09 -0500
committerPaul Duncan <pabs@pablotron.org>2022-01-31 16:42:09 -0500
commit702de7c3eb3fd19f7f7d431100b84db5266a3625 (patch)
tree23b9f36e2424363a979c85315f99b147e65f4cf2 /internal
parent566e511c9e5cbe6530dcd8212533f11f5d8ecb7a (diff)
downloadcvez-702de7c3eb3fd19f7f7d431100b84db5266a3625.tar.bz2
cvez-702de7c3eb3fd19f7f7d431100b84db5266a3625.zip
internal/cvss: add isV30VectorString() and isV31VectorString(), remove extraneous package docs
Diffstat (limited to 'internal')
-rw-r--r--internal/cvss/badkey.go1
-rw-r--r--internal/cvss/badmetric.go1
-rw-r--r--internal/cvss/category.go1
-rw-r--r--internal/cvss/cvss.go10
-rw-r--r--internal/cvss/v2key.go1
-rw-r--r--internal/cvss/v2metric.go1
-rw-r--r--internal/cvss/v2vector.go1
-rw-r--r--internal/cvss/v30vector.go10
-rw-r--r--internal/cvss/v31vector.go10
-rw-r--r--internal/cvss/v3metric.go1
-rw-r--r--internal/cvss/version.go1
11 files changed, 19 insertions, 19 deletions
diff --git a/internal/cvss/badkey.go b/internal/cvss/badkey.go
index 872a6d2..5078074 100644
--- a/internal/cvss/badkey.go
+++ b/internal/cvss/badkey.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
import "fmt"
diff --git a/internal/cvss/badmetric.go b/internal/cvss/badmetric.go
index e7c3f4c..8f0bf5f 100644
--- a/internal/cvss/badmetric.go
+++ b/internal/cvss/badmetric.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
import "fmt"
diff --git a/internal/cvss/category.go b/internal/cvss/category.go
index 45b8947..b6e0b37 100644
--- a/internal/cvss/category.go
+++ b/internal/cvss/category.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
//go:generate stringer -linecomment -type=Category
diff --git a/internal/cvss/cvss.go b/internal/cvss/cvss.go
index 0e18656..9839e84 100644
--- a/internal/cvss/cvss.go
+++ b/internal/cvss/cvss.go
@@ -36,12 +36,12 @@ type Vector interface {
// Create new CVSS vector from vector string.
func NewVector(s string) (Vector, error) {
- if len(s) > len(v31Prefix) && s[:len(v31Prefix)] == v31Prefix {
- // create CVSS v2.0 vector.
- return newV31Vector(s[len(v31Prefix):])
- } else if len(s) > len(v30Prefix) && s[:len(v30Prefix)] == v30Prefix {
+ if isV31VectorString(s) {
+ // create CVSS v3.1 vector.
+ return newV31Vector(s)
+ } else if isV30VectorString(s) {
// create CVSS v3.0 vector.
- return newV30Vector(s[len(v30Prefix):])
+ return newV30Vector(s)
} else {
// create CVSS V2 vector
return newV2Vector(s)
diff --git a/internal/cvss/v2key.go b/internal/cvss/v2key.go
index 8a7996c..e3d6aa2 100644
--- a/internal/cvss/v2key.go
+++ b/internal/cvss/v2key.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
//go:generate stringer -linecomment -type=v2Key
diff --git a/internal/cvss/v2metric.go b/internal/cvss/v2metric.go
index b2b68d8..85913a6 100644
--- a/internal/cvss/v2metric.go
+++ b/internal/cvss/v2metric.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
//go:generate stringer -linecomment -type=v2Metric
diff --git a/internal/cvss/v2vector.go b/internal/cvss/v2vector.go
index 1cb318a..efa2444 100644
--- a/internal/cvss/v2vector.go
+++ b/internal/cvss/v2vector.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
import (
diff --git a/internal/cvss/v30vector.go b/internal/cvss/v30vector.go
index 4154a2f..951cd03 100644
--- a/internal/cvss/v30vector.go
+++ b/internal/cvss/v30vector.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
import (
@@ -43,9 +42,9 @@ func (v v30Vector) Metrics() []Metric {
return r
}
-// create CVSS 3.0 vector from string
+// Create CVSS 3.0 vector from string.
func newV30Vector(s string) (Vector, error) {
- strs := strings.Split(s, "/")
+ strs := strings.Split(s[len(v31Prefix):], "/")
r := make([]v3Metric, len(strs))
// walk metric strings
@@ -63,3 +62,8 @@ func newV30Vector(s string) (Vector, error) {
// build and return vector
return v30Vector(r), nil
}
+
+// Is the given string a CVSSv3.0 vector string?
+func isV30VectorString(s string) bool {
+ return (len(s) > len(v30Prefix)) && (s[:len(v30Prefix)] == v30Prefix);
+}
diff --git a/internal/cvss/v31vector.go b/internal/cvss/v31vector.go
index 65536cf..92fb1e6 100644
--- a/internal/cvss/v31vector.go
+++ b/internal/cvss/v31vector.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
import (
@@ -43,9 +42,9 @@ func (v v31Vector) Metrics() []Metric {
return r
}
-// create CVSS 3.1 vector from string
+// create CVSS 3.1 vector from string.
func newV31Vector(s string) (Vector, error) {
- strs := strings.Split(s, "/")
+ strs := strings.Split(s[len(v31Prefix):], "/")
r := make([]v3Metric, len(strs))
// walk metric strings
@@ -63,3 +62,8 @@ func newV31Vector(s string) (Vector, error) {
// build and return vector
return v31Vector(r), nil
}
+
+// Is the given string a CVSSv3.1 vector string?
+func isV31VectorString(s string) bool {
+ return (len(s) > len(v31Prefix)) && (s[:len(v31Prefix)] == v31Prefix);
+}
diff --git a/internal/cvss/v3metric.go b/internal/cvss/v3metric.go
index 8aa86b7..a8f25de 100644
--- a/internal/cvss/v3metric.go
+++ b/internal/cvss/v3metric.go
@@ -1,4 +1,3 @@
-// CVSS vector parser.
package cvss
//go:generate stringer -linecomment -type=v3Metric
diff --git a/internal/cvss/version.go b/internal/cvss/version.go
index ab9d61f..c46c893 100644
--- a/internal/cvss/version.go
+++ b/internal/cvss/version.go
@@ -1,4 +1,3 @@
-// CVSS vector string parser.
package cvss
//go:generate stringer -linecomment -type=Version