Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CycloneDX.Core/Models/Algorithms/AlgorithmProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models;
using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -58,10 +59,12 @@ public bool ShouldSerializePrimitive_XML()
[XmlElement("executionEnvironment")]
[ProtoMember(4)]
public ExecutionEnvironment? ExecutionEnvironment { get; set; }
public bool ShouldSerializeExecutionEnvironment() { return ExecutionEnvironment.HasValue && ExecutionEnvironment.Value != Models.ExecutionEnvironment.Null; }

[XmlElement("implementationPlatform")]
[ProtoMember(5)]
public ImplementationPlatform? ImplementationPlatform { get; set; }
public bool ShouldSerializeImplementationPlatform() { return ImplementationPlatform.HasValue && ImplementationPlatform.Value != Models.ImplementationPlatform.Null; }

[XmlElement("certificationLevel")]
public List<CertificationLevel> CertificationLevel { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/CycloneDX.Core/Models/Crypto/CryptoProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Net.Sockets;
using System.Text;
Expand All @@ -28,8 +29,10 @@ namespace CycloneDX.Core.Models
public class CryptoProperties
{
[XmlElement("assetType")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1)]
public AssetType AssetType { get; set; }
public bool ShouldSerializeAssetType() { return AssetType != AssetType.Null; }

[XmlElement("algorithmProperties")]
[ProtoMember(2)]
Expand Down
3 changes: 3 additions & 0 deletions src/CycloneDX.Core/Models/Crypto/ProtocolProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
Expand All @@ -26,8 +27,10 @@ namespace CycloneDX.Core.Models
public class ProtocolProperties
{
[XmlElement("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1)]
public ProtocolType Type { get; set; }
public bool ShouldSerializeType() { return Type != ProtocolType.Null; }

[XmlElement("version")]
[ProtoMember(2)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,34 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models;
using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using CycloneDX.Models;

namespace CycloneDX.Core.Models
{
[ProtoContract]
public class RelatedCryptoMaterialProperties
{
[XmlElement("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1)]
public RelatedCryptoMaterialType Type { get; set; }
public bool ShouldSerializeType() { return Type != RelatedCryptoMaterialType.Null; }

[XmlElement("id")]
[ProtoMember(2)]
public string Id { get; set; }

[XmlElement("state")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(3)]
public KeyState State { get; set; }
public bool ShouldSerializeState() { return State != KeyState.Null; }

[XmlElement("algorithmRef")]
[ProtoMember(4)]
Expand Down
5 changes: 4 additions & 1 deletion src/CycloneDX.Core/Models/DataClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand All @@ -28,8 +29,10 @@ namespace CycloneDX.Models
public class DataClassification
{
[XmlAttribute("flow")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1, IsRequired=true)]
public DataFlowDirection Flow { get; set; }
public bool ShouldSerializeFlow() { return Flow != DataFlowDirection.Null; }

[XmlText]
[ProtoMember(2)]
Expand Down
5 changes: 4 additions & 1 deletion src/CycloneDX.Core/Models/DataFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand All @@ -29,8 +30,10 @@ public class DataFlow
{
[XmlIgnore]
[JsonPropertyName("flow")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1, IsRequired=true)]
public DataFlowDirection Flow { get; set; }
public bool ShouldSerializeFlow() { return Flow != DataFlowDirection.Null; }

[XmlIgnore]
[JsonPropertyName("classification")]
Expand Down
4 changes: 4 additions & 0 deletions src/CycloneDX.Core/Models/EnergyConsumption/Co2Measure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace CycloneDX.Models
Expand All @@ -28,7 +30,9 @@ public class Co2Measure
public float Value { get; set; }

[XmlElement("unit")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(2)]
public CO2Unit Unit { get; set; }
public bool ShouldSerializeUnit() { return Unit != CO2Unit.Null; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace CycloneDX.Models
Expand All @@ -27,8 +29,10 @@ namespace CycloneDX.Models
public class EnergyConsumption
{
[XmlElement("activity")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1)]
public ActivityType Activity { get; set; }
public bool ShouldSerializeActivity() { return Activity != ActivityType.Null; }

[XmlElement("energyProviders")]
[ProtoMember(2)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace CycloneDX.Models
Expand All @@ -28,7 +30,9 @@ public class EnergyMeasure
public float Value { get; set; }

[XmlElement("unit")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(2)]
public EnergyUnit Unit { get; set; }
public bool ShouldSerializeUnit() { return Unit != EnergyUnit.Null; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace CycloneDX.Models
Expand All @@ -33,8 +35,10 @@ public class EnergyProvider
public OrganizationalEntity Organization { get; set; }

[XmlElement("energySource")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(4)]
public EnergySource EnergySource { get; set; }
public bool ShouldSerializeEnergySource() { return EnergySource != EnergySource.Null; }

[XmlElement("energyProvided")]
[ProtoMember(5)]
Expand Down
5 changes: 4 additions & 1 deletion src/CycloneDX.Core/Models/EvidenceIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -23,7 +25,6 @@
using System.Text.Json.Serialization;
using System.Xml;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand Down Expand Up @@ -58,8 +59,10 @@ public enum EvidenceFieldType
}

[XmlElement("field")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1)]
public EvidenceFieldType Field { get; set; }
public bool ShouldSerializeField() { return Field != EvidenceFieldType.Null; }

[XmlElement("confidence")]
[ProtoMember(2)]
Expand Down
8 changes: 6 additions & 2 deletions src/CycloneDX.Core/Models/Hash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using System.Xml.Serialization;
using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace CycloneDX.Models
{
Expand Down Expand Up @@ -60,9 +62,11 @@ public enum HashAlgorithm
}

[XmlAttribute("alg")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1, IsRequired=true)]
public HashAlgorithm Alg { get; set; }

public bool ShouldSerializeAlg() { return Alg != HashAlgorithm.Null; }

[XmlText]
[ProtoMember(2)]
public string Content { get; set; }
Expand Down
6 changes: 5 additions & 1 deletion src/CycloneDX.Core/Models/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand All @@ -38,8 +40,10 @@ public enum IssueClassification
}

[XmlAttribute("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1, IsRequired=true)]
public IssueClassification Type { get; set; }
public bool ShouldSerializeType() { return Type != IssueClassification.Null; }

[XmlElement("id")]
[ProtoMember(2)]
Expand Down
2 changes: 1 addition & 1 deletion src/CycloneDX.Core/Models/LicenseChoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class LicenseChoice
[XmlAttribute("acknowledgement")]
[ProtoMember(3)]
public LicenseAcknowledgementEnumeration? Acknowledgement { get; set; }
public bool ShouldSerializeAcknowledgement() { return Acknowledgement.HasValue; }
public bool ShouldSerializeAcknowledgement() { return Acknowledgement.HasValue && Acknowledgement.Value != LicenseAcknowledgementEnumeration.Null; }

[JsonPropertyName("expressionDetails")]
[XmlIgnore]
Expand Down
6 changes: 5 additions & 1 deletion src/CycloneDX.Core/Models/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand All @@ -40,8 +42,10 @@ public enum PatchClassification
}

[XmlAttribute("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(1, IsRequired=true)]
public PatchClassification Type { get; set; }
public bool ShouldSerializeType() { return Type != PatchClassification.Null; }

[XmlElement("diff")]
[ProtoMember(2)]
Expand Down
5 changes: 4 additions & 1 deletion src/CycloneDX.Core/Models/Patent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand Down Expand Up @@ -163,8 +164,10 @@ public string PatentExpirationDate
public bool ShouldSerializePatentExpirationDate() { return PatentExpirationDate != null; }

[XmlElement("patentLegalStatus")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(12)]
public PatentLegalStatus PatentLegalStatus { get; set; }
public bool ShouldSerializePatentLegalStatus() { return PatentLegalStatus != PatentLegalStatus.Null; }

[XmlElement("patentAssignee")]
[ProtoMember(13)]
Expand Down
5 changes: 4 additions & 1 deletion src/CycloneDX.Core/Models/PatentAssertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;

namespace CycloneDX.Models
{
Expand All @@ -31,8 +32,10 @@ public class PatentAssertion
public string BomRef { get; set; }

[XmlElement("assertionType")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[ProtoMember(2)]
public PatentAssertionType AssertionType { get; set; }
public bool ShouldSerializeAssertionType() { return AssertionType != PatentAssertionType.Null; }

[XmlArray("patentRefs")]
[XmlArrayItem("bom-ref")]
Expand Down
Loading