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