-
Notifications
You must be signed in to change notification settings - Fork 187
Defining and generating spdx 3.0 json elements #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f93263
spdx 3.0 generator changes + unit tests
0ad3b33
Merge branch 'main' of https://github.com/microsoft/sbom-tool into pp…
d1572ef
address PR review comments
8584b1f
fix bug in UT + address PR comments
a625b4d
Merge branch 'main' of https://github.com/microsoft/sbom-tool into pp…
24bf69f
remove empty constructors
865edd9
add debug line
7447224
fix UT with regex
abc57b9
remove extra debug line
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using Microsoft.Sbom.Extensions.Entities; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser; | ||
|
|
||
| internal static class Constants | ||
| { | ||
| internal const string SPDXName = "SPDX"; | ||
| internal const string SPDXVersion = "3.0"; | ||
| internal const string DataLicenceValue = "CC0-1.0"; | ||
pragnya17 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| internal const string SPDXDocumentIdValue = "SPDXRef-DOCUMENT"; | ||
| internal const string RootPackageIdValue = "SPDXRef-RootPackage"; | ||
| internal const string SPDXRefFile = "SPDXRef-File"; | ||
|
|
||
| internal const string SPDXVersionHeaderName = "spdxVersion"; | ||
| internal const string DataLicenseHeaderName = "dataLicense"; | ||
| internal const string SPDXIDHeaderName = "SPDXID"; | ||
| internal const string DocumentNameHeaderName = "name"; | ||
| internal const string DocumentNamespaceHeaderName = "documentNamespace"; | ||
| internal const string CreationInfoHeaderName = "creationInfo"; | ||
| internal const string DocumentDescribesHeaderName = "documentDescribes"; | ||
|
|
||
| internal const int ReadBufferSize = 4096; | ||
|
|
||
| internal const string SPDXDocumentNameFormatString = "{0} {1}"; | ||
| internal const string PackageSupplierFormatString = "Organization: {0}"; | ||
|
|
||
| /// <summary> | ||
| /// Use if there is no available information for a field. | ||
| /// </summary> | ||
| internal const string NoneValue = "NONE"; | ||
|
|
||
| /// <summary> | ||
| /// Use if SPDX creator | ||
| /// - made an attempt to retrieve the info but cannot determine correct values. | ||
| /// - made no attempt to retrieve the info. | ||
| /// - has intentionally provided no information. | ||
| /// </summary> | ||
| internal const string NoAssertionValue = "NOASSERTION"; | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="NoAssertionValue"/> value as a list with a single item. | ||
| /// </summary> | ||
| internal static IEnumerable<string> NoAssertionListValue = new List<string> { NoAssertionValue }; | ||
|
|
||
| internal static ManifestInfo Spdx30ManifestInfo = new ManifestInfo | ||
| { | ||
| Name = SPDXName, | ||
| Version = SPDXVersion | ||
| }; | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/AnyLicenseInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities; | ||
|
|
||
| /// <summary> | ||
| /// Class defintion is based on: https://spdx.github.io/spdx-spec/v3.0.1/model/SimpleLicensing/Classes/AnyLicenseInfo/ | ||
| /// </summary> | ||
| public class AnyLicenseInfo : Element | ||
| { | ||
| public AnyLicenseInfo() | ||
| { | ||
| Type = "AnyLicenseInfo"; | ||
pragnya17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SpdxId = "SPDXRef-AnyLicenseInfo"; | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/ContentIdentifier.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities; | ||
|
|
||
| /// <summary> | ||
| /// A ContentIdentifier is a canonical, unique, immutable identifier of the content of a software artifact, such as a package, a file, or a snippet. | ||
| /// It can be used for verifying its identity and integrity. | ||
| /// https://spdx.github.io/spdx-spec/v3.0.1/model/Software/Classes/ContentIdentifier/ | ||
| /// </summary> | ||
| public class ContentIdentifier : Software | ||
| { | ||
| private string contentIdentifierType; | ||
|
|
||
| public ContentIdentifier() | ||
| { | ||
| Type = "ContentIdentifier"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the content identifier type. | ||
| /// Allowed types are Git Object ID and Software Hash Identifier (swhid). | ||
| /// We will use swhid unless otherwise specified. | ||
| /// </summary> | ||
| [JsonRequired] | ||
| [JsonPropertyName("contentIdentifierType")] | ||
| public override string ContentIdentifierType | ||
| { | ||
| get => this.contentIdentifierType ?? "swhid"; | ||
| set => this.contentIdentifierType = value; | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/CreationInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities; | ||
|
|
||
| /// <summary> | ||
| /// Used to define creation information about the SPDX element. | ||
| /// https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Classes/CreationInfo/ | ||
| /// </summary> | ||
| public class CreationInfo : Element | ||
| { | ||
| public CreationInfo() | ||
| { | ||
| Type = "CreationInfo"; | ||
| } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonPropertyName("@id")] | ||
| public string Id { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a string that specifies the time the SBOM was created on. | ||
| /// </summary> | ||
| [JsonRequired] | ||
| [JsonPropertyName("created")] | ||
| public string Created { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a list of strings that specify metadata about the creators of this SBOM. | ||
| /// This could be a person, organization, software agent, etc. and is represented by the Agent class. | ||
| /// This is not to be confused with tools that are used to perform tasks. | ||
| /// </summary> | ||
| [JsonRequired] | ||
| [JsonPropertyName("createdBy")] | ||
| public IEnumerable<string> CreatedBy { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a list of strings that specify metadata about the tools used to create this SBOM. | ||
| /// A tool is an element of hardware and/or software utilized to carry out a particular function. | ||
| /// </summary> | ||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonPropertyName("createdUsing")] | ||
| public IEnumerable<string> CreatedUsing { get; set; } | ||
|
|
||
| [JsonRequired] | ||
| [JsonPropertyName("specVersion")] | ||
| public string SpecVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Make sure that creation info details are not serialized/deserialized when creating a CreationInfo element. | ||
| /// CreationInfoDetails is a property in the base class Element that is inherited by all other classes except for CreationInfo. | ||
| /// </summary> | ||
| [JsonIgnore] | ||
| public new string CreationInfoDetails { get; set; } | ||
| } |
70 changes: 70 additions & 0 deletions
70
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Element.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities; | ||
|
|
||
| /// <summary> | ||
| /// Base domain class from which all other SPDX-3.0 domain classes derive. | ||
| /// https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Classes/Element/ | ||
| /// </summary> | ||
| public class Element | ||
pragnya17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| protected Element() | ||
| { | ||
| CreationInfoDetails = "_:creationinfo"; | ||
| } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonPropertyName("comment")] | ||
| public string Comment { get; set; } | ||
|
|
||
| [JsonRequired] | ||
| [JsonPropertyName("creationInfo")] | ||
| public string CreationInfoDetails { get; set; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonPropertyName("description")] | ||
| public string Description { get; set; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
| [JsonPropertyName("extension")] | ||
| public List<object> Extension { get; set; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
| [JsonPropertyName("externalIdentifier")] | ||
| public List<string> ExternalIdentifier { get; set; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
| [JsonPropertyName("externalRef")] | ||
| public List<string> ExternalRef { get; set; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonPropertyName("name")] | ||
| public string Name { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets unique Identifier for elements in SPDX document. | ||
| /// </summary> | ||
| [JsonRequired] | ||
| [JsonPropertyName("spdxId")] | ||
| public string SpdxId { get; set; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonPropertyName("summary")] | ||
| public string Summary { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets on how packages were verified. | ||
| /// </summary> | ||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
| [JsonPropertyName("verifiedUsing")] | ||
| public List<PackageVerificationCode> VerifiedUsing { get; set; } | ||
|
|
||
| [JsonRequired] | ||
| [JsonPropertyName("type")] | ||
| public string Type { get; set; } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Enums/HashAlgorithm.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities.Enums; | ||
|
|
||
| /// <summary> | ||
| /// Defined hash algorithms: https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Vocabularies/HashAlgorithm/ | ||
| /// </summary> | ||
| [JsonConverter(typeof(JsonStringEnumConverter))] | ||
| [SuppressMessage( | ||
| "StyleCop.CSharp.NamingRules", | ||
| "SA1300:Element should begin with upper-case letter", | ||
| Justification = "These are enum types that are case sensitive and defined by external code.")] | ||
| public enum HashAlgorithm | ||
| { | ||
| adler32, | ||
| blake2b256, | ||
| blake2b384, | ||
| blake2b512, | ||
| blake3, | ||
| crystalsDilithium, | ||
| crystalsKyber, | ||
| falcon, | ||
| md2, | ||
| md4, | ||
| md5, | ||
| md6, | ||
| other, | ||
| sha1, | ||
| sha224, | ||
| sha256, | ||
| sha384, | ||
| sha3_224, | ||
| sha3_256, | ||
| sha3_384, | ||
| sha3_512, | ||
| sha512 | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Enums/ProfileIdentifierType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities.Enums; | ||
|
|
||
| /// <summary> | ||
| /// There are a set of profiles that have been defined by a profile team. | ||
| /// https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Vocabularies/ProfileIdentifierType/. | ||
| /// </summary> | ||
| [JsonConverter(typeof(JsonStringEnumConverter))] | ||
| [SuppressMessage( | ||
| "StyleCop.CSharp.NamingRules", | ||
| "SA1300:Element should begin with upper-case letter", | ||
| Justification = "These are enum types that are case sensitive and defined by external code.")] | ||
| public enum ProfileIdentifierType | ||
| { | ||
| ai, | ||
| build, | ||
| core, | ||
| dataset, | ||
| expandedLicensing, | ||
| extension, | ||
| lite, | ||
| security, | ||
| simpleLicensing, | ||
| software | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.