|
22 | 22 | @using CycloneDX.Models |
23 | 23 | @using CycloneDX.Xml |
24 | 24 | @using CycloneDX.Json |
| 25 | +@using CycloneDX.Spdx.Interop |
25 | 26 |
|
26 | 27 | @inject IJSRuntime _jsRuntime; |
27 | 28 |
|
|
42 | 43 | <option value="json">JSON</option> |
43 | 44 | <option value="xml">XML</option> |
44 | 45 | <option value="bin">Protobuf</option> |
| 46 | + <option value="spdxjson">SPDX JSON</option> |
45 | 47 | </select> |
46 | 48 | </label> |
47 | 49 |
|
|
51 | 53 | <option value="json" selected="selected">JSON</option> |
52 | 54 | <option value="xml">XML</option> |
53 | 55 | <option value="bin">Protobuf</option> |
| 56 | + <option value="spdxjson">SPDX JSON</option> |
54 | 57 | </select> |
55 | 58 | </label> |
56 | 59 |
|
57 | 60 | <label> |
58 | | - Version |
| 61 | + Version (ignored for SPDX output) |
59 | 62 | <select id="outputVersion" @bind="_outputVersion"> |
60 | 63 | <option value="v1.3" selected="selected">v1.3</option> |
61 | 64 | <option value="v1.2">v1.2</option> |
|
100 | 103 | private async Task ConvertBOM() |
101 | 104 | { |
102 | 105 | 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")) |
104 | 120 | { |
105 | 121 | try |
106 | 122 | { |
|
144 | 160 |
|
145 | 161 | byte[] output; |
146 | 162 |
|
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") |
148 | 170 | { |
149 | 171 | string stringOutput; |
150 | 172 | if (_outputVersion == "v1.2") |
|
205 | 227 |
|
206 | 228 | var outputBom64 = System.Convert.ToBase64String(output); |
207 | 229 |
|
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); |
209 | 232 | } |
210 | 233 | } |
0 commit comments