diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/Advisory.cs b/src/CycloneDX.Core/Models/Vulnerabilities/Advisory.cs index 267cb4fa..651dff62 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/Advisory.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/Advisory.cs @@ -15,13 +15,14 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (c) OWASP Foundation. All Rights Reserved. +using System; using System.Xml.Serialization; using ProtoBuf; namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class Advisory + public class Advisory : IEquatable { [XmlElement("title")] [ProtoMember(1)] @@ -30,5 +31,19 @@ public class Advisory [XmlElement("url")] [ProtoMember(2)] public string Url { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as Advisory); + } + + public bool Equals(Advisory obj) + { + return obj != null && + (object.ReferenceEquals(this.Title, obj.Title) || + this.Title.Equals(obj.Title, StringComparison.InvariantCultureIgnoreCase)) && + (object.ReferenceEquals(this.Url, obj.Url) || + this.Url.Equals(obj.Url, StringComparison.InvariantCultureIgnoreCase)) ; + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/AffectedVersions.cs b/src/CycloneDX.Core/Models/Vulnerabilities/AffectedVersions.cs index f0fc31bc..f8a4a981 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/AffectedVersions.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/AffectedVersions.cs @@ -15,13 +15,14 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (c) OWASP Foundation. All Rights Reserved. +using System; using System.Xml.Serialization; using ProtoBuf; namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class AffectedVersions + public class AffectedVersions : IEquatable { [XmlElement("version")] [ProtoMember(1)] @@ -34,5 +35,20 @@ public class AffectedVersions [XmlElement("status")] [ProtoMember(3)] public Status Status { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as AffectedVersions); + } + + public bool Equals(AffectedVersions obj) + { + return obj != null && + (object.ReferenceEquals(this.Range, obj.Range) || + this.Range.Equals(obj.Range, StringComparison.InvariantCultureIgnoreCase)) && + (this.Status.Equals(obj.Status)) && + (object.ReferenceEquals(this.Version, obj.Version) || + this.Version.Equals(obj.Version, StringComparison.InvariantCultureIgnoreCase)); + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/Affects.cs b/src/CycloneDX.Core/Models/Vulnerabilities/Affects.cs index 3dfe543e..a8e46b8b 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/Affects.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/Affects.cs @@ -15,7 +15,9 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (c) OWASP Foundation. All Rights Reserved. +using System; using System.Collections.Generic; +using System.Linq; using System.Text.Json.Serialization; using System.Xml.Serialization; using ProtoBuf; @@ -23,7 +25,7 @@ namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class Affects + public class Affects : IEquatable { [XmlElement("ref")] [ProtoMember(1)] @@ -34,5 +36,19 @@ public class Affects [JsonPropertyName("versions")] [ProtoMember(2)] public List Versions { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as Affects); + } + + public bool Equals(Affects obj) + { + return obj != null && + (object.ReferenceEquals(this.Ref, obj.Ref) || + this.Ref.Equals(obj.Ref)) && + (object.ReferenceEquals(this.Versions, obj.Versions) || + this.Versions.SequenceEqual(obj.Versions)); + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/Analysis.cs b/src/CycloneDX.Core/Models/Vulnerabilities/Analysis.cs index c0411f46..c3056ffd 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/Analysis.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/Analysis.cs @@ -23,7 +23,7 @@ namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class Analysis + public class Analysis : IEquatable { [XmlElement("state")] [ProtoMember(1)] @@ -61,5 +61,23 @@ public DateTime? LastUpdated set { _lastUpdated = BomUtils.UtcifyDateTime(value); } } public bool ShouldSerializeLastUpdated() { return LastUpdated != null; } + + + public override bool Equals(object obj) + { + return Equals(obj as Analysis); + } + + public bool Equals(Analysis obj) + { + return obj != null && + (object.ReferenceEquals(this.Detail, obj.Detail) || + this.Detail.Equals(obj.Detail, StringComparison.InvariantCultureIgnoreCase)) && + (this.FirstIssued.Equals(obj.FirstIssued)) && + (this.Justification.Equals(obj.Justification)) && + (this.LastUpdated.Equals(obj.LastUpdated)) && + (this.Response.Equals(obj.Response)) && + (this.State.Equals(obj.State)); + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/Credits.cs b/src/CycloneDX.Core/Models/Vulnerabilities/Credits.cs index 93603711..0ccf5007 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/Credits.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/Credits.cs @@ -15,14 +15,16 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (c) OWASP Foundation. All Rights Reserved. +using System; using System.Collections.Generic; +using System.Linq; using System.Xml.Serialization; using ProtoBuf; namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class Credits + public class Credits : IEquatable { [XmlArray("organizations")] [XmlArrayItem("organization")] @@ -33,5 +35,19 @@ public class Credits [XmlArrayItem("individual")] [ProtoMember(2)] public List Individuals { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as Credits); + } + + public bool Equals(Credits obj) + { + return obj != null && + (object.ReferenceEquals(this.Individuals, obj.Individuals) || + this.Individuals.SequenceEqual(obj.Individuals)) && + (object.ReferenceEquals(this.Organizations, obj.Organizations) || + this.Organizations.SequenceEqual(obj.Organizations)); + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/ProofOfConcept.cs b/src/CycloneDX.Core/Models/Vulnerabilities/ProofOfConcept.cs index 9017d166..21d68d7f 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/ProofOfConcept.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/ProofOfConcept.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text.Json.Serialization; using System.Xml.Serialization; using ProtoBuf; @@ -24,7 +25,7 @@ namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class ProofOfConcept + public class ProofOfConcept : IEquatable { [XmlElement("reproductionSteps")] [ProtoMember(1)] @@ -39,5 +40,21 @@ public class ProofOfConcept [JsonPropertyName("supportingMaterial")] [ProtoMember(3)] public List SupportingMaterials { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as ProofOfConcept); + } + + public bool Equals(ProofOfConcept obj) + { + return obj != null && + (object.ReferenceEquals(this.Environment, obj.Environment) || + this.Environment.Equals(obj.Environment, StringComparison.InvariantCultureIgnoreCase)) && + (object.ReferenceEquals(this.ReproductionSteps, obj.ReproductionSteps) || + this.ReproductionSteps.Equals(obj.ReproductionSteps, StringComparison.InvariantCultureIgnoreCase)) && + (object.ReferenceEquals(this.SupportingMaterials, obj.SupportingMaterials) || + this.SupportingMaterials.SequenceEqual(obj.SupportingMaterials)); + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/Rating.cs b/src/CycloneDX.Core/Models/Vulnerabilities/Rating.cs index acb2be22..fa09f043 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/Rating.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/Rating.cs @@ -15,13 +15,14 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (c) OWASP Foundation. All Rights Reserved. +using System; using System.Xml.Serialization; using ProtoBuf; namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class Rating + public class Rating : IEquatable { [XmlElement("source")] [ProtoMember(1)] @@ -46,5 +47,24 @@ public class Rating [XmlElement("justification")] [ProtoMember(6)] public string Justification { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as Rating); + } + + public bool Equals(Rating obj) + { + return obj != null && + (object.ReferenceEquals(this.Justification, obj.Justification) || + this.Justification.Equals(obj.Justification, StringComparison.InvariantCultureIgnoreCase)) && + (this.Method.Equals(obj.Method)) && + (this.Score.Equals(obj.Score)) && + (this.Severity.Equals(obj.Severity)) && + (object.ReferenceEquals(this.Source, obj.Source) || + this.Source.Equals(obj.Source)) && + (object.ReferenceEquals(this.Vector, obj.Vector) || + this.Vector.Equals(obj.Vector, StringComparison.InvariantCultureIgnoreCase)); + } } } diff --git a/src/CycloneDX.Core/Models/Vulnerabilities/Reference.cs b/src/CycloneDX.Core/Models/Vulnerabilities/Reference.cs index 53a0aa16..a23c7ddf 100644 --- a/src/CycloneDX.Core/Models/Vulnerabilities/Reference.cs +++ b/src/CycloneDX.Core/Models/Vulnerabilities/Reference.cs @@ -15,13 +15,14 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (c) OWASP Foundation. All Rights Reserved. +using System; using System.Xml.Serialization; using ProtoBuf; namespace CycloneDX.Models.Vulnerabilities { [ProtoContract] - public class Reference + public class Reference : IEquatable { [XmlElement("id")] [ProtoMember(1)] @@ -30,5 +31,19 @@ public class Reference [XmlElement("source")] [ProtoMember(2)] public Source Source { get; set; } + + public override bool Equals(object obj) + { + return Equals(obj as Reference); + } + + public bool Equals(Reference obj) + { + return obj != null && + (object.ReferenceEquals(this.Id, obj.Id) || + this.Id.Equals(obj.Id, StringComparison.InvariantCultureIgnoreCase)) && + (object.ReferenceEquals(this.Source, obj.Source) || + this.Source.Equals(obj.Source)); + } } }