| | 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.Serialization; |
| | 7 | | using Spdx3.Utility; |
| | 8 | |
|
| | 9 | | namespace Spdx3.Model.Security.Classes; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Provides an EPSS assessment for a vulnerability. |
| | 13 | | /// See https://spdx.github.io/spdx-spec/v3.0.1/model/Security/Classes/EpssVulnAssessmentRelationship/ |
| | 14 | | /// </summary> |
| | 15 | | public class EpssVulnAssessmentRelationship : VulnAssessmentRelationship |
| | 16 | | { |
| | 17 | | private double _percentile; |
| | 18 | | private double _probability; |
| | 19 | |
|
| | 20 | | [JsonPropertyName("security_percentile")] |
| | 21 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| | 22 | | public required double Percentile |
| | 23 | | { |
| 4 | 24 | | get => _percentile; |
| | 25 | | set |
| | 26 | | { |
| 11 | 27 | | if (value is < 0.0 or > 1.0) |
| | 28 | | { |
| 4 | 29 | | throw new Spdx3Exception("Illegal value for Percentile", |
| 4 | 30 | | new ArgumentException("The value must be between 0.0 and 1.0 (inclusive)")); |
| | 31 | | } |
| 7 | 32 | | _percentile = value; |
| 7 | 33 | | } |
| | 34 | | } |
| | 35 | |
|
| | 36 | | [JsonPropertyName("security_probability")] |
| | 37 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| | 38 | | public required double Probability |
| | 39 | | { |
| 4 | 40 | | get => _probability; |
| | 41 | | set |
| | 42 | | { |
| 9 | 43 | | if (value is < 0.0 or > 1.0) |
| | 44 | | { |
| 4 | 45 | | throw new Spdx3Exception("Illegal value for Probability", |
| 4 | 46 | | new ArgumentException("The value must be between 0.0 and 1.0 (inclusive)")); |
| | 47 | | } |
| 5 | 48 | | _probability = value; |
| 5 | 49 | | } |
| | 50 | | } |
| | 51 | |
|
| | 52 | | // protected internal no-parm constructor required for deserialization |
| | 53 | | #pragma warning disable CS8618, CS9264 |
| 7 | 54 | | protected internal EpssVulnAssessmentRelationship() |
| | 55 | | { |
| 7 | 56 | | } |
| | 57 | | #pragma warning restore CS8618, CS9264 |
| | 58 | |
|
| | 59 | | [SetsRequiredMembers] |
| | 60 | | public EpssVulnAssessmentRelationship(Catalog catalog, CreationInfo creationInfo, Element from, List<Element> to, |
| 2 | 61 | | double percentile, double probability) : base(catalog, creationInfo, RelationshipType.hasAssessmentFor, from, |
| 2 | 62 | | to) |
| | 63 | | { |
| 2 | 64 | | Percentile = percentile; |
| 2 | 65 | | Probability = probability; |
| 2 | 66 | | } |
| | 67 | | } |