Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 44020e3

Browse files
committedDec 23, 2021
Implement SPDX library for serialization and validation
Signed-off-by: Patrick Dwyer <patrick.dwyer@owasp.org>
1 parent 9bc80df commit 44020e3

35 files changed

+3488
-0
lines changed
 

‎CycloneDXLibrary.sln

+30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CycloneDX.Utils.Tests", "te
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CycloneDX.Core.Tests", "tests\CycloneDX.Core.Tests\CycloneDX.Core.Tests.csproj", "{7474D234-9911-44FF-9CE7-A1894FEE08F4}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CycloneDX.Spdx", "src\CycloneDX.Spdx\CycloneDX.Spdx.csproj", "{A0351F39-0DFB-4789-8297-6C08C6E45912}"
27+
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CycloneDX.Spdx.Tests", "tests\CycloneDX.Spdx.Tests\CycloneDX.Spdx.Tests.csproj", "{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}"
29+
EndProject
2630
Global
2731
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2832
Debug|Any CPU = Debug|Any CPU
@@ -84,6 +88,30 @@ Global
8488
{7474D234-9911-44FF-9CE7-A1894FEE08F4}.Release|x64.Build.0 = Release|Any CPU
8589
{7474D234-9911-44FF-9CE7-A1894FEE08F4}.Release|x86.ActiveCfg = Release|Any CPU
8690
{7474D234-9911-44FF-9CE7-A1894FEE08F4}.Release|x86.Build.0 = Release|Any CPU
91+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
92+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Debug|Any CPU.Build.0 = Debug|Any CPU
93+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Debug|x64.ActiveCfg = Debug|Any CPU
94+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Debug|x64.Build.0 = Debug|Any CPU
95+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Debug|x86.ActiveCfg = Debug|Any CPU
96+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Debug|x86.Build.0 = Debug|Any CPU
97+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Release|Any CPU.ActiveCfg = Release|Any CPU
98+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Release|Any CPU.Build.0 = Release|Any CPU
99+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Release|x64.ActiveCfg = Release|Any CPU
100+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Release|x64.Build.0 = Release|Any CPU
101+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Release|x86.ActiveCfg = Release|Any CPU
102+
{A0351F39-0DFB-4789-8297-6C08C6E45912}.Release|x86.Build.0 = Release|Any CPU
103+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
104+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Debug|Any CPU.Build.0 = Debug|Any CPU
105+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Debug|x64.ActiveCfg = Debug|Any CPU
106+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Debug|x64.Build.0 = Debug|Any CPU
107+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Debug|x86.ActiveCfg = Debug|Any CPU
108+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Debug|x86.Build.0 = Debug|Any CPU
109+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Release|Any CPU.ActiveCfg = Release|Any CPU
110+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Release|Any CPU.Build.0 = Release|Any CPU
111+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Release|x64.ActiveCfg = Release|Any CPU
112+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Release|x64.Build.0 = Release|Any CPU
113+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Release|x86.ActiveCfg = Release|Any CPU
114+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E}.Release|x86.Build.0 = Release|Any CPU
87115
EndGlobalSection
88116
GlobalSection(MonoDevelopProperties) = preSolution
89117
Policies = $0
@@ -98,5 +126,7 @@ Global
98126
{F54EA8EA-C58B-48FF-8BAA-0A37C8A6F81F} = {67D64250-A7BE-48A5-96F6-930D06724523}
99127
{55159199-1892-4C73-82E0-F4143D8ADDD7} = {87631A9A-EDF0-4078-BD7A-731D56B55439}
100128
{7474D234-9911-44FF-9CE7-A1894FEE08F4} = {87631A9A-EDF0-4078-BD7A-731D56B55439}
129+
{A0351F39-0DFB-4789-8297-6C08C6E45912} = {67D64250-A7BE-48A5-96F6-930D06724523}
130+
{9D39D61D-E21B-4CBA-BB3A-BCCD48AA464E} = {87631A9A-EDF0-4078-BD7A-731D56B55439}
101131
EndGlobalSection
102132
EndGlobal

‎NOTICE

+7
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ Copyright (c) OWASP Foundation
33

44
This product includes software developed by the
55
CycloneDX community (https://cyclonedx.org/).
6+
7+
This project includes the SPDX JSON schema from
8+
the SPDX project for SPDX document validation (https://spdx.dev/).
9+
10+
This project includes example SPDX documents from
11+
the SPDX project to validate correctness of
12+
the SPDX implementation (https://spdx.dev/).

‎docs/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ To add additional utility methods to your project
2020
dotnet add package CycloneDX.Utils
2121
```
2222

23+
To add SPDX serialization, deserialization, and validation to your project
24+
25+
```shell
26+
dotnet add package CycloneDX.Spdx
27+
```
28+
29+
To convert between CycloneDX and SPDX formats
30+
31+
```shell
32+
dotnet add package CycloneDX.Spdx.Interop
33+
```
34+
2335
For code examples check out the [Getting Started Article](articles/getting-started.md)
2436

2537
## License
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Product>CycloneDX.Spdx</Product>
6+
<Authors>Patrick Dwyer</Authors>
7+
<Copyright>Copyright (c) OWASP Foundation</Copyright>
8+
<Description>A .NET Standard library for SPDX documents.</Description>
9+
<PackageId>CycloneDX.Spdx</PackageId>
10+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
11+
<PackageProjectUrl>https://github.com/CycloneDX/cyclonedx-dotnet-library</PackageProjectUrl>
12+
<RepositoryType>git</RepositoryType>
13+
<RepositoryUrl>https://github.com/CycloneDX/cyclonedx-dotnet-library.git</RepositoryUrl>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="System.Text.Json" Version="6.0.1" />
18+
<PackageReference Include="JsonSchema.Net" Version="1.11.3" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<EmbeddedResource Include="Schemas\*" />
23+
</ItemGroup>
24+
25+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
21+
namespace CycloneDX.Spdx.Models
22+
{
23+
/// <summary>
24+
/// The return type for all validation methods.
25+
/// </summary>
26+
public class ValidationResult
27+
{
28+
/// <summary>
29+
/// <c>true</c> if the document has been successfully validated.
30+
/// </summary>
31+
/// <value></value>
32+
public bool Valid { get; set; }
33+
/// <summary>
34+
/// When validation fails, has one or more messages detailing why validation failed.
35+
/// </summary>
36+
/// <typeparam name="string"></typeparam>
37+
/// <returns></returns>
38+
public IEnumerable<string> Messages { get; set; } = new List<string>();
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class Annotation
23+
{
24+
/// <summary>
25+
/// Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.
26+
/// </summary>
27+
public DateTime AnnotationDate { get; set; }
28+
29+
/// <summary>
30+
/// Type of the annotation.
31+
/// </summary>
32+
public AnnotationType AnnotationType { get; set; }
33+
34+
/// <summary>
35+
/// This field identifies the person, organization or tool that has commented on a file, package, or the entire document.
36+
/// </summary>
37+
public string Annotator { get; set; }
38+
39+
public string Comment { get; set; }
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public enum AnnotationType
23+
{
24+
OTHER,
25+
REVIEW,
26+
}
27+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class Checksum
23+
{
24+
/// <summary>
25+
/// Identifies the algorithm used to produce the subject Checksum. Currently, SHA-1 is the only supported algorithm. It is anticipated that other algorithms will be supported at a later time.
26+
/// </summary>
27+
public ChecksumAlgorithm Algorithm { get; set; }
28+
29+
/// <summary>
30+
/// The checksumValue property provides a lower case hexidecimal encoded digest value produced using a specific algorithm.
31+
/// </summary>
32+
public string ChecksumValue { get; set; }
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public enum ChecksumAlgorithm
23+
{
24+
SHA256,
25+
SHA1,
26+
SHA384,
27+
MD2,
28+
MD4,
29+
SHA512,
30+
MD6,
31+
MD5,
32+
SHA224,
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
21+
namespace CycloneDX.Spdx.Models.v2_2
22+
{
23+
public class CreationInfo
24+
{
25+
public string Comment { get; set; }
26+
27+
/// <summary>
28+
/// Identify when the SPDX file was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard. This field is distinct from the fields in section 8, which involves the addition of information during a subsequent review.
29+
/// </summary>
30+
public DateTime Created { get; set; }
31+
32+
/// <summary>
33+
/// Identify who (or what, in the case of a tool) created the SPDX file. If the SPDX file was created by an individual, indicate the person's name. If the SPDX file was created on behalf of a company or organization, indicate the entity name. If the SPDX file was created using a software tool, indicate the name and version for that tool. If multiple participants or tools were involved, use multiple instances of this field. Person name or organization name may be designated as “anonymous” if appropriate.
34+
/// </summary>
35+
public List<string> Creators { get; set; }
36+
37+
/// <summary>
38+
/// An optional field for creators of the SPDX file to provide the version of the SPDX License List used when the SPDX file was created.
39+
/// </summary>
40+
public string LicenseListVersion { get; set; }
41+
}
42+
}
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class CrossRef
23+
{
24+
/// <summary>
25+
/// True if the License SeeAlso URL points to a Wayback archive
26+
/// </summary>
27+
public bool IsWayBackLink { get; set; }
28+
29+
/// <summary>
30+
/// Status of a License List SeeAlso URL reference if it refers to a website that matches the license text.
31+
/// </summary>
32+
public string Match { get; set; }
33+
34+
/// <summary>
35+
/// Timestamp
36+
/// </summary>
37+
public string Timestamp { get; set; }
38+
39+
/// <summary>
40+
/// The ordinal order of this element within a list
41+
/// </summary>
42+
public int Order { get; set; }
43+
44+
/// <summary>
45+
/// URL Reference
46+
/// </summary>
47+
public string Url { get; set; }
48+
49+
/// <summary>
50+
/// Indicate a URL is still a live accessible location on the public internet
51+
/// </summary>
52+
public bool IsLive { get; set; }
53+
54+
/// <summary>
55+
/// True if the URL is a valid well formed URL
56+
/// </summary>
57+
public bool IsValid { get; set; }
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class ExternalDocumentRef
23+
{
24+
/// <summary>
25+
/// externalDocumentId is a string containing letters, numbers, ., - and/or + which uniquely identifies an external document within this document.
26+
/// </summary>
27+
public string ExternalDocumentId { get; set; }
28+
29+
/// <summary>
30+
/// A Checksum is value that allows the contents of a file to be authenticated. Even small changes to the content of the file will change its checksum. This class allows the results of a variety of checksum and cryptographic message digest algorithms to be represented.
31+
/// </summary>
32+
public Checksum Checksum { get; set; } = new Checksum();
33+
34+
/// <summary>
35+
/// SPDX ID for SpdxDocument. A propoerty containing an SPDX document.
36+
/// </summary>
37+
public string SpdxDocument { get; set; }
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class ExternalRef
23+
{
24+
public string Comment { get; set; }
25+
26+
/// <summary>
27+
/// Category for the external reference
28+
/// </summary>
29+
public ExternalRefCategory ReferenceCategory { get; set; }
30+
31+
/// <summary>
32+
/// The unique string with no spaces necessary to access the package-specific information, metadata, or content within the target location. The format of the locator is subject to constraints defined by the &lt;type&gt;.
33+
/// </summary>
34+
public string ReferenceLocator { get; set; }
35+
36+
/// <summary>
37+
/// Type of the external reference. These are definined in an appendix in the SPDX specification.
38+
/// </summary>
39+
public string ReferenceType { get; set; }
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public enum ExternalRefCategory
23+
{
24+
OTHER,
25+
SECURITY,
26+
PACKAGE_MANAGER,
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
21+
namespace CycloneDX.Spdx.Models.v2_2
22+
{
23+
public class ExtractedLicensingInfo
24+
{
25+
/// <summary>
26+
/// A human readable short form license identifier for a license. The license ID is iether on the standard license oist or the form "LicenseRef-"[idString] where [idString] is a unique string containing letters, numbers, ".", "-" or "+".
27+
/// </summary>
28+
public string LicenseId { get; set; }
29+
30+
public string Comment { get; set; }
31+
32+
/// <summary>
33+
/// Verbatim license or licensing notice text that was discovered.
34+
/// </summary>
35+
public string ExtractedText { get; set; }
36+
37+
/// <summary>
38+
/// Identify name of this SpdxElement.
39+
/// </summary>
40+
public string Name { get; set; }
41+
42+
/// <summary>
43+
/// Cross Reference Detail for a license SeeAlso URL
44+
/// </summary>
45+
public List<CrossRef> CrossRefs { get; set; }
46+
47+
public List<string> SeeAlsos { get; set; }
48+
}
49+
}
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text.Json.Serialization;
21+
22+
namespace CycloneDX.Spdx.Models.v2_2
23+
{
24+
public class File
25+
{
26+
/// <summary>
27+
/// Uniquely identify any element in an SPDX document which may be referenced by other elements.
28+
/// </summary>
29+
[JsonPropertyName("SPDXID")]
30+
public string SPDXID { get; set; }
31+
32+
/// <summary>
33+
/// Provide additional information about an SpdxElement.
34+
/// </summary>
35+
public List<Annotation> Annotations { get; set; }
36+
37+
/// <summary>
38+
/// The checksum property provides a mechanism that can be used to verify that the contents of a File or Package have not changed.
39+
/// </summary>
40+
public List<Checksum> Checksums { get; set; }
41+
42+
public string Comment { get; set; }
43+
44+
/// <summary>
45+
/// The text of copyright declarations recited in the Package or File.
46+
/// </summary>
47+
public string CopyrightText { get; set; }
48+
49+
/// <summary>
50+
/// This field provides a place for the SPDX file creator to record file contributors. Contributors could include names of copyright holders and/or authors who may not be copyright holders yet contributed to the file content.
51+
/// </summary>
52+
public List<string> FileContributors { get; set; }
53+
54+
/// <summary>
55+
/// The name of the file relative to the root of the package.
56+
/// </summary>
57+
public string FileName { get; set; }
58+
59+
/// <summary>
60+
/// The type of the file.
61+
/// </summary>
62+
public List<FileType> FileTypes { get; set; }
63+
64+
/// <summary>
65+
/// This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.
66+
/// </summary>
67+
public List<string> AttributionTexts { get; set; }
68+
69+
/// <summary>
70+
/// Indicates the project in which the SpdxElement originated. Tools must preserve doap:homepage and doap:name properties and the URI (if one is known) of doap:Project resources that are values of this property. All other properties of doap:Projects are not directly supported by SPDX and may be dropped when translating to or from some SPDX formats.
71+
/// </summary>
72+
[Obsolete("Artifacts Of is deprecated, use Relationships instead")]
73+
public List<string> ArtifactOfs { get; set; }
74+
75+
/// <summary>
76+
/// The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.
77+
/// </summary>
78+
public string LicenseComments { get; set; }
79+
80+
/// <summary>
81+
/// License expression for licenseConcluded. The licensing that the preparer of this SPDX document has concluded, based on the evidence, actually applies to the package.
82+
/// </summary>
83+
public string LicenseConcluded { get; set; }
84+
85+
/// <summary>
86+
/// Licensing information that was discovered directly in the subject file. This is also considered a declared license for the file.
87+
/// </summary>
88+
public List<string> LicenseInfoInFiles { get; set; }
89+
90+
/// <summary>
91+
/// This field provides a place for the SPDX file creator to record potential legal notices found in the file. This may or may not include copyright statements.
92+
/// </summary>
93+
public string NoticeText { get; set; }
94+
95+
[Obsolete("File Dependencies is deprecated, use Relationships instead")]
96+
public List<string> FileDependencies { get; set; }
97+
}
98+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public enum FileType
23+
{
24+
OTHER,
25+
DOCUMENTATION,
26+
IMAGE,
27+
VIDEO,
28+
ARCHIVE,
29+
SPDX,
30+
APPLICATION,
31+
SOURCE,
32+
BINARY,
33+
TEXT,
34+
AUDIO,
35+
}
36+
}
+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text.Json.Serialization;
21+
22+
namespace CycloneDX.Spdx.Models.v2_2
23+
{
24+
public class Package
25+
{
26+
/// <summary>
27+
/// Uniquely identify any element in an SPDX document which may be referenced by other elements.
28+
/// </summary>
29+
[JsonPropertyName("SPDXID")]
30+
public string SPDXID { get; set; }
31+
32+
/// <summary>
33+
/// Provide additional information about an SpdxElement.
34+
/// </summary>
35+
public List<Annotation> Annotations { get; set; }
36+
37+
/// <summary>
38+
/// This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.
39+
/// </summary>
40+
public List<string> AttributionTexts { get; set; }
41+
42+
/// <summary>
43+
/// The checksum property provides a mechanism that can be used to verify that the contents of a File or Package have not changed.
44+
/// </summary>
45+
public List<Checksum> Checksums { get; set; }
46+
47+
/// <summary>
48+
/// The text of copyright declarations recited in the Package or File.
49+
/// </summary>
50+
public string CopyrightText { get; set; }
51+
52+
/// <summary>
53+
/// Provides a detailed description of the package.
54+
/// </summary>
55+
public string Description { get; set; }
56+
57+
/// <summary>
58+
/// The URI at which this package is available for download. Private (i.e., not publicly reachable) URIs are acceptable as values of this property. The values http://spdx.org/rdf/terms#none and http://spdx.org/rdf/terms#noassertion may be used to specify that the package is not downloadable or that no attempt was made to determine its download location, respectively.
59+
/// </summary>
60+
public string DownloadLocation { get; set; }
61+
62+
/// <summary>
63+
/// An External Reference allows a Package to reference an external source of additional information, metadata, enumerations, asset identifiers, or downloadable content believed to be relevant to the Package.
64+
/// </summary>
65+
public List<ExternalRef> ExternalRefs { get; set; }
66+
67+
/// <summary>
68+
/// Indicates whether the file content of this package has been available for or subjected to analysis when creating the SPDX document. If false indicates packages that represent metadata or URI references to a project, product, artifact, distribution or a component. If set to false, the package must not contain any files.
69+
/// </summary>
70+
public bool? FilesAnalyzed { get; set; }
71+
72+
/// <summary>
73+
/// Indicates that a particular file belongs to a package.
74+
/// </summary>
75+
public List<string> HasFiles { get; set; }
76+
77+
public string Homepage { get; set; }
78+
79+
/// <summary>
80+
/// The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.
81+
/// </summary>
82+
public string LicenseComments { get; set; }
83+
84+
/// <summary>
85+
/// License expression for licenseConcluded. The licensing that the preparer of this SPDX document has concluded, based on the evidence, actually applies to the package.
86+
/// </summary>
87+
public string LicenseConcluded { get; set; }
88+
89+
/// <summary>
90+
/// License expression for licenseDeclared. The licensing that the creators of the software in the package, or the packager, have declared. Declarations by the original software creator should be preferred, if they exist.
91+
/// </summary>
92+
public string LicenseDeclared { get; set; }
93+
94+
/// <summary>
95+
/// The licensing information that was discovered directly within the package. There will be an instance of this property for each distinct value of alllicenseInfoInFile properties of all files contained in the package.
96+
/// </summary>
97+
public List<string> LicenseInfoFromFiles { get; set; }
98+
99+
/// <summary>
100+
/// Identify name of this SpdxElement.
101+
/// </summary>
102+
public string Name { get; set; }
103+
104+
/// <summary>
105+
/// The name and, optionally, contact information of the person or organization that originally created the package. Values of this property must conform to the agent and tool syntax.
106+
/// </summary>
107+
public string Originator { get; set; }
108+
109+
/// <summary>
110+
/// The base name of the package file name. For example, zlib-1.2.5.tar.gz.
111+
/// </summary>
112+
public string PackageFileName { get; set; }
113+
114+
/// <summary>
115+
/// A manifest based verification code (the algorithm is defined in section 4.7 of the full specification) of the SPDX Item. This allows consumers of this data and/or database to determine if an SPDX item they have in hand is identical to the SPDX item from which the data was produced. This algorithm works even if the SPDX document is included in the SPDX item.
116+
/// </summary>
117+
public PackageVerificationCode PackageVerificationCode { get; set; }
118+
119+
/// <summary>
120+
/// Allows the producer(s) of the SPDX document to describe how the package was acquired and/or changed from the original source.
121+
/// </summary>
122+
public string SourceInfo { get; set; }
123+
124+
/// <summary>
125+
/// Provides a short description of the package.
126+
/// </summary>
127+
public string Summary { get; set; }
128+
129+
/// <summary>
130+
/// The name and, optionally, contact information of the person or organization who was the immediate supplier of this package to the recipient. The supplier may be different than originator when the software has been repackaged. Values of this property must conform to the agent and tool syntax.
131+
/// </summary>
132+
public string Supplier { get; set; }
133+
134+
public string Comment { get; set; }
135+
136+
/// <summary>
137+
/// Provides an indication of the version of the package that is described by this SpdxDocument.
138+
/// </summary>
139+
public string VersionInfo { get; set; }
140+
}
141+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
21+
namespace CycloneDX.Spdx.Models.v2_2
22+
{
23+
public class PackageVerificationCode
24+
{
25+
/// <summary>
26+
/// A file that was excluded when calculating the package verification code. This is usually a file containing SPDX data regarding the package. If a package contains more than one SPDX file all SPDX files must be excluded from the package verification code. If this is not done it would be impossible to correctly calculate the verification codes in both files.
27+
/// </summary>
28+
public List<string> PackageVerificationCodeExcludedFiles { get; set; }
29+
30+
/// <summary>
31+
/// The actual package verification code as a hex encoded value.
32+
/// </summary>
33+
public string PackageVerificationCodeValue { get; set; }
34+
}
35+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class Range
23+
{
24+
public RangePointer EndPointer { get; set; } = new RangePointer();
25+
public RangePointer StartPointer { get; set; } = new RangePointer();
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class RangePointer
23+
{
24+
/// <summary>
25+
/// Byte offset in the file
26+
/// </summary>
27+
public int? Offset { get; set; }
28+
29+
/// <summary>
30+
/// line number offset in the file
31+
/// </summary>
32+
public int? LineNumber { get; set; }
33+
34+
/// <summary>
35+
/// SPDX ID for File
36+
/// </summary>
37+
public string Reference { get; set; }
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class Relationship
23+
{
24+
/// <summary>
25+
/// Id to which the SPDX element is related
26+
/// </summary>
27+
public string SpdxElementId { get; set; }
28+
29+
public string Comment { get; set; }
30+
31+
/// <summary>
32+
/// SPDX ID for SpdxElement. A related SpdxElement.
33+
/// </summary>
34+
public string RelatedSpdxElement { get; set; }
35+
36+
/// <summary>
37+
/// Describes the type of relationship between two SPDX elements.
38+
/// </summary>
39+
public RelationshipType RelationshipType { get; set; }
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public enum RelationshipType
23+
{
24+
VARIANT_OF,
25+
COPY_OF,
26+
PATCH_FOR,
27+
TEST_DEPENDENCY_OF,
28+
CONTAINED_BY,
29+
DATA_FILE_OF,
30+
OPTIONAL_COMPONENT_OF,
31+
ANCESTOR_OF,
32+
GENERATES,
33+
CONTAINS,
34+
OPTIONAL_DEPENDENCY_OF,
35+
FILE_ADDED,
36+
DEV_DEPENDENCY_OF,
37+
DEPENDENCY_OF,
38+
BUILD_DEPENDENCY_OF,
39+
DESCRIBES,
40+
PREREQUISITE_FOR,
41+
HAS_PREREQUISITE,
42+
PROVIDED_DEPENDENCY_OF,
43+
DYNAMIC_LINK,
44+
DESCRIBED_BY,
45+
METAFILE_OF,
46+
DEPENDENCY_MANIFEST_OF,
47+
PATCH_APPLIED,
48+
RUNTIME_DEPENDENCY_OF,
49+
TEST_OF,
50+
TEST_TOOL_OF,
51+
DEPENDS_ON,
52+
FILE_MODIFIED,
53+
DISTRIBUTION_ARTIFACT,
54+
DOCUMENTATION_OF,
55+
GENERATED_FROM,
56+
STATIC_LINK,
57+
OTHER,
58+
BUILD_TOOL_OF,
59+
TEST_CASE_OF,
60+
PACKAGE_OF,
61+
DESCENDANT_OF,
62+
FILE_DELETED,
63+
EXPANDED_FROM_ARCHIVE,
64+
DEV_TOOL_OF,
65+
EXAMPLE_OF,
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
20+
namespace CycloneDX.Spdx.Models.v2_2
21+
{
22+
public class ReviewInformation
23+
{
24+
/// <summary>
25+
/// The name and, optionally, contact information of the person who performed the review. Values of this property must conform to the agent and tool syntax.
26+
/// </summary>
27+
public string Reviewer { get; set; }
28+
29+
public string Comment { get; set; }
30+
31+
/// <summary>
32+
/// The date and time at which the SpdxDocument was reviewed. This value must be in UTC and have 'Z' as its timezone indicator.
33+
/// </summary>
34+
public DateTime ReviewDate { get; set; }
35+
36+
}
37+
}
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text.Json.Serialization;
21+
22+
namespace CycloneDX.Spdx.Models.v2_2
23+
{
24+
public class Snippet
25+
{
26+
/// <summary>
27+
/// Uniquely identify any element in an SPDX document which may be referenced by other elements.
28+
/// </summary>
29+
[JsonPropertyName("SPDXID")]
30+
public string SPDXID { get; set; }
31+
32+
public string Comment { get; set; }
33+
34+
/// <summary>
35+
/// The text of copyright declarations recited in the Package or File.
36+
/// </summary>
37+
public string CopyrightText { get; set; }
38+
39+
/// <summary>
40+
/// The licenseComments property allows the preparer of the SPDX document to describe why the licensing in spdx:licenseConcluded was chosen.
41+
/// </summary>
42+
public string LicenseComments { get; set; }
43+
44+
/// <summary>
45+
/// License expression for licenseConcluded. The licensing that the preparer of this SPDX document has concluded, based on the evidence, actually applies to the package.
46+
/// </summary>
47+
public string LicenseConcluded { get; set; }
48+
49+
/// <summary>
50+
/// Licensing information that was discovered directly in the subject snippet. This is also considered a declared license for the snippet.
51+
/// </summary>
52+
public List<string> LicenseInfoInSnippets { get; set; }
53+
54+
/// <summary>
55+
/// This field provides a place for the SPDX data creator to record acknowledgements that may be required to be communicated in some contexts. This is not meant to include theactual complete license text (see licenseConculded and licenseDeclared), and may or may not include copyright notices (see also copyrightText). The SPDX data creator may use this field to record other acknowledgements, such as particular clauses from license texts, which may be necessary or desirable to reproduce.
56+
/// </summary>
57+
public List<string> AttributionTexts { get; set; }
58+
59+
/// <summary>
60+
/// Identify name of this SpdxElement.
61+
/// </summary>
62+
public string Name { get; set; }
63+
64+
/// <summary>
65+
/// This field defines the byte range in the original host file (in X.2) that the snippet information applies to
66+
/// </summary>
67+
public List<Range> Ranges { get; set; }
68+
69+
/// <summary>
70+
/// SPDX ID for File. File containing the SPDX element (e.g. the file contaning a snippet).
71+
/// </summary>
72+
public string SnippetFromFile { get; set; }
73+
74+
/// <summary>
75+
/// Provide additional information about an SpdxElement.
76+
/// </summary>
77+
public List<Annotation> Annotations { get; set; }
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text.Json.Serialization;
21+
22+
namespace CycloneDX.Spdx.Models.v2_2
23+
{
24+
public class SpdxDocument
25+
{
26+
/// <summary>
27+
/// Uniquely identify any element in an SPDX document which may be referenced by other elements.
28+
/// </summary>
29+
[JsonPropertyName("SPDXID")]
30+
public string SPDXID { get; set; }
31+
32+
/// <summary>
33+
/// Provide a reference number that can be used to understand how to parse and interpret the rest of the file. It will enable both future changes to the specification and to support backward compatibility. The version number consists of a major and minor version indicator. The major field will be incremented when incompatible changes between versions are made (one or more sections are created, modified or deleted). The minor field will be incremented when backwards compatible changes are made.
34+
/// </summary>
35+
public string SpdxVersion { get; } = "SPDX-2.2";
36+
37+
/// <summary>
38+
/// One instance is required for each SPDX file produced. It provides the necessary information for forward and backward compatibility for processing tools.
39+
/// </summary>
40+
public CreationInfo CreationInfo { get; set; } = new CreationInfo();
41+
42+
/// <summary>
43+
/// Identify name of this SpdxElement.
44+
/// </summary>
45+
public string Name { get; set; }
46+
47+
/// <summary>
48+
/// License expression for dataLicense. Compliance with the SPDX specification includes populating the SPDX fields therein with data related to such fields ("SPDX-Metadata"). The SPDX specification contains numerous fields where an SPDX document creator may provide relevant explanatory text in SPDX-Metadata. Without opining on the lawfulness of "database rights" (in jurisdictions where applicable), such explanatory text is copyrightable subject matter in most Berne Convention countries. By using the SPDX specification, or any portion hereof, you hereby agree that any copyright rights (as determined by your jurisdiction) in any SPDX-Metadata, including without limitation explanatory text, shall be subject to the terms of the Creative Commons CC0 1.0 Universal license. For SPDX-Metadata not containing any copyright rights, you hereby agree and acknowledge that the SPDX-Metadata is provided to you "as-is" and without any representations or warranties of any kind concerning the SPDX-Metadata, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non-infringement, or the absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
49+
/// </summary>
50+
public string DataLicense { get; } = "CC0-1.0";
51+
52+
public string Comment { get; set; }
53+
54+
/// <summary>
55+
/// Identify any external SPDX documents referenced within this SPDX document.
56+
/// </summary>
57+
public List<ExternalDocumentRef> ExternalDocumentRefs { get; set; }
58+
59+
/// <summary>
60+
/// Indicates that a particular ExtractedLicensingInfo was defined in the subject SpdxDocument.
61+
/// </summary>
62+
public List<ExtractedLicensingInfo> HasExtractedLicensingInfos { get; set; }
63+
64+
/// <summary>
65+
/// Provide additional information about an SpdxElement.
66+
/// </summary>
67+
public List<Annotation> Annotations { get; set; }
68+
69+
/// <summary>
70+
/// Reviewed
71+
/// </summary>
72+
[Obsolete("Revieweds is deprecated, use Annotation instead")]
73+
public List<ReviewInformation> Revieweds { get; set; }
74+
75+
/// <summary>
76+
/// The URI provides an unambiguous mechanism for other SPDX documents to reference SPDX elements within this SPDX document.
77+
/// </summary>
78+
public string DocumentNamespace { get; set; }
79+
80+
/// <summary>
81+
/// Packages, files and/or Snippets described by this SPDX document
82+
/// </summary>
83+
public List<string> DocumentDescribes { get; set; }
84+
85+
/// <summary>
86+
/// Packages referenced in the SPDX document
87+
/// </summary>
88+
public List<Package> Packages { get; set; }
89+
90+
/// <summary>
91+
/// Files referenced in the SPDX document
92+
/// </summary>
93+
public List<File> Files { get; set; }
94+
95+
/// <summary>
96+
/// Snippets referenced in the SPDX document
97+
/// </summary>
98+
public List<Snippet> Snippets { get; set; }
99+
100+
/// <summary>
101+
/// Relationships referenced in the SPDX document
102+
/// </summary>
103+
public List<Relationship> Relationships { get; set; }
104+
}
105+
}

‎src/CycloneDX.Spdx/Schemas/spdx-2.2.json

+721
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Diagnostics.Contracts;
20+
using System.IO;
21+
using System.Text.Json;
22+
using System.Text.Json.Serialization;
23+
using System.Threading.Tasks;
24+
25+
namespace CycloneDX.Spdx.Serialization
26+
{
27+
public class JsonSerializer
28+
{
29+
// this is so we can "cache" the serialization options
30+
// instantiating a new instance each time tanks serialization performance
31+
private static JsonSerializerOptions _options_v2_2;
32+
33+
public static JsonSerializerOptions GetJsonSerializerOptions_v2_2()
34+
{
35+
var options = new JsonSerializerOptions
36+
{
37+
WriteIndented = true,
38+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
39+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
40+
};
41+
options.Converters.Add(new JsonStringEnumConverter());
42+
return options;
43+
}
44+
45+
public static string Serialize(Models.v2_2.SpdxDocument document)
46+
{
47+
if (_options_v2_2 is null) _options_v2_2 = GetJsonSerializerOptions_v2_2();
48+
return System.Text.Json.JsonSerializer.Serialize<Models.v2_2.SpdxDocument>(document, _options_v2_2);
49+
}
50+
51+
public static async Task SerializeAsync(Models.v2_2.SpdxDocument document, Stream outputStream)
52+
{
53+
Contract.Requires(document != null && outputStream != null);
54+
if (_options_v2_2 is null) _options_v2_2 = GetJsonSerializerOptions_v2_2();
55+
await System.Text.Json.JsonSerializer.SerializeAsync<Models.v2_2.SpdxDocument>(outputStream, document, _options_v2_2).ConfigureAwait(false);
56+
}
57+
58+
public static Models.v2_2.SpdxDocument Deserialize(string document)
59+
{
60+
if (_options_v2_2 is null) _options_v2_2 = GetJsonSerializerOptions_v2_2();
61+
return System.Text.Json.JsonSerializer.Deserialize<Models.v2_2.SpdxDocument>(document, _options_v2_2);
62+
}
63+
64+
public static async Task<Models.v2_2.SpdxDocument> DeserializeAsync(Stream jsonStream)
65+
{
66+
Contract.Requires(jsonStream != null);
67+
if (_options_v2_2 is null) _options_v2_2 = GetJsonSerializerOptions_v2_2();
68+
var doc = await System.Text.Json.JsonSerializer.DeserializeAsync<Models.v2_2.SpdxDocument>(jsonStream, _options_v2_2).ConfigureAwait(false);
69+
return doc;
70+
}
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.IO;
21+
using System.Reflection;
22+
using System.Text.Json;
23+
using System.Threading.Tasks;
24+
using Json.Schema;
25+
using CycloneDX.Spdx.Models;
26+
27+
namespace CycloneDX.Spdx.Validation
28+
{
29+
public class JsonValidator
30+
{
31+
/// <summary>
32+
/// Validate the stream contents represent a valid SPDX JSON document.
33+
/// </summary>
34+
/// <param name="jsonStream"></param>
35+
/// <param name="schemaVersion"></param>
36+
/// <returns></returns>
37+
public static async Task<ValidationResult> ValidateAsync(Stream jsonStream)
38+
{
39+
var assembly = typeof(JsonValidator).GetTypeInfo().Assembly;
40+
41+
using (var schemaStream = assembly.GetManifestResourceStream($"CycloneDX.Spdx.Schemas.spdx-2.2.json"))
42+
{
43+
var jsonSchema = await JsonSchema.FromStream(schemaStream).ConfigureAwait(false);
44+
var jsonDocument = await JsonDocument.ParseAsync(jsonStream).ConfigureAwait(false);
45+
return Validate(jsonSchema, jsonDocument);
46+
}
47+
}
48+
49+
/// <summary>
50+
/// Validate the string contents represent a valid SPDX JSON document.
51+
/// </summary>
52+
/// <param name="jsonString"></param>
53+
/// <returns></returns>
54+
public static ValidationResult Validate(string jsonString)
55+
{
56+
var assembly = typeof(JsonValidator).GetTypeInfo().Assembly;
57+
58+
using (var schemaStream = assembly.GetManifestResourceStream($"CycloneDX.Spdx.Schemas.spdx-2.2.json"))
59+
using (var schemaStreamReader = new StreamReader(schemaStream))
60+
{
61+
var jsonSchema = JsonSchema.FromText(schemaStreamReader.ReadToEnd());
62+
try
63+
{
64+
var jsonDocument = JsonDocument.Parse(jsonString);
65+
return Validate(jsonSchema, jsonDocument);
66+
}
67+
catch (JsonException exc)
68+
{
69+
return new ValidationResult
70+
{
71+
Valid = false,
72+
Messages = new List<string> { exc.Message }
73+
};
74+
}
75+
}
76+
}
77+
78+
private static ValidationResult Validate(JsonSchema schema, JsonDocument jsonDocument)
79+
{
80+
var validationMessages = new List<string>();
81+
var validationOptions = new ValidationOptions
82+
{
83+
OutputFormat = OutputFormat.Detailed,
84+
RequireFormatValidation = true
85+
};
86+
87+
var result = schema.Validate(jsonDocument.RootElement, validationOptions);
88+
89+
if (!result.IsValid)
90+
{
91+
validationMessages.Add($"Validation failed: {result.Message}");
92+
validationMessages.Add(result.SchemaLocation.ToString());
93+
94+
if (result.NestedResults != null)
95+
{
96+
var nestedResults = new Queue<ValidationResults>(result.NestedResults);
97+
98+
while (nestedResults.Count > 0)
99+
{
100+
var nestedResult = nestedResults.Dequeue();
101+
102+
if (
103+
!string.IsNullOrEmpty(nestedResult.Message)
104+
&& nestedResult.NestedResults != null
105+
&& nestedResult.NestedResults.Count > 0)
106+
{
107+
validationMessages.Add($"{nestedResult.InstanceLocation}: {nestedResult.Message}");
108+
}
109+
110+
if (nestedResult.NestedResults != null)
111+
{
112+
foreach (var newNestedResult in nestedResult.NestedResults)
113+
{
114+
nestedResults.Enqueue(newNestedResult);
115+
}
116+
}
117+
}
118+
}
119+
}
120+
121+
return new ValidationResult
122+
{
123+
Valid = validationMessages.Count == 0,
124+
Messages = validationMessages
125+
};
126+
}
127+
}
128+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
12+
<PackageReference Include="Snapshooter.Xunit" Version="0.7.1" />
13+
<PackageReference Include="xunit" Version="2.4.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="3.1.0">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<Content Include="Resources\**" CopyToOutputDirectory="Always" />
26+
<Content Include="__snapshots__\**" CopyToOutputDirectory="Always" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\..\src\CycloneDX.Spdx\CycloneDX.Spdx.csproj" />
31+
</ItemGroup>
32+
33+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.IO;
20+
using System.Threading.Tasks;
21+
using Xunit;
22+
using Snapshooter;
23+
using Snapshooter.Xunit;
24+
using CycloneDX.Spdx.Serialization;
25+
26+
namespace CycloneDX.Spdx.Tests;
27+
28+
public class JsonSerializerTests
29+
{
30+
[Theory]
31+
[InlineData("document")]
32+
public void JsonRoundTripTest(string baseFilename)
33+
{
34+
var resourceFilename = Path.Join("Resources", "v2.2", baseFilename + ".json");
35+
var document = File.ReadAllText(resourceFilename);
36+
37+
var spdxDocument = JsonSerializer.Deserialize(document);
38+
var result = JsonSerializer.Serialize(spdxDocument);
39+
40+
Snapshot.Match(result, SnapshotNameExtension.Create(baseFilename));
41+
}
42+
43+
[Theory]
44+
[InlineData("document")]
45+
public async Task JsonAsyncRoundTripTest(string baseFilename)
46+
{
47+
var resourceFilename = Path.Join("Resources", "v2.2", baseFilename + ".json");
48+
49+
using (var jsonStream = File.OpenRead(resourceFilename))
50+
using (var outputStream = new MemoryStream())
51+
{
52+
var spdxDocument = await JsonSerializer.DeserializeAsync(jsonStream);
53+
await JsonSerializer.SerializeAsync(spdxDocument, outputStream);
54+
var result = System.Text.Encoding.UTF8.GetString(outputStream.ToArray());
55+
Snapshot.Match(result, SnapshotNameExtension.Create(baseFilename));
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This file is part of CycloneDX Library for .NET
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the “License”);
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an “AS IS” BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0
16+
// Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
using System;
19+
using System.IO;
20+
using System.Threading.Tasks;
21+
using Xunit;
22+
using Snapshooter;
23+
using Snapshooter.Xunit;
24+
using CycloneDX.Spdx.Validation;
25+
26+
namespace CycloneDX.Spdx.Tests;
27+
28+
public class JsonValidatorTests
29+
{
30+
[Theory]
31+
[InlineData("document")]
32+
public void ValidateJsonStringTest(string baseFilename)
33+
{
34+
var resourceFilename = Path.Join("Resources", "v2.2", baseFilename + ".json");
35+
var document = File.ReadAllText(resourceFilename);
36+
37+
var result = JsonValidator.Validate(document);
38+
39+
Assert.True(result.Valid);
40+
}
41+
42+
[Theory]
43+
[InlineData("document")]
44+
public async Task ValidateJsonStreamTest(string baseFilename)
45+
{
46+
var resourceFilename = Path.Join("Resources", "v2.2", baseFilename + ".json");
47+
using (var jsonStream = File.OpenRead(resourceFilename))
48+
{
49+
var validationResult = await JsonValidator.ValidateAsync(jsonStream).ConfigureAwait(false);
50+
51+
Assert.True(validationResult.Valid);
52+
}
53+
}
54+
}

‎tests/CycloneDX.Spdx.Tests/Resources/v2.2/document.json

+403
Large diffs are not rendered by default.

‎tests/CycloneDX.Spdx.Tests/__snapshots__/JsonSerializerTests.JsonAsyncRoundTripTest_document.snap

+403
Large diffs are not rendered by default.

‎tests/CycloneDX.Spdx.Tests/__snapshots__/JsonSerializerTests.JsonRoundTripTest_document.snap

+403
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.