-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defining and generating spdx 3.0 json elements (#830)
* spdx 3.0 generator changes + unit tests * address PR review comments * fix bug in UT + address PR comments * remove empty constructors * add debug line * fix UT with regex * remove extra debug line --------- Co-authored-by: ppandrate <ppandrate@microsoft.com>
- Loading branch information
Showing
43 changed files
with
2,636 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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 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,40 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.Sbom.Common; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Sbom.Contracts; | ||
using Microsoft.Sbom.Contracts.Enums; | ||
using Microsoft.Sbom.Extensions.Exceptions; | ||
|
||
/// <summary> | ||
/// A class for methods that are used by SPDX generators, regardless of which SPDX version is being used. | ||
/// </summary> | ||
public class GeneratorUtils | ||
{ | ||
// Throws a <see cref="MissingHashValueException"/> if the filehashes are missing | ||
// any of the required hashes | ||
public static void EnsureRequiredHashesPresent(Checksum[] fileHashes, AlgorithmName[] requiredHashAlgorithms) | ||
{ | ||
foreach (var hashAlgorithmName in from hashAlgorithmName in requiredHashAlgorithms | ||
where !fileHashes.Select(fh => fh.Algorithm).Contains(hashAlgorithmName) | ||
select hashAlgorithmName) | ||
{ | ||
throw new MissingHashValueException($"The hash value for algorithm {hashAlgorithmName} is missing from {nameof(fileHashes)}"); | ||
} | ||
} | ||
|
||
public static string EnsureRelativePathStartsWithDot(string path) | ||
{ | ||
if (!path.StartsWith(".", StringComparison.Ordinal)) | ||
{ | ||
return "." + path; | ||
} | ||
|
||
return path; | ||
} | ||
} |
This file contains 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 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 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 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 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,37 @@ | ||
// 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"; | ||
internal const string SPDXDocumentIdValue = "SPDXRef-DOCUMENT"; | ||
internal const string RootPackageIdValue = "SPDXRef-RootPackage"; | ||
internal const string SPDXDocumentNameFormatString = "{0} {1}"; | ||
internal const string PackageSupplierFormatString = "Organization: {0}"; | ||
|
||
/// <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 | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/AnyLicenseInfo.cs
This file contains 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,18 @@ | ||
// 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() | ||
{ | ||
SpdxId = "SPDXRef-AnyLicenseInfo"; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/ContentIdentifier.cs
This file contains 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.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; | ||
|
||
/// <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; | ||
} | ||
} |
Oops, something went wrong.