Skip to content

Commit

Permalink
#349 FInished off implementing equals checks
Browse files Browse the repository at this point in the history
Signed-off-by: James Thompson <thompson.tomo@outlook.com>
  • Loading branch information
thompson-tomo committed Sep 8, 2024
1 parent 02aeda7 commit 77cc9f8
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Advisory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Advisory>
{
[XmlElement("title")]
[ProtoMember(1)]
Expand All @@ -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)) ;
}
}
}
18 changes: 17 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/AffectedVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AffectedVersions>
{
[XmlElement("version")]
[ProtoMember(1)]
Expand All @@ -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));
}
}
}
18 changes: 17 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Affects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
// 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;

namespace CycloneDX.Models.Vulnerabilities
{
[ProtoContract]
public class Affects
public class Affects : IEquatable<Affects>
{
[XmlElement("ref")]
[ProtoMember(1)]
Expand All @@ -34,5 +36,19 @@ public class Affects
[JsonPropertyName("versions")]
[ProtoMember(2)]
public List<AffectedVersions> 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));
}
}
}
20 changes: 19 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Analysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace CycloneDX.Models.Vulnerabilities
{
[ProtoContract]
public class Analysis
public class Analysis : IEquatable<Analysis>
{
[XmlElement("state")]
[ProtoMember(1)]
Expand Down Expand Up @@ -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));
}
}
}
18 changes: 17 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Credits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Credits>
{
[XmlArray("organizations")]
[XmlArrayItem("organization")]
Expand All @@ -33,5 +35,19 @@ public class Credits
[XmlArrayItem("individual")]
[ProtoMember(2)]
public List<OrganizationalContact> 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));
}
}
}
19 changes: 18 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/ProofOfConcept.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

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

namespace CycloneDX.Models.Vulnerabilities
{
[ProtoContract]
public class ProofOfConcept
public class ProofOfConcept : IEquatable<ProofOfConcept>
{
[XmlElement("reproductionSteps")]
[ProtoMember(1)]
Expand All @@ -39,5 +40,21 @@ public class ProofOfConcept
[JsonPropertyName("supportingMaterial")]
[ProtoMember(3)]
public List<AttachedText> 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));
}
}
}
22 changes: 21 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Rating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rating>
{
[XmlElement("source")]
[ProtoMember(1)]
Expand All @@ -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));
}
}
}
17 changes: 16 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Reference>
{
[XmlElement("id")]
[ProtoMember(1)]
Expand All @@ -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));
}
}
}

0 comments on commit 77cc9f8

Please sign in to comment.