aboutsummaryrefslogtreecommitdiff
path: root/spdx
diff options
context:
space:
mode:
authorSteve Winslow <steve@swinslow.net>2021-03-20 17:16:31 -0400
committerSteve Winslow <steve@swinslow.net>2021-03-20 17:16:31 -0400
commit6234aa66fed08ee03a2be31ec177152cefeedfd2 (patch)
tree8f62b5948cffe465927cc06a6eb83c815ac39d04 /spdx
parentad870ed6f31eb4918018af143611a5a2dc6aa798 (diff)
downloadspdx-tools-6234aa66fed08ee03a2be31ec177152cefeedfd2.tar.gz
Fix special IDs for right-side 2.2 Relationships
In SPDX 2.2, the right-hand side of Relationships are not limited to SPDX IDs; they can also include the special values NONE and NOASSERTION. To handle these, since Golang doesn't (to my knowledge) have a concept of union types, and since I don't want to use interface{}, this commit instead adds a new SpecialID field to DocElementID. When SpecialID is non-empty, it should be treated as being a "special" ID value, and DocumentRefID / ElementRefID should be ignored. (Unfortunately, we can't just use ElementRefID == "NONE", etc. for this purpose, because in theory an SPDX document could define the identifier SPDXRef-NONE to mean something. Even though they really, really shouldn't do that.) This commit updates tvloader and tvsaver to appropriately handle the possibility of NONE and NOASSERTION for this field. Signed-off-by: Steve Winslow <steve@swinslow.net>
Diffstat (limited to 'spdx')
-rw-r--r--spdx/identifier.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/spdx/identifier.go b/spdx/identifier.go
index 496aeb3..baf44c1 100644
--- a/spdx/identifier.go
+++ b/spdx/identifier.go
@@ -18,9 +18,14 @@ type ElementID string
// present document.
// DocElementIDs should NOT contain the mandatory 'DocumentRef-' or
// 'SPDXRef-' portions.
+// SpecialID is used ONLY if the DocElementID matches a defined set of
+// permitted special values for a particular field, e.g. "NONE" or
+// "NOASSERTION" for the right-hand side of Relationships. If SpecialID
+// is set, DocumentRefID and ElementRefID should be empty (and vice versa).
type DocElementID struct {
DocumentRefID string
ElementRefID ElementID
+ SpecialID string
}
// TODO: add equivalents for LicenseRef- identifiers
@@ -36,6 +41,14 @@ func MakeDocElementID(docRef string, eltRef string) DocElementID {
}
}
+// MakeDocElementSpecial takes a "special" string (e.g. "NONE" or
+// "NOASSERTION" for the right side of a Relationship), nd returns
+// a DocElementID with it in the SpecialID field. Other fields will
+// be empty.
+func MakeDocElementSpecial(specialID string) DocElementID {
+ return DocElementID{SpecialID: specialID}
+}
+
// RenderElementID takes an ElementID and returns the string equivalent,
// with the SPDXRef- prefix reinserted.
func RenderElementID(eID ElementID) string {
@@ -44,8 +57,12 @@ func RenderElementID(eID ElementID) string {
// RenderDocElementID takes a DocElementID and returns the string equivalent,
// with the SPDXRef- prefix (and, if applicable, the DocumentRef- prefix)
-// reinserted.
+// reinserted. If a SpecialID is present, it will be rendered verbatim and
+// DocumentRefID and ElementRefID will be ignored.
func RenderDocElementID(deID DocElementID) string {
+ if deID.SpecialID != "" {
+ return deID.SpecialID
+ }
prefix := ""
if deID.DocumentRefID != "" {
prefix = "DocumentRef-" + deID.DocumentRefID + ":"