Skip to content

Commit 8791310

Browse files
authored
Merge pull request #59 from CycloneDX/spdx
2 parents 32c6f6e + 40ba65c commit 8791310

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

local-build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#!/usr/bin/env bash
22
dotnet publish --configuration Release --output ./gh-pages src/CycloneDX.WebTool
3+
cd gh-pages/wwwroot
4+
python3 -m http.server 8000

src/CycloneDX.WebTool/CycloneDX.WebTool.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="CycloneDX.Utils" Version="4.0.0" />
10+
<PackageReference Include="CycloneDX.Utils" Version="4.2.0" />
11+
<PackageReference Include="CycloneDX.Spdx.Interop" Version="4.2.0" />
1112
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
1213
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
1314
</ItemGroup>

src/CycloneDX.WebTool/Pages/Convert.razor

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@using CycloneDX.Models
2323
@using CycloneDX.Xml
2424
@using CycloneDX.Json
25+
@using CycloneDX.Spdx.Interop
2526

2627
@inject IJSRuntime _jsRuntime;
2728

@@ -42,6 +43,7 @@
4243
<option value="json">JSON</option>
4344
<option value="xml">XML</option>
4445
<option value="bin">Protobuf</option>
46+
<option value="spdxjson">SPDX JSON</option>
4547
</select>
4648
</label>
4749

@@ -51,11 +53,12 @@
5153
<option value="json" selected="selected">JSON</option>
5254
<option value="xml">XML</option>
5355
<option value="bin">Protobuf</option>
56+
<option value="spdxjson">SPDX JSON</option>
5457
</select>
5558
</label>
5659

5760
<label>
58-
Version
61+
Version (ignored for SPDX output)
5962
<select id="outputVersion" @bind="_outputVersion">
6063
<option value="v1.3" selected="selected">v1.3</option>
6164
<option value="v1.2">v1.2</option>
@@ -100,7 +103,20 @@
100103
private async Task ConvertBOM()
101104
{
102105
Models.v1_3.Bom bom;
103-
if (_inputFormat == "json" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".json"))
106+
if (_inputFormat == "spdxjson" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".spdx.json"))
107+
{
108+
try
109+
{
110+
var spdxDoc = CycloneDX.Spdx.Serialization.JsonSerializer.Deserialize(Encoding.UTF8.GetString(_inputFileContents));
111+
bom = spdxDoc.ToCycloneDX();
112+
}
113+
catch (Exception e)
114+
{
115+
await Alert("Error deserializing BOM: " + e.Message);
116+
return;
117+
}
118+
}
119+
else if (_inputFormat == "json" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".json"))
104120
{
105121
try
106122
{
@@ -144,7 +160,13 @@
144160

145161
byte[] output;
146162

147-
if (_outputFormat == "json")
163+
if (_outputFormat == "spdxjson")
164+
{
165+
var spdxDoc = bom.ToSpdx();
166+
var stringOutput = CycloneDX.Spdx.Serialization.JsonSerializer.Serialize(spdxDoc);
167+
output = Encoding.UTF8.GetBytes(stringOutput);
168+
}
169+
else if (_outputFormat == "json")
148170
{
149171
string stringOutput;
150172
if (_outputVersion == "v1.2")
@@ -205,6 +227,7 @@
205227

206228
var outputBom64 = System.Convert.ToBase64String(output);
207229

208-
await _jsRuntime.InvokeVoidAsync("cdxFileDownload", Path.GetFileNameWithoutExtension(_userInputFilename) + "." + _outputFormat, outputBom64);
230+
var fileExtension = _outputFormat == "spdxjson" ? "spdx.json": _outputFormat;
231+
await _jsRuntime.InvokeVoidAsync("cdxFileDownload", Path.GetFileNameWithoutExtension(_userInputFilename) + "." + fileExtension, outputBom64);
209232
}
210233
}

0 commit comments

Comments
 (0)