-
Notifications
You must be signed in to change notification settings - Fork 2
/
software.go
64 lines (58 loc) · 2.19 KB
/
software.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2020 Joakim Kennedy. All rights reserved. Use of
// this source code is governed by the included BSD license.
package stix2
import (
"fmt"
"strings"
)
// Software object represents high-level properties associated with software,
// including software products.
type Software struct {
STIXCyberObservableObject
// Name specifies the name of the software.
Name string `json:"name"`
// CPE specifies the Common Platform Enumeration (CPE) entry for the
// software, if available. The value for this property MUST be a CPE v2.3
// entry from the official NVD CPE Dictionary.
CPE string `json:"cpe,omitempty"`
// SWID specifies the Software Identification (SWID) Tags entry for the
// software, if available. The tag attribute, tagId, a globally unique
// identifier, SHOULD be used as a proxy identifier of the tagged product.
SWID string `json:"swid,omitempty"`
// Languages specifies the languages supported by the software. The value
// of each list member MUST be an ISO 639-2 language code.
Languages []string `json:"languages,omitempty"`
// Vendor specifies the name of the vendor of the software.
Vendor string `json:"vendor,omitempty"`
// Version specifies the version of the software.
Version string `json:"version,omitempty"`
}
func (o *Software) MarshalJSON() ([]byte, error) {
return marshalToJSONHelper(o)
}
// NewSoftware creates a new Software object. A Software object MUST contain at least one
// of hashes or name.
func NewSoftware(name string, opts ...STIXOption) (*Software, error) {
if name == "" {
return nil, ErrInvalidParameter
}
base := newSTIXCyberObservableObject(TypeSoftware)
obj := &Software{
STIXCyberObservableObject: base,
Name: name,
}
err := applyOptions(obj, opts)
idContri := make([]string, 0, 4)
idContri = append(idContri, fmt.Sprintf(`"%s"`, obj.Name))
if obj.CPE != "" {
idContri = append(idContri, fmt.Sprintf(`"%s"`, obj.CPE))
}
if obj.Vendor != "" {
idContri = append(idContri, fmt.Sprintf(`"%s"`, obj.Vendor))
}
if obj.Version != "" {
idContri = append(idContri, fmt.Sprintf(`"%s"`, obj.Version))
}
obj.ID = NewObservableIdentifier(fmt.Sprintf("[%s]", strings.Join(idContri, ",")), TypeSoftware)
return obj, err
}