Skip to content

Commit

Permalink
CycloneDX#349 replace serialization with actual checks
Browse files Browse the repository at this point in the history
Signed-off-by: James Thompson <[email protected]>
  • Loading branch information
thompson-tomo committed Sep 8, 2024
1 parent 9bed4fd commit 1e6f34a
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 7 deletions.
56 changes: 55 additions & 1 deletion src/CycloneDX.Core/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
Expand Down Expand Up @@ -240,7 +241,60 @@ public override bool Equals(object obj)

public bool Equals(Component obj)
{
return obj != null && Json.Serializer.Serialize(this) == Json.Serializer.Serialize(obj);
return obj != null &&
(object.ReferenceEquals(this.Author, obj.Author) ||
this.Author.Equals(obj.Author, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.BomRef, obj.BomRef) ||
this.BomRef.Equals(obj.BomRef, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Components, obj.Components) ||
this.Components.SequenceEqual(obj.Components)) &&
(object.ReferenceEquals(this.Copyright, obj.Copyright) ||
this.Copyright.Equals(obj.Copyright, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Cpe, obj.Cpe) ||
this.Cpe.Equals(obj.Cpe, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Data, obj.Data) ||
this.Data.Equals(obj.Data)) &&
(object.ReferenceEquals(this.Description, obj.Description) ||
this.Description.Equals(obj.Description, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Evidence, obj.Evidence) ||
this.Evidence.Equals(obj.Evidence)) &&
(object.ReferenceEquals(this.ExternalReferences, obj.ExternalReferences) ||
this.ExternalReferences.SequenceEqual(obj.ExternalReferences)) &&
(object.ReferenceEquals(this.Group, obj.Group) ||
this.Group.Equals(obj.Group, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Hashes, obj.Hashes) ||
this.Hashes.SequenceEqual(obj.Hashes)) &&
(object.ReferenceEquals(this.Licenses, obj.Licenses) ||
this.Licenses.SequenceEqual(obj.Licenses)) &&
(object.ReferenceEquals(this.LicensesSerialized, obj.LicensesSerialized) ||
this.LicensesSerialized.Equals(obj.LicensesSerialized)) &&
(object.ReferenceEquals(this.MimeType, obj.MimeType) ||
this.MimeType.Equals(obj.MimeType, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.ModelCard, obj.ModelCard) ||
this.ModelCard.Equals(obj.ModelCard)) &&
(this.Modified.Equals(obj.Modified)) &&
(object.ReferenceEquals(this.Name, obj.Name) ||
this.Name.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase)) &&
(this.NonNullableModified.Equals(obj.NonNullableModified)) &&
(this.NonNullableScope == obj.NonNullableScope) &&
(object.ReferenceEquals(this.Pedigree, obj.Pedigree) ||
this.Pedigree.Equals(obj.Pedigree)) &&
(object.ReferenceEquals(this.Properties, obj.Properties) ||
this.Properties.SequenceEqual(obj.Properties)) &&
(object.ReferenceEquals(this.Publisher, obj.Publisher) ||
this.Publisher.Equals(obj.Publisher, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Purl, obj.Purl) ||
this.Purl.Equals(obj.Purl, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.ReleaseNotes, obj.ReleaseNotes) ||
this.ReleaseNotes.Equals(obj.ReleaseNotes)) &&
(this.Scope == obj.Scope) &&
(object.ReferenceEquals(this.Supplier, obj.Supplier) ||
this.Supplier.Equals(obj.Supplier)) &&
(object.ReferenceEquals(this.Swid, obj.Swid) ||
this.Swid.Equals(obj.Swid)) &&
(this.Type == obj.Type) &&
(object.ReferenceEquals(this.Version, obj.Version) ||
this.Version.Equals(obj.Version, StringComparison.InvariantCultureIgnoreCase));
}

public override int GetHashCode()
Expand Down
12 changes: 11 additions & 1 deletion src/CycloneDX.Core/Models/Composition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Xml.Serialization;
using System.Text.Json.Serialization;
using ProtoBuf;
using System.Linq;

namespace CycloneDX.Models
{
Expand Down Expand Up @@ -202,7 +203,16 @@ public override bool Equals(object obj)

public bool Equals(Composition obj)
{
return obj != null && CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
return obj != null &&
(this.Aggregate == obj.Aggregate) &&
(object.ReferenceEquals(this.BomRef, obj.BomRef) ||
this.BomRef.Equals(obj.BomRef, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Assemblies, obj.Assemblies) ||
this.Assemblies.SequenceEqual(obj.Assemblies)) &&
(object.ReferenceEquals(this.Dependencies, obj.Dependencies) ||
this.Dependencies.SequenceEqual(obj.Dependencies)) &&
(object.ReferenceEquals(this.Vulnerabilities, obj.Vulnerabilities) ||
this.Vulnerabilities.SequenceEqual(obj.Vulnerabilities));
}

public override int GetHashCode()
Expand Down
7 changes: 6 additions & 1 deletion src/CycloneDX.Core/Models/Dependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;
Expand All @@ -43,7 +44,11 @@ public override bool Equals(object obj)

public bool Equals(Dependency obj)
{
return obj != null && CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
return obj != null &&
(object.ReferenceEquals(this.Ref, obj.Ref) ||
this.Ref.Equals(obj.Ref, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Dependencies, obj.Dependencies) ||
this.Dependencies.SequenceEqual(obj.Dependencies));
}

public override int GetHashCode()
Expand Down
10 changes: 9 additions & 1 deletion src/CycloneDX.Core/Models/ExternalReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;
Expand Down Expand Up @@ -135,7 +136,14 @@ public override bool Equals(object obj)

public bool Equals(ExternalReference obj)
{
return obj != null && CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
return obj != null &&
(object.ReferenceEquals(this.Comment, obj.Comment) ||
this.Comment.Equals(obj.Comment, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Hashes, obj.Hashes) ||
this.Hashes.SequenceEqual(obj.Hashes)) &&
(this.Type == obj.Type) &&
(object.ReferenceEquals(this.Url, obj.Url) ||
this.Comment.Equals(obj.Url, StringComparison.InvariantCultureIgnoreCase));;
}

public override int GetHashCode()
Expand Down
40 changes: 39 additions & 1 deletion src/CycloneDX.Core/Models/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using ProtoBuf;
Expand Down Expand Up @@ -214,7 +215,44 @@ public override bool Equals(object obj)

public bool Equals(Service obj)
{
return obj != null && CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
return obj != null &&
(this.Authenticated == obj.Authenticated) &&
(object.ReferenceEquals(this.BomRef, obj.BomRef) ||
this.BomRef.Equals(obj.BomRef, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Data, obj.Data) ||
this.Data.SequenceEqual(obj.Data)) &&
(object.ReferenceEquals(this.Description, obj.Description) ||
this.BomRef.Equals(obj.Description, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Endpoints, obj.Endpoints) ||
this.Endpoints.SequenceEqual(obj.Endpoints)) &&
(object.ReferenceEquals(this.ExternalReferences, obj.ExternalReferences) ||
this.ExternalReferences.SequenceEqual(obj.ExternalReferences)) &&
(object.ReferenceEquals(this.Group, obj.Group) ||
this.Group.Equals(obj.Group, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Licenses, obj.Licenses) ||
this.Licenses.SequenceEqual(obj.Licenses)) &&
(object.ReferenceEquals(this.LicensesSerialized, obj.LicensesSerialized) ||
this.LicensesSerialized.Equals(obj.LicensesSerialized)) &&
(object.ReferenceEquals(this.Name, obj.Name) ||
this.Name.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase)) &&
(this.NonNullableAuthenticated.Equals(obj.NonNullableAuthenticated)) &&
(this.NonNullableXTrustBoundary.Equals(obj.NonNullableXTrustBoundary)) &&
(object.ReferenceEquals(this.Properties, obj.Properties) ||
this.Properties.SequenceEqual(obj.Properties)) &&
(object.ReferenceEquals(this.Provider, obj.Provider) ||
this.Provider.Equals(obj.Provider)) &&
(object.ReferenceEquals(this.ReleaseNotes, obj.ReleaseNotes) ||
this.ReleaseNotes.Equals(obj.ReleaseNotes)) &&
(object.ReferenceEquals(this.Services, obj.Services) ||
this.Services.SequenceEqual(obj.Services)) &&
(this.SpecVersion.Equals(obj.SpecVersion)) &&
(object.ReferenceEquals(this.TrustZone, obj.TrustZone) ||
this.TrustZone.Equals(obj.TrustZone, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Version, obj.Version) ||
this.Version.Equals(obj.Version, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.XmlData, obj.XmlData) ||
this.XmlData.Equals(obj.XmlData)) &&
(this.TrustZone.Equals(obj.XTrustBoundary));
}

public override int GetHashCode()
Expand Down
13 changes: 12 additions & 1 deletion src/CycloneDX.Core/Models/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

Expand Down Expand Up @@ -55,7 +56,17 @@ public override bool Equals(object obj)

public bool Equals(Tool obj)
{
return obj != null && CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
return obj != null &&
(object.ReferenceEquals(this.ExternalReferences, obj.ExternalReferences) ||
this.ExternalReferences.SequenceEqual(obj.ExternalReferences)) &&
(object.ReferenceEquals(this.Hashes, obj.Hashes) ||
this.Hashes.SequenceEqual(obj.Hashes)) &&
(object.ReferenceEquals(this.Name, obj.Name) ||
this.Name.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Vendor, obj.Vendor) ||
this.Vendor.Equals(obj.Vendor, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Version, obj.Version) ||
this.Version.Equals(obj.Version, StringComparison.InvariantCultureIgnoreCase));
}

public override int GetHashCode()
Expand Down
41 changes: 40 additions & 1 deletion src/CycloneDX.Core/Models/Vulnerabilities/Vulnerability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Xml.Serialization;
using System.Text.Json.Serialization;
using ProtoBuf;
using System.Linq;

namespace CycloneDX.Models.Vulnerabilities
{
Expand Down Expand Up @@ -151,7 +152,45 @@ public override bool Equals(object obj)

public bool Equals(Vulnerability obj)
{
return obj != null && CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
return obj != null &&
(object.ReferenceEquals(this.Advisories, obj.Advisories) ||
this.Advisories.SequenceEqual(obj.Advisories)) &&
(object.ReferenceEquals(this.Affects, obj.Affects) ||
this.Affects.SequenceEqual(obj.Affects)) &&
(object.ReferenceEquals(this.Analysis, obj.Analysis) ||
this.Analysis.Equals(obj.Analysis)) &&
(object.ReferenceEquals(this.BomRef, obj.BomRef) ||
this.BomRef.Equals(obj.BomRef, StringComparison.InvariantCultureIgnoreCase)) &&
(this.Created.Equals(obj.Created)) &&
(object.ReferenceEquals(this.Credits, obj.Credits) ||
this.Credits.Equals(obj.Credits)) &&
(object.ReferenceEquals(this.CWES, obj.CWES) ||
this.CWES.SequenceEqual(obj.CWES)) &&
(object.ReferenceEquals(this.Description, obj.Description) ||
this.Description.Equals(obj.Description, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Detail, obj.Detail) ||
this.Detail.Equals(obj.Detail, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.Id, obj.Id) ||
this.Id.Equals(obj.Id, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.ProofOfConcept, obj.ProofOfConcept) ||
this.ProofOfConcept.Equals(obj.ProofOfConcept)) &&
(object.ReferenceEquals(this.Properties, obj.Properties) ||
this.Properties.SequenceEqual(obj.Properties)) &&
(this.Published.Equals(obj.Published)) &&
(object.ReferenceEquals(this.Ratings, obj.Ratings) ||
this.Ratings.SequenceEqual(obj.Ratings)) &&
(object.ReferenceEquals(this.Recommendation, obj.Recommendation) ||
this.Recommendation.Equals(obj.Recommendation, StringComparison.InvariantCultureIgnoreCase)) &&
(object.ReferenceEquals(this.References, obj.References) ||
this.References.SequenceEqual(obj.References)) &&
(this.Rejected.Equals(obj.Rejected)) &&
(object.ReferenceEquals(this.Source, obj.Source) ||
this.Source.Equals(obj.Source)) &&
(object.ReferenceEquals(this.Tools, obj.Tools) ||
this.Tools.Equals(obj.Tools)) &&
(this.Updated.Equals(obj.Updated)) &&
(object.ReferenceEquals(this.Workaround, obj.Workaround) ||
this.Workaround.Equals(obj.Workaround));
}

public override int GetHashCode()
Expand Down

0 comments on commit 1e6f34a

Please sign in to comment.