CSAF/Type/Vulnerability.pm

filter: Statementstmt 96.0% 48 / 50 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod n/a totaltotal 97.0% 65 / 67 CC 1 SCAR 0.2
CC
1
Cov
96%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« CSAF/Type/Document.pm ↑ Summary CSAF/Type/Acknowledgments.pm »
1 package CSAF::Type::Vulnerability;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use CSAF::Type::Acknowledgments;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use CSAF::Type::CWE;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use CSAF::Type::Flags;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use CSAF::Type::IDs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use CSAF::Type::Involvements;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use CSAF::Type::Notes;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use CSAF::Type::ProductStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use CSAF::Type::References;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use CSAF::Type::Remediations;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use CSAF::Type::Scores;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use CSAF::Type::Threats;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶use CSAF::Util qw(parse_datetime);
Subroutine BEGIN: called CC=1 SCAR=2.6
23  
24 use Moo;
25 extends 'CSAF::Type::Base';
26  
27  
28 has title => (is => 'rw');
29 has cve => (is => 'rw', isa => sub { Carp::carp 'Malformed CVE ID' if ($_[0] && $_[0] !~ /^CVE-\d{4}-\d{4,7}$/) });
30 has discovery_date => (is => 'rw', coerce => \&parse_datetime);
31 has release_date => (is => 'rw', coerce => \&parse_datetime);
32  
33 sub cwe {
34 my ($self, %params) = @_;
35 $self->{cwe} ||= CSAF::Type::CWE->new(%params);
36 }
37  
38 sub product_status {
39 my ($self, %params) = @_;
40 $self->{product_status} ||= CSAF::Type::ProductStatus->new(%params);
41 }
42  
43 sub notes {
44 my $self = shift;
45 $self->{notes} ||= CSAF::Type::Notes->new(@_);
46 }
47  
48 sub references {
49 my $self = shift;
50 $self->{references} ||= CSAF::Type::References->new(@_);
51 }
52  
53 sub scores {
54 my ($self, %params) = @_;
55 $self->{scores} ||= CSAF::Type::Scores->new(%params);
56 }
57  
58 sub acknowledgments {
59 my $self = shift;
60 $self->{acknowledgments} ||= CSAF::Type::Acknowledgments->new(@_);
61 }
62  
63 sub remediations {
64 my $self = shift;
65 $self->{remediations} ||= CSAF::Type::Remediations->new(@_);
66 }
67  
68 sub threats {
69 my $self = shift;
70 $self->{threats} ||= CSAF::Type::Threats->new(@_);
71 }
72  
73 sub ids {
74 my $self = shift;
75 $self->{ids} ||= CSAF::Type::IDs->new(@_);
76 }
77  
78 sub involvements {
79 my $self = shift;
80 $self->{involvements} ||= CSAF::Type::Involvements->new(@_);
81 }
82  
83 sub flags {
84 my $self = shift;
85 $self->{flags} ||= CSAF::Type::Flags->new(@_);
86 }
87  
88  
89 sub TO_CSAF {
90  
91 my $self = shift;
92  
93 my $output = {};
94  
95 $output->{cve} = $self->cve if ($self->cve);
96 $output->{title} = $self->title if ($self->title);
97  
98 $output->{discovery_date} = parse_datetime($self->discovery_date) if ($self->discovery_date);
99 $output->{release_date} = parse_datetime($self->release_date) if ($self->release_date);
100  
101 if ($self->cwe->id) {
102 $output->{cwe} = $self->cwe;
103 }
104  
105 if (@{$self->acknowledgments->items}) {
106 $output->{acknowledgments} = $self->acknowledgments;
107 }
108  
109 if (@{$self->notes->items}) {
110 $output->{notes} = $self->notes;
111 }
112  
113 if (@{$self->scores->items}) {
114 $output->{scores} = $self->scores;
115 }
116  
117 if (@{$self->remediations->items}) {
118 $output->{remediations} = $self->remediations;
119 }
120  
121 if (@{$self->references->items}) {
122 $output->{references} = $self->references;
123 }
124  
125 if (@{$self->involvements->items}) {
126 $output->{involvements} = $self->involvements;
127 }
128  
129 if (my $product_status = $self->product_status->TO_CSAF) {
130 $output->{product_status} = $product_status;
131 }
132  
133 if (my $flags = $self->flags->TO_CSAF) {
134 $output->{flags} = $flags if (@$flags); # TODO
135 }
136  
137 if (my $ids = $self->ids->TO_CSAF) {
138 $output->{ids} = $ids if (@$ids); # TODO
139 }
140  
141 return $output;
142  
143 }
144  
145 1;
146  
147 __END__
« CSAF/Type/Document.pm ↑ Summary CSAF/Type/Acknowledgments.pm »