aboutsummaryrefslogtreecommitdiff
path: root/internal/cpe
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-03 08:34:46 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-03 08:34:46 -0500
commit2580300f01b30ce7ec99df4986e9c9489f7c5d9b (patch)
treef9a282b5a338ba4250d0cedc4c96d108c4f4eb03 /internal/cpe
parent06a4cc5f6d5d66061c8f4f254528aec70a016994 (diff)
downloadcvez-2580300f01b30ce7ec99df4986e9c9489f7c5d9b.tar.bz2
cvez-2580300f01b30ce7ec99df4986e9c9489f7c5d9b.zip
internal/cpe: s/Binding/V23Binding/
Diffstat (limited to 'internal/cpe')
-rw-r--r--internal/cpe/binding.go28
-rw-r--r--internal/cpe/binding_test.go20
2 files changed, 24 insertions, 24 deletions
diff --git a/internal/cpe/binding.go b/internal/cpe/binding.go
index f58752e..24fb7b2 100644
--- a/internal/cpe/binding.go
+++ b/internal/cpe/binding.go
@@ -8,7 +8,7 @@ import (
)
// CPE 2.3 binding.
-type Binding struct {
+type V23Binding struct {
Part Part // Part attribute (NISTIR7695 5.3.3.1).
Vendor AvString // Vendor attribute (NISTIR7695 5.3.3.2).
Product AvString // Product attribute (NISTIR7695 5.3.3.3).
@@ -29,40 +29,40 @@ var cpe23Prefix = "cpe:2.3:"
var missingPrefix = errors.New("missing CPE 2.3 prefix")
// Create binding from CPE 2.3 formatted string.
-func NewBinding(s string) (Binding, error) {
+func NewV23Binding(s string) (V23Binding, error) {
// check prefix
if s[0:len(cpe23Prefix)] != cpe23Prefix {
- return Binding{}, missingPrefix
+ return V23Binding{}, missingPrefix
}
// tokenize string, check for error
toks, err := tokenize([]byte(s[len(cpe23Prefix):]))
if err != nil {
- return Binding{}, err
+ return V23Binding{}, err
}
// check token count
if len(toks) != 11 {
err = fmt.Errorf("invalid attribute count: %d != 11", len(toks))
- return Binding{}, err
+ return V23Binding{}, err
}
// create part
part, err := newPart(toks[0])
if err != nil {
- return Binding{}, err
+ return V23Binding{}, err
}
// parse tokens into strings
strs := make([]AvString, len(toks) - 1)
for i, t := range(toks[1:]) {
if strs[i], err = newAvString(t); err != nil {
- return Binding{}, err
+ return V23Binding{}, err
}
}
// build and return result
- return Binding {
+ return V23Binding {
Part: part,
Vendor: strs[0],
Product: strs[1],
@@ -77,8 +77,8 @@ func NewBinding(s string) (Binding, error) {
}, nil
}
-// Serialize binding as CPE 2.3 formatted string.
-func (v Binding) String() string {
+// Serialize CPE 2.3 binding as formatted string.
+func (v V23Binding) String() string {
return cpe23Prefix + strings.Join([]string {
v.Part.String(),
v.Vendor.String(),
@@ -94,8 +94,8 @@ func (v Binding) String() string {
}, ":")
}
-// Unmarshal CPE binding from JSON string.
-func (me *Binding) UnmarshalJSON(b []byte) error {
+// Unmarshal CPE 2.3 binding from JSON string.
+func (me *V23Binding) UnmarshalJSON(b []byte) error {
// decode json string
var s string
if err := json.Unmarshal(b, &s); err != nil {
@@ -103,7 +103,7 @@ func (me *Binding) UnmarshalJSON(b []byte) error {
}
// create binding
- binding, err := NewBinding(s)
+ binding, err := NewV23Binding(s)
if err != nil {
return err
}
@@ -114,6 +114,6 @@ func (me *Binding) UnmarshalJSON(b []byte) error {
}
// Marshal CPE binding as JSON string.
-func (v Binding) MarshalJSON() ([]byte, error) {
+func (v V23Binding) MarshalJSON() ([]byte, error) {
return json.Marshal(v.String())
}
diff --git a/internal/cpe/binding_test.go b/internal/cpe/binding_test.go
index 7c5154a..4fa46bb 100644
--- a/internal/cpe/binding_test.go
+++ b/internal/cpe/binding_test.go
@@ -5,14 +5,14 @@ import (
"testing"
)
-func TestNewBinding(t *testing.T) {
+func TestNewV23Binding(t *testing.T) {
passTests := []string {
"cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*",
}
for _, val := range(passTests) {
t.Run(val, func(t *testing.T) {
- if _, err := NewBinding(val); err != nil {
+ if _, err := NewV23Binding(val); err != nil {
t.Error(err)
}
})
@@ -37,7 +37,7 @@ func TestNewBinding(t *testing.T) {
for _, test := range(failTests) {
t.Run(test.val, func(t *testing.T) {
- got, err := NewBinding(test.val)
+ got, err := NewV23Binding(test.val)
if err == nil {
t.Errorf("got %v, exp error", got)
} else if err.Error() != test.exp {
@@ -47,14 +47,14 @@ func TestNewBinding(t *testing.T) {
}
}
-func TestBindingString(t *testing.T) {
+func TestV23BindingString(t *testing.T) {
tests := []string {
"cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*",
}
for _, val := range(tests) {
t.Run(val, func(t *testing.T) {
- if got, err := NewBinding(val); err != nil {
+ if got, err := NewV23Binding(val); err != nil {
t.Error(err)
} else if got.String() != val {
t.Errorf("got \"%s\", exp \"%s\"", got.String(), val)
@@ -63,14 +63,14 @@ func TestBindingString(t *testing.T) {
}
}
-func TestBindingUnmarshalJSON(t *testing.T) {
+func TestV23BindingUnmarshalJSON(t *testing.T) {
passTests := []string {
`"cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*"`,
}
for _, val := range(passTests) {
t.Run(val, func(t *testing.T) {
- var b Binding
+ var b V23Binding
if err := json.Unmarshal([]byte(val), &b); err != nil {
t.Error(err)
}
@@ -90,7 +90,7 @@ func TestBindingUnmarshalJSON(t *testing.T) {
for _, test := range(failTests) {
t.Run(test.val, func(t *testing.T) {
- var got Binding
+ var got V23Binding
if err := json.Unmarshal([]byte(test.val), &got); err == nil {
t.Errorf("got %v, exp error", got)
} else if err.Error() != test.exp {
@@ -100,7 +100,7 @@ func TestBindingUnmarshalJSON(t *testing.T) {
}
}
-func TestBindingMarshalJSON(t *testing.T) {
+func TestV23BindingMarshalJSON(t *testing.T) {
tests := []string {
"cpe:2.3:o:intel:ethernet_controller_e810_firmware:*:*:*:*:*:*:*:*",
}
@@ -108,7 +108,7 @@ func TestBindingMarshalJSON(t *testing.T) {
for _, val := range(tests) {
t.Run(val, func(t *testing.T) {
// create binding, check for error
- b, err := NewBinding(val)
+ b, err := NewV23Binding(val)
if err != nil {
t.Error(err)
return