Skip to content

Conversation

@kzantow
Copy link
Collaborator

@kzantow kzantow commented Aug 1, 2024

After a number of experiments, I think this PR now represents the more-or-less easiest model to deal with the set of compromises required to support SPDX 3 inheritance and other features in go.

Some notes:

  • all elements are required to have a creation Info; this PR includes a feature during JSON serialization to set all elements creation info if it is unset, and due to this chicken-and-egg problem between creation info and agent, where both are required and both reference each other, there is a constructor to help
  • all SPDX elements must have an spdxId; this happens automatically prior to serialization
  • it could be possible to have multiple SPDX document objects in the same json document but this is prohibited by the spec, only the first will be returned
  • there are 2 ways to interact with the data: directly accessing structs and using interfaces. When creating documents/constructing objects, it's much more convenient to directly construct them in a familiar go struct syntax but due to the object inheritance, accessing documents is done predominantly through interfaces
  • due to the way much of this all works, it is most correct to have every minor version of SPDX 3 present, since every field ID changes. There could be some workarounds, but I have not implemented them here
  • no conversion backwards from v3 to v2 is implemented

Very basic example usage:

import spdx "github.com/spdx/tools-golang/spdx/v3/v3_0_1"

d := spdx.NewDocument(spdx.ProfileIdentifierType_Software, "ADocumentName",
		&spdx.SoftwareAgent{Name: "some-tool"},
		&spdx.Tool{Name: "some-tool"})

sbom := &spdx.SBOM{}
d.RootElements = append(d.RootElements, sbom)

pkg := &spdx.Package{
  Name: "a-package-name",
}

file := &spdx.File{
  Name: "a-file-name",
}

sbom.RootElements = append(sbom.RootElements, pkg)
sbom.Elements = append(sbom.Elements, &spdx.Relationship{
  Type: spdx.RelationshipType_DependsOn,
  From: pkg,
  To: spdx.ElementList{ file },
}

@kzantow kzantow force-pushed the feat/spdx-3-prototype branch 2 times, most recently from b71353a to 936ae58 Compare August 1, 2024 06:32
@kzantow kzantow changed the title feat: prototype v3_0 model feat: prototype 3.0 model Aug 1, 2024
@kzantow kzantow force-pushed the feat/spdx-3-prototype branch 2 times, most recently from ea44d2b to 14db0d0 Compare August 1, 2024 16:05
Signed-off-by: Keith Zantow <kzantow@gmail.com>
@kzantow kzantow force-pushed the feat/spdx-3-prototype branch from 14db0d0 to 8e9125f Compare August 2, 2024 19:49
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
kzantow added 2 commits March 10, 2025 01:33
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
@AlexandreEXFO
Copy link

aquasecurity/trivy#9195

kzantow added 3 commits August 5, 2025 22:22
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
@kzantow kzantow dismissed pandatix’s stale review October 8, 2025 22:14

Addressed issue

Signed-off-by: Keith Zantow <kzantow@gmail.com>
@kzantow kzantow changed the title feat: prototype 3.0 model feat: SPDX 3 Oct 9, 2025
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants