Skip to content

Commit ce78c54

Browse files
authored
Merge pull request #60 from CycloneDX/spec-v1.4
2 parents 7b311a4 + 7a0e53b commit ce78c54

File tree

4 files changed

+50
-85
lines changed

4 files changed

+50
-85
lines changed

src/CycloneDX.WebTool/CycloneDX.WebTool.csproj

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

99
<ItemGroup>
10-
<PackageReference Include="CycloneDX.Utils" Version="4.2.0" />
11-
<PackageReference Include="CycloneDX.Spdx.Interop" Version="4.2.0" />
10+
<PackageReference Include="CycloneDX.Utils" Version="5.0.0" />
11+
<PackageReference Include="CycloneDX.Spdx.Interop" Version="5.0.0" />
1212
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
1313
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
1414
</ItemGroup>

src/CycloneDX.WebTool/Pages/Convert.razor

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@
6060
<label>
6161
Version (ignored for SPDX output)
6262
<select id="outputVersion" @bind="_outputVersion">
63-
<option value="v1.3" selected="selected">v1.3</option>
64-
<option value="v1.2">v1.2</option>
65-
<option value="v1.1">v1.1</option>
66-
<option value="v1.0">v1.0</option>
63+
<option value="v1_4" selected="selected">v1.4</option>
64+
<option value="v1_3">v1.3</option>
65+
<option value="v1_2">v1.2</option>
66+
<option value="v1_1">v1.1</option>
67+
<option value="v1_0">v1.0</option>
6768
</select>
6869
</label>
6970

@@ -75,7 +76,7 @@
7576
private string _userInputFilename;
7677
private string _inputFormat = "autodetect";
7778
private string _outputFormat = "json";
78-
private string _outputVersion = "v1.3";
79+
private string _outputVersion = "v1_4";
7980

8081
private async Task Alert(string message)
8182
{
@@ -102,7 +103,13 @@
102103

103104
private async Task ConvertBOM()
104105
{
105-
Models.v1_3.Bom bom;
106+
if (!Enum.TryParse(_outputVersion, out SpecificationVersion specificationVersion))
107+
{
108+
await Alert("Looks like you've hit a bug. This shouldn't happen, but there has been a problem reading the schema version.");
109+
return;
110+
}
111+
112+
Models.Bom bom;
106113
if (_inputFormat == "spdxjson" || _inputFormat == "autodetect" && _userInputFilename.EndsWith(".spdx.json"))
107114
{
108115
try
@@ -120,7 +127,7 @@
120127
{
121128
try
122129
{
123-
bom = Json.Deserializer.Deserialize(Encoding.UTF8.GetString(_inputFileContents));
130+
bom = Json.Serializer.Deserialize(Encoding.UTF8.GetString(_inputFileContents));
124131
}
125132
catch (Exception e)
126133
{
@@ -132,7 +139,7 @@
132139
{
133140
try
134141
{
135-
bom = Xml.Deserializer.Deserialize(Encoding.UTF8.GetString(_inputFileContents));
142+
bom = Xml.Serializer.Deserialize(Encoding.UTF8.GetString(_inputFileContents));
136143
}
137144
catch (Exception e)
138145
{
@@ -144,7 +151,7 @@
144151
{
145152
try
146153
{
147-
bom = Protobuf.Deserializer.Deserialize(_inputFileContents);
154+
bom = Protobuf.Serializer.Deserialize(_inputFileContents);
148155
}
149156
catch (Exception e)
150157
{
@@ -159,6 +166,8 @@
159166
}
160167

161168
byte[] output;
169+
170+
bom.SpecVersion = specificationVersion;
162171

163172
if (_outputFormat == "spdxjson")
164173
{
@@ -168,26 +177,20 @@
168177
}
169178
else if (_outputFormat == "json")
170179
{
171-
string stringOutput;
172-
if (_outputVersion == "v1.2")
173-
{
174-
var bom12 = new Models.v1_2.Bom(bom);
175-
stringOutput = Json.Serializer.Serialize(bom12);
176-
}
177-
else if (_outputVersion == "v1.1" || _outputVersion == "v1.0")
180+
if (bom.SpecVersion < SpecificationVersion.v1_2)
178181
{
179182
await Alert("Invalid version specified for JSON output. JSON output is only supported for versions >= 1.2");
180183
return;
181184
}
182185
else
183186
{
184-
stringOutput = Json.Serializer.Serialize(bom);
187+
var stringOutput = Json.Serializer.Serialize(bom);
188+
output = Encoding.UTF8.GetBytes(stringOutput);
185189
}
186-
output = Encoding.UTF8.GetBytes(stringOutput);
187190
}
188191
else if (_outputFormat == "bin")
189192
{
190-
if (_outputVersion == "v1.2" || _outputVersion == "v1.1" || _outputVersion == "v1.0")
193+
if (bom.SpecVersion < SpecificationVersion.v1_3)
191194
{
192195
await Alert("Invalid version specified for Protobuf output. Protobuf output is only supported for versions >= 1.3");
193196
return;
@@ -199,29 +202,7 @@
199202
}
200203
else
201204
{
202-
string stringOutput;
203-
if (_outputVersion == "v1.2")
204-
{
205-
var bom12 = new Models.v1_2.Bom(bom);
206-
stringOutput = Xml.Serializer.Serialize(bom12);
207-
}
208-
else if (_outputVersion == "v1.1")
209-
{
210-
var bom12 = new Models.v1_2.Bom(bom);
211-
var bom11 = new Models.v1_1.Bom(bom12);
212-
stringOutput = Xml.Serializer.Serialize(bom11);
213-
}
214-
else if (_outputVersion == "v1.0")
215-
{
216-
var bom12 = new Models.v1_2.Bom(bom);
217-
var bom11 = new Models.v1_1.Bom(bom12);
218-
var bom10 = new Models.v1_0.Bom(bom11);
219-
stringOutput = Xml.Serializer.Serialize(bom10);
220-
}
221-
else
222-
{
223-
stringOutput = Xml.Serializer.Serialize(bom);
224-
}
205+
var stringOutput = Xml.Serializer.Serialize(bom);
225206
output = Encoding.UTF8.GetBytes(stringOutput);
226207
}
227208

src/CycloneDX.WebTool/Pages/Merge.razor

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@
5757
<label>
5858
Version
5959
<select id="outputVersion" @bind="_outputVersion">
60-
<option value="v1.3" selected="selected">v1.3</option>
61-
<option value="v1.2">v1.2</option>
62-
<option value="v1.1">v1.1</option>
63-
<option value="v1.0">v1.0</option>
60+
<option value="v1_4" selected="selected">v1.4</option>
61+
<option value="v1_3">v1.3</option>
62+
<option value="v1_2">v1.2</option>
63+
<option value="v1_1">v1.1</option>
64+
<option value="v1_0">v1.0</option>
6465
</select>
6566
</label>
6667

@@ -72,7 +73,7 @@
7273
private List<string> _userInputFilenames;
7374
private string _inputFormat = "autodetect";
7475
private string _outputFormat = "json";
75-
private string _outputVersion = "v1.3";
76+
private string _outputVersion = "v1_4";
7677

7778
private async Task Alert(string message)
7879
{
@@ -104,18 +105,24 @@
104105

105106
private async Task MergeBOM()
106107
{
107-
Models.v1_3.Bom mergedBom = null;
108+
if (!Enum.TryParse(_outputVersion, out SpecificationVersion specificationVersion))
109+
{
110+
await Alert("Looks like you've hit a bug. This shouldn't happen, but there has been a problem reading the schema version.");
111+
return;
112+
}
113+
114+
Models.Bom mergedBom = null;
108115
for (var i = 0; i < _inputFileContents.Count; i++)
109116
{
110117
var fileContents = _inputFileContents[i];
111118
var filename = _userInputFilenames[i];
112-
Models.v1_3.Bom currentBom = null;
119+
Models.Bom currentBom = null;
113120

114121
if (_inputFormat == "json" || _inputFormat == "autodetect" && filename.EndsWith(".json"))
115122
{
116123
try
117124
{
118-
currentBom = Json.Deserializer.Deserialize(Encoding.UTF8.GetString(fileContents));
125+
currentBom = Json.Serializer.Deserialize(Encoding.UTF8.GetString(fileContents));
119126
}
120127
catch (Exception e)
121128
{
@@ -127,7 +134,7 @@
127134
{
128135
try
129136
{
130-
currentBom = Xml.Deserializer.Deserialize(Encoding.UTF8.GetString(fileContents));
137+
currentBom = Xml.Serializer.Deserialize(Encoding.UTF8.GetString(fileContents));
131138
}
132139
catch (Exception e)
133140
{
@@ -139,7 +146,7 @@
139146
{
140147
try
141148
{
142-
currentBom = Protobuf.Deserializer.Deserialize(fileContents);
149+
currentBom = Protobuf.Serializer.Deserialize(fileContents);
143150
}
144151
catch (Exception e)
145152
{
@@ -165,14 +172,11 @@
165172

166173
byte[] output;
167174

175+
mergedBom.SpecVersion = specificationVersion;
176+
168177
if (_outputFormat == "json")
169178
{
170-
if (_outputVersion == "v1.2")
171-
{
172-
var bom12 = new Models.v1_2.Bom(mergedBom);
173-
output = Encoding.UTF8.GetBytes(Json.Serializer.Serialize(bom12));
174-
}
175-
else if (_outputVersion == "v1.1" || _outputVersion == "v1.0")
179+
if (mergedBom.SpecVersion < SpecificationVersion.v1_2)
176180
{
177181
await Alert("Invalid version specified for JSON output. JSON output is only supported for versions >= 1.2");
178182
return;
@@ -184,7 +188,7 @@
184188
}
185189
else if (_outputFormat == "bin")
186190
{
187-
if (_outputVersion == "v1.2" || _outputVersion == "v1.1" || _outputVersion == "v1.0")
191+
if (mergedBom.SpecVersion < SpecificationVersion.v1_3)
188192
{
189193
await Alert("Invalid version specified for Protobuf output. Protobuf output is only supported for versions >= 1.3");
190194
return;
@@ -196,28 +200,7 @@
196200
}
197201
else
198202
{
199-
if (_outputVersion == "v1.2")
200-
{
201-
var bom12 = new Models.v1_2.Bom(mergedBom);
202-
output = Encoding.UTF8.GetBytes(Xml.Serializer.Serialize(bom12));
203-
}
204-
else if (_outputVersion == "v1.1")
205-
{
206-
var bom12 = new Models.v1_2.Bom(mergedBom);
207-
var bom11 = new Models.v1_1.Bom(bom12);
208-
output = Encoding.UTF8.GetBytes(Xml.Serializer.Serialize(bom11));
209-
}
210-
else if (_outputVersion == "v1.0")
211-
{
212-
var bom12 = new Models.v1_2.Bom(mergedBom);
213-
var bom11 = new Models.v1_1.Bom(bom12);
214-
var bom10 = new Models.v1_0.Bom(bom11);
215-
output = Encoding.UTF8.GetBytes(Xml.Serializer.Serialize(bom10));
216-
}
217-
else
218-
{
219-
output = Encoding.UTF8.GetBytes(Xml.Serializer.Serialize(mergedBom));
220-
}
203+
output = Encoding.UTF8.GetBytes(Xml.Serializer.Serialize(mergedBom));
221204
}
222205

223206
var outputBom64 = System.Convert.ToBase64String(output);

src/CycloneDX.WebTool/Pages/Validate.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
<label>
4646
Version
4747
<select id="inputVersion" @bind="_inputVersion">
48-
<option value="v1_3" selected="selected">v1.3</option>
48+
<option value="v1_4" selected="selected">v1.4</option>
49+
<option value="v1_3">v1.3</option>
4950
<option value="v1_2">v1.2</option>
5051
<option value="v1_1">v1.1</option>
5152
<option value="v1_0">v1.0</option>
@@ -61,7 +62,7 @@
6162
private string _inputFileContents;
6263
private string _userInputFilename;
6364
private string _inputFormat = "autodetect";
64-
private string _inputVersion = "v1_3";
65+
private string _inputVersion = "v1_4";
6566
private string _validationMessage = "";
6667

6768
private async Task Alert(string message)

0 commit comments

Comments
 (0)