| | 1 | | using System.Diagnostics.CodeAnalysis; |
| | 2 | | using System.Text.Json.Serialization; |
| | 3 | | using Spdx3.Exceptions; |
| | 4 | | using Spdx3.Model.Core.Classes; |
| | 5 | | using Spdx3.Model.Core.Enums; |
| | 6 | | using Spdx3.Model.Security.Enums; |
| | 7 | | using Spdx3.Serialization; |
| | 8 | | using Spdx3.Utility; |
| | 9 | |
|
| | 10 | | namespace Spdx3.Model.Security.Classes; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Provides a CVSS version 4 assessment for a vulnerability. |
| | 14 | | /// See https://spdx.github.io/spdx-spec/v3.0.1/model/Security/Classes/CvssV4VulnAssessmentRelationship/ |
| | 15 | | /// </summary> |
| | 16 | | public class CvssV4VulnAssessmentRelationship : VulnAssessmentRelationship |
| | 17 | | { |
| | 18 | | [JsonPropertyName("security_score")] |
| | 19 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 11 | 20 | | public required double? Score { get; set; } |
| | 21 | |
|
| | 22 | | [JsonPropertyName("security_severity")] |
| | 23 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 12 | 24 | | public required CvssSeverityType? Severity { get; set; } |
| | 25 | |
|
| | 26 | | [JsonPropertyName("security_vectorString")] |
| | 27 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 11 | 28 | | public required string? VectorString { get; set; } |
| | 29 | |
|
| | 30 | | public override void Validate() |
| | 31 | | { |
| 3 | 32 | | base.Validate(); |
| 3 | 33 | | ValidateRequiredProperty(nameof(Score)); |
| 3 | 34 | | ValidateRequiredProperty(nameof(VectorString)); |
| 3 | 35 | | ValidateRequiredProperty(nameof(Severity)); |
| | 36 | |
|
| 3 | 37 | | if (RelationshipType.hasAssessmentFor != RelationshipType) |
| | 38 | | { |
| 1 | 39 | | throw new Spdx3ValidationException(this, nameof(RelationshipType), "Must be 'hasAssessmentFor'"); |
| | 40 | | } |
| 2 | 41 | | } |
| | 42 | |
|
| | 43 | | // protected internal no-parm constructor required for deserialization |
| | 44 | | #pragma warning disable CS8618, CS9264 |
| 2 | 45 | | protected internal CvssV4VulnAssessmentRelationship() |
| | 46 | | { |
| 2 | 47 | | } |
| | 48 | | #pragma warning restore CS8618, CS9264 |
| | 49 | |
|
| | 50 | | [SetsRequiredMembers] |
| | 51 | | public CvssV4VulnAssessmentRelationship(Catalog catalog, CreationInfo creationInfo, Element from, List<Element> to, |
| 2 | 52 | | double score, CvssSeverityType severity, string vectorString) : base(catalog, creationInfo, |
| 2 | 53 | | RelationshipType.hasAssessmentFor, from, to) |
| | 54 | | { |
| 2 | 55 | | Score = score; |
| 2 | 56 | | Severity = severity; |
| 2 | 57 | | VectorString = vectorString; |
| 2 | 58 | | } |
| | 59 | | } |