Skip to content

Commit

Permalink
merge attestations and standards
Browse files Browse the repository at this point in the history
Signed-off-by: MTsfoni <[email protected]>
  • Loading branch information
mtsfoni committed Sep 1, 2024
1 parent 1903c63 commit 31112e8
Show file tree
Hide file tree
Showing 16 changed files with 457 additions and 37 deletions.
27 changes: 27 additions & 0 deletions src/CycloneDX.Core/Json/Serializer.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,32 @@ internal static string Serialize(Models.ExternalReference externalReference)
return JsonSerializer.Serialize(externalReference, _options);
}

internal static string Serialize(Models.Standard standard)
{
Contract.Requires(standard != null);
return JsonSerializer.Serialize(standard, _options);
}

internal static string Serialize(Models.OrganizationalEntity organization)
{
Contract.Requires(organization != null);
return JsonSerializer.Serialize(organization, _options);
}

internal static string Serialize(Models.Claim obj)
{
Contract.Requires(obj != null);
return JsonSerializer.Serialize(obj, _options);
}
internal static string Serialize(Models.Assessor obj)
{
Contract.Requires(obj != null);
return JsonSerializer.Serialize(obj, _options);
}
internal static string Serialize(Models.Attestation obj)
{
Contract.Requires(obj != null);
return JsonSerializer.Serialize(obj, _options);
}
}
}
2 changes: 1 addition & 1 deletion src/CycloneDX.Core/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace CycloneDX.Models
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
[XmlType("component")]
[ProtoContract]
public class Component: IEquatable<Component>
public class Component: IEquatable<Component>, IHasBomRef

Check failure on line 34 in src/CycloneDX.Core/Models/Component.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 34 in src/CycloneDX.Core/Models/Component.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 34 in src/CycloneDX.Core/Models/Component.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 34 in src/CycloneDX.Core/Models/Component.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[ProtoContract]
public enum Classification
Expand Down
25 changes: 24 additions & 1 deletion src/CycloneDX.Core/Models/Declarations/Assessor.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 CycloneDX.Core.Models;
using ProtoBuf;
using System;
using System.Text.Json.Serialization;
using System.Xml;
using System.Xml.Serialization;

namespace CycloneDX.Models
{
[ProtoContract]
public class Assessor
public class Assessor : IEquatable<Assessor>, IHasBomRef

Check failure on line 28 in src/CycloneDX.Core/Models/Declarations/Assessor.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 28 in src/CycloneDX.Core/Models/Declarations/Assessor.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 28 in src/CycloneDX.Core/Models/Declarations/Assessor.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlAttribute("bom-ref")]
[JsonPropertyName("bom-ref")]
Expand All @@ -36,5 +38,26 @@ public class Assessor
[XmlElement("organization")]
[ProtoMember(3)]
public OrganizationalEntity Organization { get; set; }

public override bool Equals(object obj)
{
var other = obj as Assessor;
if (other == null)
{
return false;
}

return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(other);
}

public bool Equals(Assessor obj)
{
return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(obj);
}

public override int GetHashCode()
{
return Json.Serializer.Serialize(this).GetHashCode();
}
}
}
24 changes: 23 additions & 1 deletion src/CycloneDX.Core/Models/Declarations/Attestation.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 ProtoBuf;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml;
Expand All @@ -24,7 +25,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class Attestation
public class Attestation : IEquatable<Attestation>
{
[XmlElement("summary")]
[ProtoMember(1)]
Expand All @@ -45,5 +46,26 @@ public class Attestation
[XmlIgnore]
public Signature Signature { get; set; }

public override bool Equals(object obj)
{
var other = obj as Attestation;
if (other == null)
{
return false;
}

return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(other);
}

public bool Equals(Attestation obj)
{
return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(obj);
}

public override int GetHashCode()
{
return Json.Serializer.Serialize(this).GetHashCode();
}

}
}
26 changes: 25 additions & 1 deletion src/CycloneDX.Core/Models/Declarations/Claim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) OWASP Foundation. All Rights Reserved.

using CycloneDX.Core.Models;
using CycloneDX.Models.Vulnerabilities;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml;
Expand All @@ -24,7 +27,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class Claim
public class Claim : IEquatable<Claim>, IHasBomRef

Check failure on line 30 in src/CycloneDX.Core/Models/Declarations/Claim.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 30 in src/CycloneDX.Core/Models/Declarations/Claim.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 30 in src/CycloneDX.Core/Models/Declarations/Claim.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlAttribute("bom-ref")]
[JsonPropertyName("bom-ref")]
Expand Down Expand Up @@ -66,5 +69,26 @@ public class Claim
public XmlElement XmlSignature { get; set; }
[XmlIgnore]
public Signature Signature { get; set; }

public override bool Equals(object obj)
{
var other = obj as Claim;
if (other == null)
{
return false;
}

return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(other);
}

public bool Equals(Claim obj)
{
return CycloneDX.Json.Serializer.Serialize(this) == CycloneDX.Json.Serializer.Serialize(obj);
}

public override int GetHashCode()
{
return CycloneDX.Json.Serializer.Serialize(this).GetHashCode();
}
}
}
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.Core.Models;
using ProtoBuf;
using System;
using System.Collections.Generic;
Expand All @@ -25,7 +26,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class DeclarationsEvidence
public class DeclarationsEvidence : IHasBomRef

Check failure on line 29 in src/CycloneDX.Core/Models/Declarations/DeclarationsEvidence.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 29 in src/CycloneDX.Core/Models/Declarations/DeclarationsEvidence.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 29 in src/CycloneDX.Core/Models/Declarations/DeclarationsEvidence.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlAttribute("bom-ref")]
[JsonPropertyName("bom-ref")]
Expand Down
2 changes: 1 addition & 1 deletion src/CycloneDX.Core/Models/Definitions/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class Level
public class Level : IHasBomRef

Check failure on line 26 in src/CycloneDX.Core/Models/Definitions/Level.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 26 in src/CycloneDX.Core/Models/Definitions/Level.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 26 in src/CycloneDX.Core/Models/Definitions/Level.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlAttribute("bom-ref")]
[JsonPropertyName("bom-ref")]
Expand Down
3 changes: 2 additions & 1 deletion src/CycloneDX.Core/Models/Definitions/Requirement.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 ProtoBuf;
using System.Collections.Generic;
using System.Text.Json.Serialization;
Expand All @@ -23,7 +24,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class Requirement
public class Requirement : IHasBomRef

Check failure on line 27 in src/CycloneDX.Core/Models/Definitions/Requirement.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in src/CycloneDX.Core/Models/Definitions/Requirement.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in src/CycloneDX.Core/Models/Definitions/Requirement.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlAttribute("bom-ref")]
[JsonPropertyName("bom-ref")]
Expand Down
29 changes: 28 additions & 1 deletion src/CycloneDX.Core/Models/Definitions/Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
// Copyright (c) OWASP Foundation. All Rights Reserved.

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

namespace CycloneDX.Models
{
[ProtoContract]
public class Standard
public class Standard : IEquatable<Standard>, IHasBomRef

Check failure on line 27 in src/CycloneDX.Core/Models/Definitions/Standard.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in src/CycloneDX.Core/Models/Definitions/Standard.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in src/CycloneDX.Core/Models/Definitions/Standard.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlAttribute("bom-ref")]
[JsonPropertyName("bom-ref")]
Expand Down Expand Up @@ -62,6 +63,8 @@ public class Standard
public List<ExternalReference> ExternalReferences { get; set; }
public bool ShouldSerializeExternalReferences() => ExternalReferences?.Count > 0;



[XmlAnyElement]
public List<System.Xml.XmlElement> Any { get; set; }

Expand All @@ -70,5 +73,29 @@ public class Standard

[XmlIgnore]
public Signature signature { get; set; }




public override bool Equals(object obj)
{
var other = obj as Standard;
if (other == null)
{
return false;
}

return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(other);
}

public bool Equals(Standard obj)
{
return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(obj);
}

public override int GetHashCode()
{
return Json.Serializer.Serialize(this).GetHashCode();
}
}
}
24 changes: 23 additions & 1 deletion src/CycloneDX.Core/Models/OrganizationalEntity.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 System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
Expand All @@ -23,7 +24,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class OrganizationalEntity
public class OrganizationalEntity : IEquatable<OrganizationalEntity>, IHasBomRef

Check failure on line 27 in src/CycloneDX.Core/Models/OrganizationalEntity.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in src/CycloneDX.Core/Models/OrganizationalEntity.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in src/CycloneDX.Core/Models/OrganizationalEntity.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
[XmlElement("name")]
[ProtoMember(1)]
Expand All @@ -45,5 +46,26 @@ public class OrganizationalEntity
[XmlElement("address")]
[ProtoMember(5)]
public PostalAddress Address { get; set; }

public override bool Equals(object obj)
{
var other = obj as OrganizationalEntity;
if (other == null)
{
return false;
}

return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(other);
}

public bool Equals(OrganizationalEntity obj)
{
return Json.Serializer.Serialize(this) == Json.Serializer.Serialize(obj);
}

public override int GetHashCode()
{
return Json.Serializer.Serialize(this).GetHashCode();
}
}
}
2 changes: 1 addition & 1 deletion src/CycloneDX.Core/Models/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace CycloneDX.Models
{
[ProtoContract]
public class Service: IEquatable<Service>
public class Service: IEquatable<Service>, IHasBomRef

Check failure on line 29 in src/CycloneDX.Core/Models/Service.cs

View workflow job for this annotation

GitHub Actions / Build warnings check

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 29 in src/CycloneDX.Core/Models/Service.cs

View workflow job for this annotation

GitHub Actions / Tests on ubuntu-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 29 in src/CycloneDX.Core/Models/Service.cs

View workflow job for this annotation

GitHub Actions / Tests on windows-latest

The type or namespace name 'IHasBomRef' could not be found (are you missing a using directive or an assembly reference?)
{
public Service()
{
Expand Down
Loading

0 comments on commit 31112e8

Please sign in to comment.