aboutsummaryrefslogtreecommitdiff
path: root/spdx
diff options
context:
space:
mode:
authorSteve Winslow <steve@swinslow.net>2021-05-02 17:34:43 -0400
committerSteve Winslow <steve@swinslow.net>2021-05-02 17:34:43 -0400
commit0e918ca7c85a9a4f865b59445ecf46abbb8d3feb (patch)
treeb5565aa245495205aed6206c95a38796ebb919d1 /spdx
parentcb47219353548d6fdb55034422dc4e7fbee19058 (diff)
parent6234aa66fed08ee03a2be31ec177152cefeedfd2 (diff)
downloadspdx-tools-0e918ca7c85a9a4f865b59445ecf46abbb8d3feb.tar.gz
Merge branch 'issue-59' into issue-59-to-master
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 + ":"