DNS/RR/RRSIG.pm

filter: Statementstmt 99.4% 188 / 189 Branchbran 100% 48 / 48 Conditioncond 100% 16 / 16 MC/DCmcdc 100% 9 / 9 Subroutinesub 100% 42 / 42 Podpod 100% 17 / 17 totaltotal 99.6% 320 / 321 CC 40 SCAR 10.7
CC
40
Cov
100%
_string2time
6.0
algorithm
5.0
_time2string
5.0
CRAP 2.9
« DNS/RR/NSEC.pm ↑ Summary DNS/RR/SIG.pm »
1 package Net::DNS::RR::RRSIG;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = (qw$Id: RRSIG.pm 2066 2026-11-17 11:13:39Z willem $)[2];
6  
7 2 ▶use base qw(Net::DNS::RR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 =head1 NAME
11  
12 Net::DNS::RR::RRSIG - DNS RRSIG resource record
13  
14 =cut
15  
16 2 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use Net::DNS::Parameters qw(:type);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 ▶use constant UTIL => defined eval { require Scalar::Util; };
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 eval { require MIME::Base64 };
28  
29 ## IMPORTANT: MUST NOT include crypto packages in metadata (strong crypto prohibited in many territories)
30 2 ▶use constant DNSSEC => defined $INC{'Net/DNS/SEC.pm'}; ## Discover how we got here, without exposing any crypto
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 2 my @algorithms;
33 my @deprecated;
34 2 if (DNSSEC) {
35 my @module = qw(Private DSA RSA ECDSA EdDSA MLDSA Digest);
36 foreach my $class ( map {"Net::DNS::SEC::$_"} @module ) {
37 my @index = eval join '', qw(r e q u i r e), " $class; $class->_index()"; ## no critic
38 push @algorithms, map { ( $_ => $class ) } @index;
39 push @deprecated, eval { $class->_deprecate() };
40 }
41 croak 'Net::DNS::SEC version not supported' unless scalar(@algorithms);
42 }
43  
44 2 my %DNSSEC_verify = @algorithms;
45 2 my %DNSSEC_siggen = @algorithms;
46  
47 2 delete @DNSSEC_verify{@deprecated}; ## DNSSEC status per RFC9904
48 0 delete @DNSSEC_siggen{map { abs($_) } @deprecated};
49  
50 2 my @field = qw(typecovered algorithm labels orgttl sigexpiration siginception keytag);
51  
52  
53 334 ▶sub _decode_rdata { ## decode rdata from wire-format octet string
Subroutine _decode_rdata: called CC=1 SCAR=0.0
54 334 my ( $self, $data, $offset, @opaque ) = @_;
55  
56 334 my $limit = $offset + $self->{rdlength};
57 334 @{$self}{@field} = unpack "\@$offset n C2 N3 n", $$data;
58 334 ( $self->{signame}, $offset ) = Net::DNS::DomainName->decode( $data, $offset + 18, @opaque );
59 334 $self->{sigbin} = substr $$data, $offset, $limit - $offset;
60 334 return;
61 }
62  
63  
64 5 ▶sub _encode_rdata { ## encode rdata as wire-format octet string
Subroutine _encode_rdata: called CC=1 SCAR=0.0
65 5 my $self = shift;
66  
67 5 my $signame = $self->{signame};
68 5 return pack 'n C2 N3 n a* a*', @{$self}{@field}, $signame->canonical, $self->sigbin;
69 }
70  
71  
72 3 ▶sub _format_rdata { ## format rdata portion of RR string.
Subroutine _format_rdata: called CC=1 SCAR=0.0
73 3 my $self = shift;
74  
75 3 my $signame = $self->{signame};
76 3 my @sig64 = split /\s+/, MIME::Base64::encode( $self->sigbin );
77 3 my @rdata = ( map( { $self->$_ } @field ), $signame->string, @sig64 );
78 3 $rdata[3] .= "\n";
79 3 return @rdata;
80 }
81  
82  
83 3 ▶sub _parse_rdata { ## populate RR from rdata in argument list
Subroutine _parse_rdata: called CC=2 SCAR=6.9
84 3 my ( $self, @argument ) = @_;
85  
86 3 foreach ( @field, qw(signame) ) { $self->$_( shift @argument ) }
87 3 $self->signature(@argument);
88 3 return;
89 }
90  
91  
92 2 ▶sub _defaults { ## specify RR attribute default values
Subroutine _defaults: called CC=1 SCAR=0.0
93 2 my $self = shift;
94  
95 2 $self->sigval(30);
96 2 return;
97 }
98  
99  
100 9 ▶sub typecovered {
Subroutine typecovered: called CC=3 SCAR=11.0
Pod documented
101 9 my ( $self, @value ) = @_;
102 9 for (@value) { $self->{typecovered} = typebyname($_) }
103 9 my $typecode = $self->{typecovered};
104 9 ▶ return defined $typecode ? typebyval($typecode) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $typecode ? : 8 1 9
105 }
106  
107  
108 19 ▶sub algorithm {
Subroutine algorithm: called CC=5 SCAR=16.1
Pod documented
109 19 my ( $self, $arg ) = @_;
110  
111 19 ▶ unless ( ref($self) ) { ## class method or simple function
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 3 16 19
112 3 my $argn = pop;
113 3 ▶ return $argn =~ /[^0-9]/ ? _algbyname($argn) : _algbyval($argn);
Branch: 1 branch
BranchTrueFalseTotal
$argn =~ /[^0-9]/ ? : 1 2 3
114 }
115  
116 16 ▶ return $self->{algorithm} unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 8 8 16
117 8 ▶ return _algbyval( $self->{algorithm} ) if $arg =~ /MNEMONIC/i;
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /MNEMONIC/i 1 7 8
118 7 return $self->{algorithm} = _algbyname($arg);
119 }
120  
121  
122 9 ▶sub labels {
Subroutine labels: called CC=3 SCAR=11.0
Pod documented
123 9 my ( $self, @value ) = @_;
124 9 for (@value) { $self->{labels} = 0 + $_ }
125 9 ▶ return $self->{labels} || 0;
Condition100%2/2
$self->{'labels'} || 0
l!l
81
MC/DC100%1/1
$self->{'labels'} || 0
$self->{'labels'}
Truth table100%2/2
A
A= $self->{'labels'}
Aresult
11
00
126 }
127  
128  
129 9 ▶sub orgttl {
Subroutine orgttl: called CC=3 SCAR=11.0
Pod documented
130 9 my ( $self, @value ) = @_;
131 9 for (@value) { $self->{orgttl} = 0 + $_ }
132 9 ▶ return $self->{orgttl} || 0;
Condition100%2/2
$self->{'orgttl'} || 0
l!l
81
MC/DC100%1/1
$self->{'orgttl'} || 0
$self->{'orgttl'}
Truth table100%2/2
A
A= $self->{'orgttl'}
Aresult
11
00
133 }
134  
135  
136 11 ▶sub sigexpiration {
Subroutine sigexpiration: called CC=4 SCAR=13.9
Pod documented
137 11 my ( $self, @value ) = @_;
138 11 for (@value) { $self->{sigexpiration} = _string2time($_) }
139 11 my $time = $self->{sigexpiration};
140 11 ▶ return unless defined wantarray && defined $time;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray and defined $time 5 6 11
Condition100%3/3
defined wantarray and defined $time
!ll&&!rl&&r
416
MC/DC100%2/2
defined wantarray and defined $time
defined wantarray defined $time
Truth table100%3/3
A and B
A= defined wantarrayB= defined $time
ABresult
0X0
100
111
141 6 return UTIL ? Scalar::Util::dualvar( $time, _time2string($time) ) : _time2string($time);
142 }
143  
144 11 ▶sub siginception {
Subroutine siginception: called CC=4 SCAR=13.9
Pod documented
145 11 my ( $self, @value ) = @_;
146 11 for (@value) { $self->{siginception} = _string2time($_) }
147 11 my $time = $self->{siginception};
148 11 ▶ return unless defined wantarray && defined $time;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray and defined $time 5 6 11
Condition100%3/3
defined wantarray and defined $time
!ll&&!rl&&r
416
MC/DC100%2/2
defined wantarray and defined $time
defined wantarray defined $time
Truth table100%3/3
A and B
A= defined wantarrayB= defined $time
ABresult
0X0
100
111
149 6 return UTIL ? Scalar::Util::dualvar( $time, _time2string($time) ) : _time2string($time);
150 }
151  
152 2 ▶sub sigex { return &sigexpiration; } ## historical
Subroutine sigex: called CC=1 SCAR=0.0
Pod documented
153  
154 2 ▶sub sigin { return &siginception; } ## historical
Subroutine sigin: called CC=1 SCAR=0.0
Pod documented
155  
156 2 ▶sub sigval {
Subroutine sigval: called CC=1 SCAR=0.0
Pod documented
157 2 my ( $self, @value ) = @_;
158 2 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 2 return ( $self->{sigval} ) = map { int( 86400 * $_ ) } @value;
160 }
161  
162  
163 9 ▶sub keytag {
Subroutine keytag: called CC=3 SCAR=11.0
Pod documented
164 9 my ( $self, @value ) = @_;
165 9 for (@value) { $self->{keytag} = 0 + $_ }
166 9 ▶ return $self->{keytag} || 0;
Condition100%2/2
$self->{'keytag'} || 0
l!l
81
MC/DC100%1/1
$self->{'keytag'} || 0
$self->{'keytag'}
Truth table100%2/2
A
A= $self->{'keytag'}
Aresult
11
00
167 }
168  
169  
170 6 ▶sub signame {
Subroutine signame: called CC=3 SCAR=11.0
Pod documented
171 6 my ( $self, @value ) = @_;
172 6 for (@value) { $self->{signame} = Net::DNS::DomainName->new($_) }
173 6 ▶ return $self->{signame} ? $self->{signame}->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'signame'} ? : 5 1 6
174 }
175  
176  
177 8 ▶sub sig {
Subroutine sig: called CC=2 SCAR=6.9
Pod documented
178 8 my ( $self, @value ) = @_;
179 8 ▶ return MIME::Base64::encode( $self->sigbin(), "" ) unless scalar @value;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @value 4 4 8
180 4 return $self->sigbin( MIME::Base64::decode( join "", @value ) );
181 }
182  
183  
184 16 ▶sub sigbin {
Subroutine sigbin: called CC=3 SCAR=11.0
Pod documented
185 16 my ( $self, @value ) = @_;
186 16 for (@value) { $self->{sigbin} = $_ }
187 16 ▶ return $self->{sigbin} || "";
Condition100%2/2
$self->{'sigbin'} || ''
l!l
151
MC/DC100%1/1
$self->{'sigbin'} || ''
$self->{'sigbin'}
Truth table100%2/2
A
A= $self->{'sigbin'}
Aresult
11
00
188 }
189  
190  
191 6 ▶sub signature { return &sig; }
Subroutine signature: called CC=1 SCAR=0.0
Pod documented
192  
193  
194 1 ▶sub create {
Subroutine create: called CC=1 SCAR=0.0
Pod documented
195 1 unless (DNSSEC) {
196 1 croak qq[No "use Net::DNS::SEC" declaration in application code];
197 } else {
198 my ( $class, $rrsetref, $priv_key, %etc ) = @_;
199  
200 $rrsetref = [$rrsetref] unless ref($rrsetref) eq 'ARRAY';
201 my $RR = $rrsetref->[0];
202 croak '$rrsetref is not reference to RR array' unless ref($RR) =~ /^Net::DNS::RR/;
203  
204 # All the TTLs need to be the same in the data RRset.
205 my $ttl = $RR->ttl;
206 croak 'RRs in RRset do not have same TTL' if grep { $_->ttl != $ttl } @$rrsetref;
207  
208 my $private = ref($priv_key) ? $priv_key : Net::DNS::SEC::Private->new($priv_key);
209 croak 'unable to parse private key' unless ref($private) eq 'Net::DNS::SEC::Private';
210  
211 my @label = grep { $_ ne chr(42) } $RR->{owner}->_wire; # count labels
212  
213 my $self = Net::DNS::RR->new(
214 name => $RR->name,
215 type => 'RRSIG',
216 class => 'IN',
217 ttl => $ttl,
218 typecovered => $RR->type,
219 labels => scalar @label,
220 orgttl => $ttl,
221 siginception => time(),
222 algorithm => $private->algorithm,
223 keytag => $private->keytag,
224 signame => $private->signame,
225 );
226  
227 while ( my ( $attribute, $value ) = each %etc ) {
228 $self->$attribute($value);
229 }
230  
231 $self->{sigexpiration} = $self->{siginception} + $self->{sigval}
232 unless $self->{sigexpiration};
233  
234 my $sigdata = $self->_CreateSigData($rrsetref);
235 $self->_CreateSig( $sigdata, $private );
236 return $self;
237 }
238 }
239  
240  
241 1 ▶sub verify {
Subroutine verify: called CC=1 SCAR=0.0
Pod documented
242  
243 # Reminder...
244  
245 # $rrsetref must be a reference to an array of RR objects.
246  
247 # $keyref is either a key object or a reference to an array of key objects.
248  
249 1 unless (DNSSEC) {
250 1 croak qq[No "use Net::DNS::SEC" declaration in application code];
251 } else {
252 my ( $self, $rrsetref, $keyref ) = @_;
253  
254 croak '$keyref argument is scalar or undefined' unless ref($keyref);
255  
256 print '$keyref argument is ', ref($keyref), "\n" if DEBUG;
257 if ( ref($keyref) eq "ARRAY" ) {
258  
259 # We will iterate over the supplied key list and
260 # return when there is a successful verification.
261 # If not, continue so that we survive key-id collision.
262  
263 print "Iterating over ", scalar(@$keyref), " keys\n" if DEBUG;
264 my @error;
265 foreach my $keyrr (@$keyref) {
266 my $result = $self->verify( $rrsetref, $keyrr );
267 return $result if $result;
268 my $error = $self->{vrfyerrstr};
269 my $keyid = $keyrr->keytag;
270 push @error, "key $keyid: $error";
271 print "key $keyid: $error\n" if DEBUG;
272 next;
273 }
274  
275 $self->{vrfyerrstr} = join "\n", @error;
276 return 0;
277  
278 } elsif ( $keyref->isa('Net::DNS::RR::DNSKEY') ) {
279  
280 print "Validating using key with keytag: ", $keyref->keytag, "\n" if DEBUG;
281  
282 } else {
283 croak join ' ', ref($keyref), 'can not be used as DNSSEC key';
284 }
285  
286  
287 $rrsetref = [$rrsetref] unless ref($rrsetref) eq 'ARRAY';
288 my $RR = $rrsetref->[0];
289 croak '$rrsetref not a reference to array of RRs' unless ref($RR) =~ /^Net::DNS::RR/;
290  
291 if (DEBUG) {
292 print "\n ---------------------- RRSIG DEBUG --------------------";
293 print "\n SIG:\t", $self->string;
294 print "\n KEY:\t", $keyref->string;
295 print "\n -------------------------------------------------------\n";
296 }
297  
298 $self->{vrfyerrstr} = '';
299 unless ( $self->algorithm == $keyref->algorithm ) {
300 $self->{vrfyerrstr} = 'algorithm does not match';
301 return 0;
302 }
303  
304 unless ( $self->keytag == $keyref->keytag ) {
305 $self->{vrfyerrstr} = 'keytag does not match';
306 return 0;
307 }
308  
309 my $sigdata = $self->_CreateSigData($rrsetref);
310 $self->_VerifySig( $sigdata, $keyref ) || return 0;
311  
312 # time to do some time checking.
313 my $t = time;
314  
315 if ( _ordered( $self->{sigexpiration}, $t ) ) {
316 $self->{vrfyerrstr} = join ' ', 'Signature expired at', $self->sigexpiration;
317 return 0;
318 } elsif ( _ordered( $t, $self->{siginception} ) ) {
319 $self->{vrfyerrstr} = join ' ', 'Signature valid from', $self->siginception;
320 return 0;
321 }
322  
323 return 1;
324 }
325 } #END verify
326  
327  
328 2 ▶sub vrfyerrstr {
Subroutine vrfyerrstr: called CC=1 SCAR=0.0
Pod documented
329 2 my $self = shift;
330 2 return $self->{vrfyerrstr};
331 }
332  
333  
334 ########################################
335  
336 {
337 2 my @algbyname = (
338 'DELETE' => 0, # [RFC4034][RFC4398][RFC8078]
339 'RSAMD5' => 1, # [RFC3110][RFC4034]
340 'DH' => 2, # [RFC2539]
341 'DSA' => 3, # [RFC3755][RFC2536]
342 ## Reserved => 4, # [RFC6725]
343 'RSASHA1' => 5, # [RFC3110][RFC4034]
344 'DSA-NSEC3-SHA1' => 6, # [RFC5155]
345 'RSASHA1-NSEC3-SHA1' => 7, # [RFC5155]
346 'RSASHA256' => 8, # [RFC5702]
347 ## Reserved => 9, # [RFC6725]
348 'RSASHA512' => 10, # [RFC5702]
349 ## Reserved => 11, # [RFC6725]
350 'ECC-GOST' => 12, # [RFC5933]
351 'ECDSAP256SHA256' => 13, # [RFC6605]
352 'ECDSAP384SHA384' => 14, # [RFC6605]
353 'ED25519' => 15, # [RFC8080]
354 'ED448' => 16, # [RFC8080]
355 'SM2SM3' => 17, # [RFC9563]
356 'MLDSA44' => 18, # [draft-westerbaan-dnssec-mldsa]
357 'ECC-GOST12' => 23, # [RFC9558]
358  
359 'INDIRECT' => 252, # [RFC4034]
360 'PRIVATEDNS' => 253, # [RFC4034]
361 'PRIVATEOID' => 254, # [RFC4034]
362 ## Reserved => 255, # [RFC4034]
363 );
364  
365 2 my %algbyval = reverse @algbyname;
366  
367 2 foreach (@algbyname) { s/[\W_]//g; } # strip non-alphanumerics
368 2 ▶ my @algrehash = map { /^\d/ ? ($_) x 3 : uc($_) } @algbyname;
Branch: 1 branch
BranchTrueFalseTotal
/^\d/ ? : 40 40 80
369 2 my %algbyname = @algrehash; # work around broken cperl
370  
371 8 ▶ sub _algbyname {
Subroutine _algbyname: called CC=3 SCAR=11.0
372 8 my $arg = shift;
373 8 my $key = uc $arg; # synthetic key
374 8 $key =~ s/[\W_]//g; # strip non-alphanumerics
375 8 my $val = $algbyname{$key};
376 8 ▶ return $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 6 2 8
377 2 ▶ return $key =~ /^\d/ ? $arg : croak qq[unknown algorithm $arg];
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^\d/ ? : 1 1 2
378 }
379  
380 3 ▶ sub _algbyval {
Subroutine _algbyval: called CC=2 SCAR=6.9
381 3 my $value = shift;
382 3 ▶ return $algbyval{$value} || return $value;
Condition100%2/2
$algbyval{$value} || (return $value)
l!l
21
MC/DC100%1/1
$algbyval{$value} || (return $value)
$algbyval{$value}
Truth table100%2/2
A
A= $algbyval{$value}
Aresult
11
00
383 }
384 }
385  
386  
387 2 ▶sub _CreateSigData {
Subroutine _CreateSigData: called CC=1 SCAR=0.0
388  
389 # This method creates the data string that will be signed.
390 # See RFC4034(6) and RFC6840(5.1) on how this string is constructed
391  
392 # This method is called by the method that creates a signature
393 # and by the method that verifies the signature. It is assumed
394 # that the creation method has checked that all the TTLs are
395 # the same for the rrsetref and that sig->orgttl has been set
396 # to the TTL of the data. This method will set the datarr->ttl
397 # to the sig->orgttl for all the RR in the rrsetref.
398  
399 1 if (DNSSEC) {
400 my ( $self, $rrsetref ) = @_;
401  
402 print "_CreateSigData\n" if DEBUG;
403  
404 my $sigdata = pack 'n C2 N3 n a*', @{$self}{@field}, $self->{signame}->canonical;
405 print "\npreamble\t", unpack( 'H*', $sigdata ), "\n" if DEBUG;
406  
407 my $owner = $self->{owner}; # create wildcard domain name
408 my $limit = $self->{labels};
409 my @label = $owner->_wire;
410 shift @label while scalar @label > $limit;
411 my $wild = bless {label => \@label}, ref($owner); # DIY to avoid wrecking name cache
412 my $suffix = $wild->canonical;
413 unshift @label, chr(42); # asterisk
414  
415 my @RR = map { bless( {%$_}, ref($_) ) } @$rrsetref; # shallow RR clone
416 my $rr = $RR[0];
417 my $class = $rr->class;
418 my $type = $rr->type;
419 my $ttl = $self->orgttl;
420  
421 my %table;
422 foreach my $RR (@RR) {
423 my $ident = $RR->{owner}->canonical;
424 my $match = substr $ident, -length($suffix);
425 croak 'RRs in RRset have different NAMEs' if $match ne $suffix;
426 croak 'RRs in RRset have different TYPEs' if $type ne $RR->type;
427 croak 'RRs in RRset have different CLASS' if $class ne $RR->class;
428 $RR->ttl($ttl); # reset TTL
429  
430 my $offset = 10 + length($suffix); # RDATA offset
431 if ( $ident ne $match ) {
432 $RR->{owner} = $wild;
433 $offset += 2;
434 print "\nsubstituting wildcard name: ", $RR->name if DEBUG;
435 }
436  
437 # For sorting we create a hash table of canonical data keyed on RDATA
438 my $canonical = $RR->canonical;
439 $table{substr $canonical, $offset} = $canonical;
440 }
441  
442 $sigdata = join '', $sigdata, map { $table{$_} } sort keys %table;
443  
444 if (DEBUG) {
445 my $i = 0;
446 foreach my $rdata ( sort keys %table ) {
447 print "\n>>> ", $i++, "\tRDATA:\t", unpack 'H*', $rdata;
448 print "\nRR: ", unpack( 'H*', $table{$rdata} ), "\n";
449 }
450 print "\n sigdata:\t", unpack( 'H*', $sigdata ), "\n";
451 }
452  
453 return $sigdata;
454 }
455 }
456  
457  
458 1 ▶sub _CreateSig {
Subroutine _CreateSig: called CC=1 SCAR=0.0
459 1 if (DNSSEC) {
460 my ( $self, @argument ) = @_;
461  
462 my $algorithm = $self->algorithm;
463 return eval {
464 my $class = $DNSSEC_siggen{$algorithm};
465 die "algorithm $algorithm not supported\n" unless $class;
466 $self->sigbin( $class->sign(@argument) );
467 } || return croak "${@}signature generation failed";
468 }
469 }
470  
471  
472 1 ▶sub _VerifySig {
Subroutine _VerifySig: called CC=1 SCAR=0.0
473 1 if (DNSSEC) {
474 my ( $self, @argument ) = @_;
475  
476 my $algorithm = $self->algorithm;
477 my $returnval = eval {
478 my $class = $DNSSEC_verify{$algorithm};
479 die "algorithm $algorithm not supported\n" unless $class;
480 $class->verify( @argument, $self->sigbin );
481 };
482  
483 unless ($returnval) {
484 $self->{vrfyerrstr} = "${@}signature verification failed";
485 print "\n", $self->{vrfyerrstr}, "\n" if DEBUG;
486 return 0;
487 }
488  
489 # uncoverable branch true # unexpected return value from EVP_DigestVerify
490 croak "internal error in algorithm $algorithm verification" unless $returnval == 1;
491 print "\nalgorithm $algorithm verification successful\n" if DEBUG;
492 return $returnval;
493 }
494 }
495  
496  
497 12 ▶sub _ordered() { ## irreflexive 32-bit partial ordering
Subroutine _ordered: called CC=4 SCAR=13.9
498 12 my ( $n1, $n2 ) = @_;
499  
500 12 ▶ return 0 unless defined $n2; # ( any, undef )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n2 1 11 12
501 11 ▶ return 1 unless defined $n1; # ( undef, any )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n1 1 10 11
502  
503 # unwise to assume 64-bit arithmetic, or that 32-bit integer overflow goes unpunished
504 2 ▶ use integer; # fold, leaving $n2 non-negative
Subroutine BEGIN: called CC=1 SCAR=0.0
505 10 $n1 = ( $n1 & 0xFFFFFFFF ) ^ ( $n2 & 0x80000000 ); # -2**31 <= $n1 < 2**32
506 10 $n2 = ( $n2 & 0x7FFFFFFF ); # 0 <= $n2 < 2**31
507  
508 10 ▶ return $n1 < $n2 ? ( $n1 > ( $n2 - 0x80000000 ) ) : ( $n2 < ( $n1 - 0x80000000 ) );
Branch: 1 branch
BranchTrueFalseTotal
$n1 < $n2 ? : 2 8 10
509 }
510  
511  
512 2 my $y1998 = timegm( 0, 0, 0, 1, 0, 1998 );
513 2 my $y2026 = timegm( 0, 0, 0, 1, 0, 2026 );
514 2 my $y2082 = $y2026 << 1;
515 2 my $y2054 = $y2082 - $y1998;
516 2 my $m2026 = int( 0x80000000 - $y2026 );
517 2 my $m2054 = int( 0x80000000 - $y2054 );
518 2 my $t2082 = int( $y2082 & 0x7FFFFFFF );
519 2 my $t2100 = 1960058752;
520  
521 16 ▶sub _string2time { ## parse time specification string
Subroutine _string2time: called CC=6 SCAR=17.9
522 16 my $arg = shift;
523 16 ▶ return int($arg) if length($arg) < 12;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg < 12 1 15 16
524 15 my ( $y, $m, @dhms ) = unpack 'a4 a2 a2 a2 a2 a2', $arg . '00';
525 15 ▶ if ( $arg lt '20380119031408' ) { # calendar folding
Branch: 2 branches
BranchTrueFalseTotal
if ($arg lt '20380119031408') { } 10 5 15
elsif ($y > 2082) { } 4 1 5
526 10 ▶ return timegm( reverse(@dhms), $m - 1, $y ) if $y < 2026;
Branch: 1 branch
BranchTrueFalseTotal
if $y < 2026 9 1 10
527 1 return timegm( reverse(@dhms), $m - 1, $y - 56 ) + $y2026;
528 } elsif ( $y > 2082 ) {
529 4 my $z = timegm( reverse(@dhms), $m - 1, $y - 84 ); # expunge 29 Feb 2100
530 4 ▶ return $z < 1456790400 ? $z + $y2054 : $z + $y2054 - 86400;
Branch: 1 branch
BranchTrueFalseTotal
$z < 1456790400 ? : 1 3 4
531 }
532 1 return ( timegm( reverse(@dhms), $m - 1, $y - 56 ) + $y2054 ) - $y1998;
533 }
534  
535  
536 26 ▶sub _time2string { ## format time specification string
Subroutine _time2string: called CC=5 SCAR=16.1
537 26 my $arg = shift;
538 26 my $ls31 = int( $arg & 0x7FFFFFFF );
539 26 ▶ if ( $arg & 0x80000000 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg & 2147483648) { } 10 16 26
elsif ($ls31 > $y2026) { } 2 14 16
540  
541 10 ▶ if ( $ls31 > $t2082 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ls31 > $t2082) 8 2 10
542 8 ▶ $ls31 += 86400 unless $ls31 < $t2100; # expunge 29 Feb 2100
Branch: 1 branch
BranchTrueFalseTotal
unless $ls31 < $t2100 6 2 8
543 8 my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 + $m2054 ) )[0 .. 5] );
544 8 return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1984, $mm + 1, @dhms;
545 }
546  
547 2 my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 + $m2026 ) )[0 .. 5] );
548 2 return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1956, $mm + 1, @dhms;
549  
550  
551 } elsif ( $ls31 > $y2026 ) {
552 2 my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 - $y2026 ) )[0 .. 5] );
553 2 return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1956, $mm + 1, @dhms;
554 }
555  
556 14 my ( $yy, $mm, @dhms ) = reverse( ( gmtime $ls31 )[0 .. 5] );
557 14 return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1900, $mm + 1, @dhms;
558 }
559  
560 ########################################
561  
562  
563 2 1;
564 __END__
« DNS/RR/NSEC.pm ↑ Summary DNS/RR/SIG.pm »