Crypt/Nodelist.pm

filter: Statementstmt 22.0% 22 / 100 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 77.7% 7 / 9 Podpod 100% 2 / 2 totaltotal 19.1% 31 / 162 CC 27 SCAR 51.8
CC
27
Cov
15%
new
272.0
get_email_addr
156.0
BEGIN
1.0
CRAP 178.0
↑ Summary Crypt/Msg.pm »
1 # FTN::Crypt::Nodelist - Nodelist processing for the FTN::Crypt module
2 #
3 # Copyright (C) 2019 by Petr Antonov
4 #
5 # This library is free software; you can redistribute it and/or modify it
6 # under the same terms as Perl 5.10.0. For more details, see the full text
7 # of the licenses at https://opensource.org/licenses/Artistic-1.0, and
8 # http://www.gnu.org/licenses/gpl-2.0.html.
9 #
10 # This package is provided "as is" and without any express or implied
11 # warranties, including, without limitation, the implied warranties of
12 # merchantability and fitness for a particular purpose.
13 #
14  
15 package FTN::Crypt::Nodelist;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use base qw/FTN::Crypt::Error/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #----------------------------------------------------------------------#
24  
25 =head1 NAME
26  
27 FTN::Crypt::Nodelist - Nodelist processing for the L<FTN::Crypt> module.
28  
29 =head1 SYNOPSIS
30  
31 use FTN::Crypt::Nodelist;
32  
33 my $obj = FTN::Crypt::Nodelist->new(
34 Nodelist => 'NODELIST.*',
35 Pointlist => [
36 'pointlist_1.*',
37 'pointlist_2',
38 ],
39 Username => 'user', # optional, defaults to 'sysop'
40 );
41 my ($addr, $method) = $obj->get_email_addr('99:8877/1');
42  
43 =cut
44  
45 #----------------------------------------------------------------------#
46  
47 1 ▶use FTN::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use FTN::Crypt::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use FTN::Nodelist;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 #----------------------------------------------------------------------#
52  
53 1 my $DEFAULT_USERNAME = 'sysop';
54  
55 #----------------------------------------------------------------------#
56  
57 =head1 METHODS
58  
59 =cut
60  
61 #----------------------------------------------------------------------#
62  
63 =head2 new()
64  
65 Constructor.
66  
67 =head3 Parameters:
68  
69 =over 4
70  
71 =item * C<Nodelist>: Path to nodelist file(s), either scalar or arrayref. If contains wildcard, file with maximum number in digital extension will be selected.
72  
73 =item * B<Optional> C<Pointlist>: Path to pointlist file(s), either scalar or arrayref. If contains wildcard, file with maximum number in digital extension will be selected.
74  
75 =item * B<Optional> C<Username>: Username part in email address, which corresponds to the FTN one, defaults to 'sysop'.
76  
77 =back
78  
79 =head3 Returns:
80  
81 Created object or error in C<FTN::Crypt::Nodelist-E<gt>error>.
82  
83 Sample:
84  
85 my $obj = FTN::Crypt::Nodelist->new(
86 Nodelist => 'NODELIST.*',
87 Pointlist => [
88 'pointlist_1.*',
89 'pointlist_2',
90 ],
91 Username => 'user', # optional, defaults to 'sysop'
92 );
93  
94 =cut
95  
96 0 ▶sub new {
Subroutine new: not called CC=16 SCAR=56.1
Pod documented
97 0 my $class = shift;
98 0 my (%opts) = @_;
99  
100 0 ▶ unless (%opts) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%opts) 0 0 0
101 0 $class->set_error('No options specified');
102 0 return;
103 }
104 0 ▶ unless ($opts{Nodelist}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"Nodelist"}) 0 0 0
105 0 $class->set_error('No nodelist specified');
106 0 return;
107 }
108  
109 0 my $self = {
110 _username => $DEFAULT_USERNAME,
111 };
112  
113 0 ▶ $opts{Nodelist} = [$opts{Nodelist}] unless ref $opts{Nodelist};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts{"Nodelist"} 0 0 0
114 0 ▶ unless (ref $opts{Nodelist} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $opts{"Nodelist"} eq "ARRAY") 0 0 0
115 0 $class->set_error('Nodelist value error');
116 0 return;
117 }
118 0 ▶ unless (scalar @{$opts{Nodelist}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$opts{"Nodelist"};}) 0 0 0
119 0 $class->set_error('No nodelist specified');
120 0 return;
121 }
122  
123 0 $self->{_nodelist} = [];
124 0 foreach my $nl_file (@{$opts{Nodelist}}) {
125 0 my $nl = FTN::Nodelist->new(-file => $nl_file);
126 0 ▶ unless ($nl) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nl) 0 0 0
127 0 $class->set_error($@);
128 0 return;
129 }
130 0 push @{$self->{_nodelist}}, $nl;
131 }
132  
133 0 ▶ if ($opts{Pointlist}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"Pointlist"}) 0 0 0
134 0 ▶ $opts{Pointlist} = [$opts{Pointlist}] unless ref $opts{Pointlist};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts{"Pointlist"} 0 0 0
135 0 ▶ unless (ref $opts{Pointlist} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $opts{"Pointlist"} eq "ARRAY") 0 0 0
136 0 $class->set_error('Pointlist value error');
137 0 return;
138 }
139 0 ▶ if (scalar @{$opts{Pointlist}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$opts{"Pointlist"};}) 0 0 0
140 0 $self->{_pointlist} = [];
141 0 foreach my $pl_file (@{$opts{Pointlist}}) {
142 0 my $pl = FTN::Nodelist->new(-file => $pl_file);
143 0 ▶ unless ($pl) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pl) 0 0 0
144 0 $class->set_error($@);
145 0 return;
146 }
147 0 push @{$self->{_pointlist}}, $pl;
148 }
149 }
150 }
151  
152 0 ▶ if ($opts{Username}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"Username"}) 0 0 0
153 0 ▶ unless ($opts{Username} =~ /^\w+([\.-]?\w+)*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"Username"} =~ /^\w+([\.-]?\w+)*$/) 0 0 0
154 0 $class->set_error('Invalid username format');
155 0 return;
156 }
157 0 $self->{_username} = $opts{Username};
158 }
159  
160 0 $self = bless $self, $class;
161 0 return $self;
162 }
163  
164 #----------------------------------------------------------------------#
165  
166 =head2 get_email_addr()
167  
168 If recipient supports PGP encryption, get recipient's email address and encryption method.
169  
170 =head3 Parameters:
171  
172 =over 4
173  
174 =item * Recipient's FTN address.
175  
176 =back
177  
178 =head3 Returns:
179  
180 Recipient's email address and encryption method or error in C<$obj-E<gt>error>.
181  
182 Sample:
183  
184 my ($addr, $method) = $obj->get_email_addr('99:8877/1') or die $obj->error;
185  
186 =cut
187  
188 0 ▶sub get_email_addr {
Subroutine get_email_addr: not called CC=12 SCAR=50.5
Pod documented
189 0 my $self = shift;
190 0 my ($ftn_addr) = @_;
191  
192 0 ▶ unless ($ftn_addr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftn_addr) 0 0 0
193 0 $self->set_error('No FTN address specified');
194 0 return;
195 }
196  
197 0 my $addr = FTN::Address->new($ftn_addr);
198 0 ▶ unless ($addr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($addr) 0 0 0
199 0 $self->set_error($@);
200 0 return;
201 }
202  
203 0 ▶ my $search_list = ($ftn_addr =~ /^\d+:\d+\/\d+\.(\d+)(?:@\w+)?$/ && $1 && $self->{_pointlist}) ? '_pointlist' : '_nodelist';
Branch: 1 branch
BranchTrueFalseTotal
$ftn_addr =~ m[^\d+:\d+/\d+\.(\d+)(?:\@\w+)?$] && $1 && $self->{'_pointlist'} ? : 0 0 0
Condition0%0/6
$ftn_addr =~ m[^\d+:\d+/\d+\.(\d+)(?:\@\w+)?$] and $1 and $self->{"_pointlist"}
!ll&&!rl&&r
000
$ftn_addr =~ m[^\d+:\d+/\d+\.(\d+)(?:\@\w+)?$] and $1
!ll&&!rl&&r
000
MC/DC0%0/3
$ftn_addr =~ m[^\d+:\d+/\d+\.(\d+)(?:\@\w+)?$] and $1 and $self->{"_pointlist"}
$ftn_addr =~ m[^\d+:\d+/\d+\.(\d+)(?:\@\w+)?$] $1 $self->{"_pointlist"}
Truth table0%0/4
A and B and C
A= $ftn_addr =~ m[^\d+:\d+/\d+\.(\d+)(?:\@\w+)?$]B= $1C= $self->{"_pointlist"}
ABCresult
0XX0
10X0
1100
1111
204  
205 0 my $node;
206 0 foreach my $list (@{$self->{$search_list}}) {
207 0 $node = $list->getNode($ftn_addr);
208 0 ▶ last if $node;
Branch: 1 branch
BranchTrueFalseTotal
if $node 0 0 0
209 }
210 0 ▶ unless ($node) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 0 0
211 0 $self->set_error('FTN address not found');
212 0 return;
213 }
214  
215 0 ▶ my %flags = map { /:/ ? (split /:/, $_, 2) : ($_ => 1) }
Branch: 1 branch
BranchTrueFalseTotal
/:/ ? : 0 0 0
216 0 map { tr/\r\n//dr }
217 0 @{$node->flags};
218 0 ▶ unless ($flags{$FTN::Crypt::Constants::ENC_NODELIST_FLAG}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flags{$FTN::Crypt::Constants::ENC_NODELIST_FLAG}) 0 0 0
219 0 $self->set_error("No encryption nodelist flag ($FTN::Crypt::Constants::ENC_NODELIST_FLAG)");
220 0 return;
221 }
222 0 ▶ unless ($FTN::Crypt::Constants::ENC_METHODS{$flags{$FTN::Crypt::Constants::ENC_NODELIST_FLAG}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FTN::Crypt::Constants::ENC_METHODS{$flags{$FTN::Crypt::Constants::ENC_NODELIST_FLAG}}) 0 0 0
223 0 $self->set_error("Unsupported encryption method ($flags{$FTN::Crypt::Constants::ENC_NODELIST_FLAG})");
224 0 return;
225 }
226  
227 0 return "<$self->{_username}@" . $addr->fqdn . '>', $flags{$FTN::Crypt::Constants::ENC_NODELIST_FLAG};
228 }
229  
230 1 1;
231 __END__
↑ Summary Crypt/Msg.pm »