AS2/Message.pm

filter: Statementstmt 49.1% 28 / 57 Branchbran 0.0% 0 / 22 Conditioncond 4.5% 1 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 33.3% 7 / 21 Podpod 76.4% 13 / 17 totaltotal 32.4% 49 / 151 SCAR 52.8
CC
22
Cov
29%
serialized_state
72.0
create_from_serialized_state
56.0
notification_options_check
42.0
CRAP 197.3
↑ Summary AS2.pm »
1 package Net::AS2::Message;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 =head1 NAME
6
7 Net::AS2::Message - AS2 incoming message
8
9 =head1 SYNOPSIS
10
11 ### Receiving Message and sending MDN
12 my $message = $as2->decode_messages($headers, $post_body);
13 if ($message->is_success) {
14 print $message->content;
15 }
16
17 =head1 PUBLIC INTERFACE
18
19 =cut
20
21 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22
23 2 my $crlf = "\x0d\x0a";
24
25 sub new
26 {
27 1 ▶ my ($class, $message_id, $async_url, $should_mdn_sign, $mic, $content) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
28
29 1 my $self = $class->_create_message($message_id, $async_url, $should_mdn_sign);
30 1 $self->{success} = 1;
31 1 $self->{content} = $content;
32 1 $self->{mic} = $mic;
33 1 return $self;
34 }
35
36 sub create_error_message
37 {
38 1 ▶ my $self = _create_message(@_);
Subroutine create_error_message: called CC=1 SCAR=0.0
Pod undocumented
39 1 $self->{error} = 1;
40 1 return $self;
41 }
42
43 sub create_failure_message
44 {
45 1 ▶ my $self = _create_message(@_);
Subroutine create_failure_message: called CC=1 SCAR=0.0
Pod undocumented
46 1 $self->{failure} = 1;
47 1 return $self;
48 }
49
50 sub _create_message
51 {
52 3 ▶ my ($class, $message_id, $async_url, $should_mdn_sign, $status_text, $plain_text) = @_;
Subroutine _create_message: called CC=2 SCAR=7.2
53 3 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
54 3 my $self = {
55 message_id => $message_id,
56 async_url => $async_url,
57 should_mdn_sign => $should_mdn_sign,
58 status_text => $status_text,
59 plain_text => $plain_text,
60 };
61 3 bless ($self, $class);
62 3 return $self;
63 }
64
65 =head2 Constructor
66
67 =over 4
68
69 =item $msg = Net::AS2::Message->create_from_serialized_state($state)
70
71 Create an C<Net::AS2::Message> from a serialized state data returned from L<serialized_state>
72
73 =back
74
75 =cut
76
77 sub create_from_serialized_state
78 {
79 0 ▶ my ($class, $state) = @_;
Subroutine create_from_serialized_state: not called CC=7 SCAR=40.3
Pod documented
80
81 0 my ($version, $status, $message_id, $mic, $async_url, $should_mdn_sign, $status_text, $plain_text)
82 = split(/\n/, $state);
83 0 ▶ croak "Net::AS2::Message state version is not supported"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version and $version eq "v1" and defined $plain_text 0 0 0
Condition0%0/6
defined $version and $version eq "v1" and defined $plain_text
!ll&&!rl&&r
000
defined $version and $version eq "v1"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $version and $version eq "v1" and defined $plain_text
defined $version $version eq "v1" defined $plain_text
Truth table0%0/4
A and B and C
A= defined $versionB= $version eq "v1"C= defined $plain_text
ABCresult
0XX0
10X0
1100
1111
84 unless defined $version && $version eq 'v1' && defined $plain_text;
85
86 0 ▶ $class = ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
87 0 ▶ my $self = {
Branch: 2 branches
BranchTrueFalseTotal
$status eq '1' ? : 0 0 0
$status eq '-1' ? : 0 0 0
88 (
89 $status eq '1' ? ( success => 1 ) :
90 $status eq '-1' ? ( error => 1 ) :
91 ( failure => 1 )
92 ),
93 message_id => $message_id,
94 mic => $mic,
95 status_text => $status_text,
96 should_mdn_sign => $should_mdn_sign,
97 plain_text => $plain_text,
98 async_url => $async_url
99 };
100 0 bless ($self, $class);
101
102 0 return $self;
103 }
104
105 =head2 Methods
106
107 =over 4
108
109 =item $msg->is_success
110
111 Returns if the message was successfully parsed.
112 C<content> and C<mic> would be available.
113
114 =cut
115
116 0 ▶sub is_success { return (shift)->{success}; }
Subroutine is_success: not called CC=1 SCAR=6.9
Pod documented
117
118 =item $msg->is_error
119
120 Returns if the message was failed to parse.
121 C<error_status_text> and C<error_plain_text> would be available.
122
123 =cut
124
125 0 ▶sub is_error { return (shift)->{error}; }
Subroutine is_error: not called CC=1 SCAR=6.9
Pod documented
126
127 =item $msg->is_failure
128
129 Returns if the message was parsed but failed in further processing, e.g. unsupported algorithm request .
130 C<error_status_text> and C<error_plain_text> would be available.
131
132 =cut
133
134 0 ▶sub is_failure { return (shift)->{failure}; }
Subroutine is_failure: not called CC=1 SCAR=6.9
Pod documented
135
136 =item $msg->is_mdn_async
137
138 Returns if the partner wants to have the MDN sent in ASYNC.
139 C<async_url> would be available.
140
141 =cut
142
143 0 ▶sub is_mdn_async { return (shift)->{async_url} ? 1 : 0; }
Subroutine is_mdn_async: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'async_url'} ? : 0 0 0
144
145 =item $msg->should_mdn_sign
146
147 Returns if the partner wants to have the MDN signed.
148
149 =cut
150
151 0 ▶sub should_mdn_sign { return (shift)->{should_mdn_sign} ? 1 : 0; }
Subroutine should_mdn_sign: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'should_mdn_sign'} ? : 0 0 0
152
153 =item $msg->message_id
154
155 Returns the message id of this message. This could be undefined in some failure mode.
156
157 =cut
158
159 0 ▶sub message_id { return (shift)->{message_id}; }
Subroutine message_id: not called CC=1 SCAR=6.9
Pod documented
160
161 =item $msg->content
162
163 Returns the encoded content (binary) of the message.
164 This is only defined when C<is_success> is true.
165
166 =cut
167
168 0 ▶sub content { return (shift)->{content}; }
Subroutine content: not called CC=1 SCAR=6.9
Pod documented
169
170 =item $msg->mic
171
172 Returns the SHA-1 MIC of the message.
173 This is only defined when C<is_success> is true.
174
175 =cut
176
177 0 ▶sub mic { return (shift)->{mic}; }
Subroutine mic: not called CC=1 SCAR=6.9
Pod documented
178
179 =item $msg->error_status_text
180
181 Dedicated short error text that should goes into machine readable report in the MDN.
182
183 =cut
184
185 0 ▶sub error_status_text { return (shift)->{status_text}; }
Subroutine error_status_text: not called CC=1 SCAR=6.9
Pod documented
186
187 =item $msg->error_plain_text
188
189 Error text that goes into human readable report in the MDN.
190
191 =cut
192
193 0 ▶sub error_plain_text { return (shift)->{plain_text}; }
Subroutine error_plain_text: not called CC=1 SCAR=6.9
Pod documented
194
195 =item $msg->async_url
196
197 Returns the url that partner wants us to send MDN to.
198
199 =cut
200
201 0 ▶sub async_url { return (shift)->{async_url}; }
Subroutine async_url: not called CC=1 SCAR=6.9
Pod documented
202
203 =item $msg->serialized_state
204
205 Returns the serialized state of this message.
206
207 This is usually used for passing C<Net::AS2::Message> to another process for sending ASYNC MDN.
208
209 =cut
210
211 sub serialized_state {
212 0 ▶ my $self = shift;
Subroutine serialized_state: not called CC=8 SCAR=42.8
Pod documented
213 return join("\n",
214 'v1',
215 $self->is_success ? 1 : $self->is_error ? -1 : -2,
216 $self->{message_id},
217 $self->{mic} // '',
218 $self->{async_url} // '',
219 $self->{should_mdn_sign} // '',
220 $self->{status_text} // '',
221 0 ▶ $self->{plain_text} // ''
Branch: 2 branches
BranchTrueFalseTotal
$self->is_success ? : 0 0 0
$self->is_error ? : 0 0 0
Condition0%0/10
$self->{"mic"} // ""
l!l
00
$self->{"async_url"} // ""
l!l
00
$self->{"should_mdn_sign"} // ""
l!l
00
$self->{"status_text"} // ""
l!l
00
$self->{"plain_text"} // ""
l!l
00
MC/DC0%0/1
$self->{"mic"} // ""
$self->{"mic"}
MC/DC0%0/1
$self->{"async_url"} // ""
$self->{"async_url"}
MC/DC0%0/1
$self->{"should_mdn_sign"} // ""
$self->{"should_mdn_sign"}
MC/DC0%0/1
$self->{"status_text"} // ""
$self->{"status_text"}
MC/DC0%0/1
$self->{"plain_text"} // ""
$self->{"plain_text"}
Truth table0%0/2
A
A= $self->{"mic"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"async_url"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"should_mdn_sign"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"status_text"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"plain_text"}
Aresult
11
00
222 );
223 }
224
225 # Check if notification options are supported
226 sub notification_options_check
227 {
228 0 ▶ my ($options) = @_;
Subroutine notification_options_check: not called CC=6 SCAR=37.4
Pod undocumented
229 0 foreach (split(/;/, $options))
230 {
231 0 my ($key, $value) = $_ =~ /^\s*(.+?)\s*=\s*(.+?)\s*$/;
232 0 my ($requireness, @values) = lc($value) =~ /\s*(.+?)\s*(?:,|$)/g;
233
234 0 ▶ if (lc($key) eq 'signed-receipt-protocol') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $key eq "signed-receipt-protocol") 0 0 0
235 0 ▶ return 'requested MDN protocol is not supported'
Branch: 1 branch
BranchTrueFalseTotal
unless "pkcs7-signature" ~~ \@values 0 0 0
236 unless 'pkcs7-signature' ~~ \@values;
237 }
238 0 ▶ if (lc($key) eq 'signed-receipt-micalg') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $key eq "signed-receipt-micalg") 0 0 0
239 0 ▶ return 'requested MIC algorithm is not supported'
Branch: 1 branch
BranchTrueFalseTotal
unless "sha1" ~~ \@values 0 0 0
240 unless 'sha1' ~~ \@values;
241 }
242 }
243 0 return undef;
244 }
245
246 2 1;
247
248 =back
249
250 =head1 SEE ALSO
251
252 L<Net::AS2>
253
↑ Summary AS2.pm »