| 1 | package Net::DNS::RR::SIG; | ||||||||||||||||||||||||||||
| 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: SIG.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::SIG - DNS SIG 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 | my @field = qw(typecovered algorithm labels orgttl sigexpiration siginception keytag); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub _decode_rdata { ## decode rdata from wire-format octet string | ||||||||||||||||||||||||||
|
Subroutine
_decode_rdata: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 2 | my ( $self, $data, $offset, @opaque ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | my $limit = $offset + $self->{rdlength}; | |||||||||||||||||||||||||||
| 54 | 2 | ▶ | croak('misplaced or corrupt SIG') unless $limit == length $$data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 1 | my $raw = substr $$data, 0, $self->{offset}++; | |||||||||||||||||||||||||||
| 56 | 1 | $self->{rawref} = \$raw; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | @{$self}{@field} = unpack "\@$offset n C2 N3 n", $$data; | |||||||||||||||||||||||||||
| 59 | 1 | ( $self->{signame}, $offset ) = Net::DNS::DomainName->decode( $data, $offset + 18, @opaque ); | |||||||||||||||||||||||||||
| 60 | 1 | $self->{sigbin} = substr $$data, $offset, $limit - $offset; | |||||||||||||||||||||||||||
| 61 | 1 | return; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 7 | ▶ | sub _encode_rdata { ## encode rdata as wire-format octet string | ||||||||||||||||||||||||||
|
Subroutine
_encode_rdata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 7 | my ( $self, $offset, @opaque ) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 7 | my $signame = $self->{signame}; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 7 | if ( DNSSEC && !$self->{sigbin} ) { | |||||||||||||||||||||||||||
| 71 | my ( undef, $packet ) = @opaque; | ||||||||||||||||||||||||||||
| 72 | my $private = delete $self->{private}; # one shot is all you get | ||||||||||||||||||||||||||||
| 73 | my $sigdata = $self->_CreateSigData($packet); | ||||||||||||||||||||||||||||
| 74 | $self->_CreateSig( $sigdata, $private || die 'missing key reference' ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 7 | return pack 'n C2 N3 n a* a*', @{$self}{@field}, $signame->canonical, $self->sigbin; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | sub _format_rdata { ## format rdata portion of RR string. | ||||||||||||||||||||||||||
|
Subroutine
_format_rdata: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 82 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 4 | ▶ | my $sname = $self->{signame} || return ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'signame'} || (return '')
MC/DC100%1/1
$self->{'signame'} || (return '')
$self->{'signame'}
Truth table100%2/2
A
A= $self->{'signame'}
| |||||||||||||||||||||||||||||
| 85 | 3 | my @sig64 = split /\s+/, MIME::Base64::encode( $self->sigbin ); | |||||||||||||||||||||||||||
| 86 | 3 | my @rdata = ( map( { $self->$_ } @field ), $sname->string, @sig64 ); | |||||||||||||||||||||||||||
| 87 | 3 | return @rdata; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub _parse_rdata { ## populate RR from rdata in argument list | ||||||||||||||||||||||||||
|
Subroutine
_parse_rdata: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 92 | 2 | my ( $self, @argument ) = @_; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 2 | foreach ( @field, qw(signame) ) { $self->$_( shift @argument ) } | |||||||||||||||||||||||||||
| 95 | 2 | $self->signature(@argument); | |||||||||||||||||||||||||||
| 96 | 2 | return; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | sub _defaults { ## specify RR attribute default values | ||||||||||||||||||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | $self->class('ANY'); | |||||||||||||||||||||||||||
| 104 | 2 | $self->typecovered('TYPE0'); | |||||||||||||||||||||||||||
| 105 | 2 | $self->algorithm(1); | |||||||||||||||||||||||||||
| 106 | 2 | $self->labels(0); | |||||||||||||||||||||||||||
| 107 | 2 | $self->orgttl(0); | |||||||||||||||||||||||||||
| 108 | 2 | $self->sigval(10); | |||||||||||||||||||||||||||
| 109 | 2 | return; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 10 | ▶ | sub typecovered { | ||||||||||||||||||||||||||
|
Subroutine
typecovered: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 10 | my ( $self, @value ) = @_; # uncoverable pod | |||||||||||||||||||||||||||
| 115 | 10 | for (@value) { $self->{typecovered} = typebyname($_) } | |||||||||||||||||||||||||||
| 116 | 10 | my $typecode = $self->{typecovered}; | |||||||||||||||||||||||||||
| 117 | 10 | ▶ | return defined $typecode ? typebyval($typecode) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 22 | ▶ | sub algorithm { | ||||||||||||||||||||||||||
|
Subroutine
algorithm: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 22 | my ( $self, $arg ) = @_; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 22 | ▶ | unless ( ref($self) ) { ## class method or simple function | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 3 | my $argn = pop; | |||||||||||||||||||||||||||
| 126 | 3 | ▶ | return $argn =~ /[^0-9]/ ? _algbyname($argn) : _algbyval($argn); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 19 | ▶ | return $self->{algorithm} unless defined $arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 9 | ▶ | return _algbyval( $self->{algorithm} ) if $arg =~ /MNEMONIC/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 8 | return $self->{algorithm} = _algbyname($arg); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 10 | ▶ | sub labels { | ||||||||||||||||||||||||||
|
Subroutine
labels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 10 | return shift->{labels} = 0; # uncoverable pod | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 10 | ▶ | sub orgttl { | ||||||||||||||||||||||||||
|
Subroutine
orgttl: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 10 | return shift->{orgttl} = 0; # uncoverable pod | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 10 | ▶ | sub sigexpiration { | ||||||||||||||||||||||||||
|
Subroutine
sigexpiration: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 10 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 147 | 10 | for (@value) { $self->{sigexpiration} = _string2time($_) } | |||||||||||||||||||||||||||
| 148 | 10 | my $time = $self->{sigexpiration}; | |||||||||||||||||||||||||||
| 149 | 10 | ▶ | return unless defined wantarray && defined $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined wantarray and defined $time
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
| |||||||||||||||||||||||||||||
| 150 | 6 | return UTIL ? Scalar::Util::dualvar( $time, _time2string($time) ) : _time2string($time); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 10 | ▶ | sub siginception { | ||||||||||||||||||||||||||
|
Subroutine
siginception: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 10 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 155 | 10 | for (@value) { $self->{siginception} = _string2time($_) } | |||||||||||||||||||||||||||
| 156 | 10 | my $time = $self->{siginception}; | |||||||||||||||||||||||||||
| 157 | 10 | ▶ | return unless defined wantarray && defined $time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined wantarray and defined $time
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
| |||||||||||||||||||||||||||||
| 158 | 6 | return UTIL ? Scalar::Util::dualvar( $time, _time2string($time) ) : _time2string($time); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 2 | ▶ | sub sigex { return &sigexpiration; } ## historical | ||||||||||||||||||||||||||
|
Subroutine
sigex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 2 | ▶ | sub sigin { return &siginception; } ## historical | ||||||||||||||||||||||||||
|
Subroutine
sigin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 2 | ▶ | sub sigval { | ||||||||||||||||||||||||||
|
Subroutine
sigval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 2 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 167 | 2 | ▶ | no integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 168 | 2 | ( $self->{sigval} ) = map { int( 60.0 * $_ ) } @value; | |||||||||||||||||||||||||||
| 169 | 2 | return; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 8 | ▶ | sub keytag { | ||||||||||||||||||||||||||
|
Subroutine
keytag: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 8 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 175 | 8 | for (@value) { $self->{keytag} = 0 + $_ } | |||||||||||||||||||||||||||
| 176 | 8 | ▶ | return $self->{keytag} || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'keytag'} || 0
MC/DC100%1/1
$self->{'keytag'} || 0
$self->{'keytag'}
Truth table100%2/2
A
A= $self->{'keytag'}
| |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 5 | ▶ | sub signame { | ||||||||||||||||||||||||||
|
Subroutine
signame: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 5 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 182 | 5 | for (@value) { $self->{signame} = Net::DNS::DomainName2535->new($_) } | |||||||||||||||||||||||||||
| 183 | 5 | ▶ | return $self->{signame} ? $self->{signame}->name : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 7 | ▶ | sub sig { | ||||||||||||||||||||||||||
|
Subroutine
sig: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 7 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 189 | 7 | ▶ | return MIME::Base64::encode( $self->sigbin(), "" ) unless scalar @value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 3 | return $self->sigbin( MIME::Base64::decode( join "", @value ) ); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 19 | ▶ | sub sigbin { | ||||||||||||||||||||||||||
|
Subroutine
sigbin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 19 | my ( $self, @value ) = @_; | |||||||||||||||||||||||||||
| 196 | 19 | for (@value) { $self->{sigbin} = $_ } | |||||||||||||||||||||||||||
| 197 | 19 | ▶ | return $self->{sigbin} || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'sigbin'} || ''
MC/DC100%1/1
$self->{'sigbin'} || ''
$self->{'sigbin'}
Truth table100%2/2
A
A= $self->{'sigbin'}
| |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 5 | ▶ | sub signature { return &sig; } | ||||||||||||||||||||||||||
|
Subroutine
signature: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 2 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 2 | unless (DNSSEC) { | |||||||||||||||||||||||||||
| 206 | 2 | croak qq[No "use Net::DNS::SEC" declaration in application code]; | |||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||
| 208 | my ( $class, $data, $priv_key, %etc ) = @_; | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | my $private = ref($priv_key) ? $priv_key : ( Net::DNS::SEC::Private->new($priv_key) ); | ||||||||||||||||||||||||||||
| 211 | croak 'Unable to parse private key' unless ref($private) eq 'Net::DNS::SEC::Private'; | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | my $self = Net::DNS::RR->new( | ||||||||||||||||||||||||||||
| 214 | type => 'SIG', | ||||||||||||||||||||||||||||
| 215 | typecovered => 'TYPE0', | ||||||||||||||||||||||||||||
| 216 | siginception => time(), | ||||||||||||||||||||||||||||
| 217 | algorithm => $private->algorithm, | ||||||||||||||||||||||||||||
| 218 | keytag => $private->keytag, | ||||||||||||||||||||||||||||
| 219 | signame => $private->signame, | ||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | while ( my ( $attribute, $value ) = each %etc ) { | ||||||||||||||||||||||||||||
| 223 | $self->$attribute($value); | ||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | $self->{sigexpiration} = $self->{siginception} + $self->{sigval} | ||||||||||||||||||||||||||||
| 227 | unless $self->{sigexpiration}; | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | $self->_CreateSig( $self->_CreateSigData($data), $private ) if $data; | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | $self->{private} = $private unless $data; # mark packet for SIG0 generation | ||||||||||||||||||||||||||||
| 232 | return $self; | ||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 2 | ▶ | sub verify { | ||||||||||||||||||||||||||
|
Subroutine
verify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | # Reminder... | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # $dataref may be either a data string or a reference to a | ||||||||||||||||||||||||||||
| 242 | # Net::DNS::Packet object. | ||||||||||||||||||||||||||||
| 243 | # | ||||||||||||||||||||||||||||
| 244 | # $keyref is either a key object or a reference to an array | ||||||||||||||||||||||||||||
| 245 | # of keys. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 2 | unless (DNSSEC) { | |||||||||||||||||||||||||||
| 248 | 2 | croak qq[No "use Net::DNS::SEC" declaration in application code]; | |||||||||||||||||||||||||||
| 249 | } else { | ||||||||||||||||||||||||||||
| 250 | my ( $self, $dataref, $keyref ) = @_; | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | if ( my $isa = ref($dataref) ) { | ||||||||||||||||||||||||||||
| 253 | print '$dataref argument is ', $isa, "\n" if DEBUG; | ||||||||||||||||||||||||||||
| 254 | croak '$dataref must be scalar or a Net::DNS::Packet' | ||||||||||||||||||||||||||||
| 255 | unless $isa =~ /Net::DNS/ && $dataref->isa('Net::DNS::Packet'); | ||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | print '$keyref argument is of class ', ref($keyref), "\n" if DEBUG; | ||||||||||||||||||||||||||||
| 259 | if ( ref($keyref) eq "ARRAY" ) { | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | # We will iterate over the supplied key list and | ||||||||||||||||||||||||||||
| 262 | # return when there is a successful verification. | ||||||||||||||||||||||||||||
| 263 | # If not, continue so that we survive key-id collision. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | print "Iterating over ", scalar(@$keyref), " keys\n" if DEBUG; | ||||||||||||||||||||||||||||
| 266 | my @error; | ||||||||||||||||||||||||||||
| 267 | foreach my $keyrr (@$keyref) { | ||||||||||||||||||||||||||||
| 268 | my $result = $self->verify( $dataref, $keyrr ); | ||||||||||||||||||||||||||||
| 269 | return $result if $result; | ||||||||||||||||||||||||||||
| 270 | my $error = $self->{vrfyerrstr}; | ||||||||||||||||||||||||||||
| 271 | my $keyid = $keyrr->keytag; | ||||||||||||||||||||||||||||
| 272 | push @error, "key $keyid: $error"; | ||||||||||||||||||||||||||||
| 273 | print "key $keyid: $error\n" if DEBUG; | ||||||||||||||||||||||||||||
| 274 | next; | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | $self->{vrfyerrstr} = join "\n", @error; | ||||||||||||||||||||||||||||
| 278 | return 0; | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | } elsif ( $keyref->isa('Net::DNS::RR::DNSKEY') ) { | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | print "Validating using key with keytag: ", $keyref->keytag, "\n" if DEBUG; | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | } else { | ||||||||||||||||||||||||||||
| 285 | croak join ' ', ref($keyref), 'can not be used as SIG0 key'; | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | croak "SIG typecovered is TYPE$self->{typecovered}" if $self->{typecovered}; | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | if (DEBUG) { | ||||||||||||||||||||||||||||
| 291 | print "\n ---------------------- SIG 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 | # The data that is to be verified | ||||||||||||||||||||||||||||
| 309 | my $sigdata = $self->_CreateSigData($dataref); | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | my $verified = $self->_VerifySig( $sigdata, $keyref ) || return 0; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | # time to do some time checking. | ||||||||||||||||||||||||||||
| 314 | my $t = time; | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | if ( _ordered( $self->{sigexpiration}, $t ) ) { | ||||||||||||||||||||||||||||
| 317 | $self->{vrfyerrstr} = join ' ', 'Signature expired at', $self->sigexpiration; | ||||||||||||||||||||||||||||
| 318 | return 0; | ||||||||||||||||||||||||||||
| 319 | } elsif ( _ordered( $t, $self->{siginception} ) ) { | ||||||||||||||||||||||||||||
| 320 | $self->{vrfyerrstr} = join ' ', 'Signature valid from', $self->siginception; | ||||||||||||||||||||||||||||
| 321 | return 0; | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | return 1; | ||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | } #END verify | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 2 | ▶ | sub vrfyerrstr { | ||||||||||||||||||||||||||
|
Subroutine
vrfyerrstr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 330 | 2 | return shift->{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
| |||||||||||||||||||||||||||||
| 369 | 2 | my %algbyname = @algrehash; # work around broken cperl | |||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 9 | ▶ | sub _algbyname { | ||||||||||||||||||||||||||
|
Subroutine
_algbyname: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 372 | 9 | my $arg = shift; | |||||||||||||||||||||||||||
| 373 | 9 | my $key = uc $arg; # synthetic key | |||||||||||||||||||||||||||
| 374 | 9 | $key =~ s/[\W_]//g; # strip non-alphanumerics | |||||||||||||||||||||||||||
| 375 | 9 | my $val = $algbyname{$key}; | |||||||||||||||||||||||||||
| 376 | 9 | ▶ | return $val if defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 2 | ▶ | return $key =~ /^\d/ ? $arg : croak qq[unknown algorithm $arg]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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)
MC/DC100%1/1
$algbyval{$value} || (return $value)
$algbyval{$value}
Truth table100%2/2
A
A= $algbyval{$value}
| |||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||
| 388 | 2 | my %siglen = ( | |||||||||||||||||||||||||||
| 389 | 1 => 128, | ||||||||||||||||||||||||||||
| 390 | 3 => 41, | ||||||||||||||||||||||||||||
| 391 | 5 => 256, | ||||||||||||||||||||||||||||
| 392 | 6 => 41, | ||||||||||||||||||||||||||||
| 393 | 7 => 256, | ||||||||||||||||||||||||||||
| 394 | 8 => 256, | ||||||||||||||||||||||||||||
| 395 | 10 => 256, | ||||||||||||||||||||||||||||
| 396 | 12 => 64, | ||||||||||||||||||||||||||||
| 397 | 13 => 64, | ||||||||||||||||||||||||||||
| 398 | 14 => 96, | ||||||||||||||||||||||||||||
| 399 | 15 => 64, | ||||||||||||||||||||||||||||
| 400 | 16 => 114, | ||||||||||||||||||||||||||||
| 401 | ); | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 2 | ▶ | sub _size { ## estimate encoded size | ||||||||||||||||||||||||||
|
Subroutine
_size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 404 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 405 | 2 | my $clone = bless {%$self}, ref($self); # shallow clone | |||||||||||||||||||||||||||
| 406 | 2 | $clone->sigbin( 'x' x $siglen{$self->algorithm} ); | |||||||||||||||||||||||||||
| 407 | 2 | return length $clone->encode(); | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 2 | ▶ | sub _CreateSigData { | ||||||||||||||||||||||||||
|
Subroutine
_CreateSigData: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 413 | 1 | if (DNSSEC) { | |||||||||||||||||||||||||||
| 414 | my ( $self, $message ) = @_; | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | if ( ref($message) ) { | ||||||||||||||||||||||||||||
| 417 | die 'missing packet reference' unless $message->isa('Net::DNS::Packet'); | ||||||||||||||||||||||||||||
| 418 | my @unsigned = grep { ref($_) ne ref($self) } @{$message->{additional}}; | ||||||||||||||||||||||||||||
| 419 | local $message->{additional} = \@unsigned; # remake header image | ||||||||||||||||||||||||||||
| 420 | my @part = qw(question answer authority additional); | ||||||||||||||||||||||||||||
| 421 | my @size = map { scalar @{$message->{$_}} } @part; | ||||||||||||||||||||||||||||
| 422 | my $rref = delete $self->{rawref}; | ||||||||||||||||||||||||||||
| 423 | my $data = $rref ? $$rref : $message->encode; | ||||||||||||||||||||||||||||
| 424 | my ( $id, $status ) = unpack 'n2', $data; | ||||||||||||||||||||||||||||
| 425 | my $hbin = pack 'n6 a*', $id, $status, @size; | ||||||||||||||||||||||||||||
| 426 | $message = $hbin . substr $data, length $hbin; | ||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | my $sigdata = pack 'n C2 N3 n a*', @{$self}{@field}, $self->{signame}->encode; | ||||||||||||||||||||||||||||
| 430 | print "\npreamble\t", unpack( 'H*', $sigdata ), "\nrawdata\t", unpack( 'H100', $message ), " ...\n" | ||||||||||||||||||||||||||||
| 431 | if DEBUG; | ||||||||||||||||||||||||||||
| 432 | return join '', $sigdata, $message; | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 1 | ▶ | sub _CreateSig { | ||||||||||||||||||||||||||
|
Subroutine
_CreateSig: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 438 | 1 | if (DNSSEC) { | |||||||||||||||||||||||||||
| 439 | my ( $self, @argument ) = @_; | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | my $algorithm = $self->algorithm; | ||||||||||||||||||||||||||||
| 442 | return eval { | ||||||||||||||||||||||||||||
| 443 | my $class = $DNSSEC_siggen{$algorithm}; | ||||||||||||||||||||||||||||
| 444 | die "algorithm $algorithm not supported\n" unless $class; | ||||||||||||||||||||||||||||
| 445 | $self->sigbin( $class->sign(@argument) ); | ||||||||||||||||||||||||||||
| 446 | } || return croak "${@}signature generation failed"; | ||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 1 | ▶ | sub _VerifySig { | ||||||||||||||||||||||||||
|
Subroutine
_VerifySig: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 452 | 1 | if (DNSSEC) { | |||||||||||||||||||||||||||
| 453 | my ( $self, @argument ) = @_; | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | my $algorithm = $self->algorithm; | ||||||||||||||||||||||||||||
| 456 | my $returnval = eval { | ||||||||||||||||||||||||||||
| 457 | my $class = $DNSSEC_verify{$algorithm}; | ||||||||||||||||||||||||||||
| 458 | die "algorithm $algorithm not supported\n" unless $class; | ||||||||||||||||||||||||||||
| 459 | $class->verify( @argument, $self->sigbin ); | ||||||||||||||||||||||||||||
| 460 | }; | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | unless ($returnval) { | ||||||||||||||||||||||||||||
| 463 | $self->{vrfyerrstr} = "${@}signature verification failed"; | ||||||||||||||||||||||||||||
| 464 | print "\n", $self->{vrfyerrstr}, "\n" if DEBUG; | ||||||||||||||||||||||||||||
| 465 | return 0; | ||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | # uncoverable branch true # unexpected return value from EVP_DigestVerify | ||||||||||||||||||||||||||||
| 469 | croak "internal error in algorithm $algorithm verification" unless $returnval == 1; | ||||||||||||||||||||||||||||
| 470 | print "\nalgorithm $algorithm verification successful\n" if DEBUG; | ||||||||||||||||||||||||||||
| 471 | return $returnval; | ||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 12 | ▶ | sub _ordered() { ## irreflexive 32-bit partial ordering | ||||||||||||||||||||||||||
|
Subroutine
_ordered: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 477 | 12 | my ( $n1, $n2 ) = @_; | |||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 12 | ▶ | return 0 unless defined $n2; # ( any, undef ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | 11 | ▶ | return 1 unless defined $n1; # ( undef, any ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | # unwise to assume 64-bit arithmetic, or that 32-bit integer overflow goes unpunished | ||||||||||||||||||||||||||||
| 483 | 2 | ▶ | use integer; # fold, leaving $n2 non-negative | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 484 | 10 | $n1 = ( $n1 & 0xFFFFFFFF ) ^ ( $n2 & 0x80000000 ); # -2**31 <= $n1 < 2**32 | |||||||||||||||||||||||||||
| 485 | 10 | $n2 = ( $n2 & 0x7FFFFFFF ); # 0 <= $n2 < 2**31 | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 10 | ▶ | return $n1 < $n2 ? ( $n1 > ( $n2 - 0x80000000 ) ) : ( $n2 < ( $n1 - 0x80000000 ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 2 | my $y1998 = timegm( 0, 0, 0, 1, 0, 1998 ); | |||||||||||||||||||||||||||
| 492 | 2 | my $y2026 = timegm( 0, 0, 0, 1, 0, 2026 ); | |||||||||||||||||||||||||||
| 493 | 2 | my $y2082 = $y2026 << 1; | |||||||||||||||||||||||||||
| 494 | 2 | my $y2054 = $y2082 - $y1998; | |||||||||||||||||||||||||||
| 495 | 2 | my $m2026 = int( 0x80000000 - $y2026 ); | |||||||||||||||||||||||||||
| 496 | 2 | my $m2054 = int( 0x80000000 - $y2054 ); | |||||||||||||||||||||||||||
| 497 | 2 | my $t2082 = int( $y2082 & 0x7FFFFFFF ); | |||||||||||||||||||||||||||
| 498 | 2 | my $t2100 = 1960058752; | |||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 14 | ▶ | sub _string2time { ## parse time specification string | ||||||||||||||||||||||||||
|
Subroutine
_string2time: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 501 | 14 | my $arg = shift; | |||||||||||||||||||||||||||
| 502 | 14 | ▶ | return int($arg) if length($arg) < 12; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 503 | 13 | my ( $y, $m, @dhms ) = unpack 'a4 a2 a2 a2 a2 a2', $arg . '00'; | |||||||||||||||||||||||||||
| 504 | 13 | ▶ | if ( $arg lt '20380119031408' ) { # calendar folding | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 505 | 8 | ▶ | return timegm( reverse(@dhms), $m - 1, $y ) if $y < 2026; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | 1 | return timegm( reverse(@dhms), $m - 1, $y - 56 ) + $y2026; | |||||||||||||||||||||||||||
| 507 | } elsif ( $y > 2082 ) { | ||||||||||||||||||||||||||||
| 508 | 4 | my $z = timegm( reverse(@dhms), $m - 1, $y - 84 ); # expunge 29 Feb 2100 | |||||||||||||||||||||||||||
| 509 | 4 | ▶ | return $z < 1456790400 ? $z + $y2054 : $z + $y2054 - 86400; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||
| 511 | 1 | return ( timegm( reverse(@dhms), $m - 1, $y - 56 ) + $y2054 ) - $y1998; | |||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 26 | ▶ | sub _time2string { ## format time specification string | ||||||||||||||||||||||||||
|
Subroutine
_time2string: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 516 | 26 | my $arg = shift; | |||||||||||||||||||||||||||
| 517 | 26 | my $ls31 = int( $arg & 0x7FFFFFFF ); | |||||||||||||||||||||||||||
| 518 | 26 | ▶ | if ( $arg & 0x80000000 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 10 | ▶ | if ( $ls31 > $t2082 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | 8 | ▶ | $ls31 += 86400 unless $ls31 < $t2100; # expunge 29 Feb 2100 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | 8 | my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 + $m2054 ) )[0 .. 5] ); | |||||||||||||||||||||||||||
| 523 | 8 | return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1984, $mm + 1, @dhms; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 2 | my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 + $m2026 ) )[0 .. 5] ); | |||||||||||||||||||||||||||
| 527 | 2 | return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1956, $mm + 1, @dhms; | |||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | } elsif ( $ls31 > $y2026 ) { | ||||||||||||||||||||||||||||
| 531 | 2 | my ( $yy, $mm, @dhms ) = reverse( ( gmtime( $ls31 - $y2026 ) )[0 .. 5] ); | |||||||||||||||||||||||||||
| 532 | 2 | return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1956, $mm + 1, @dhms; | |||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | 14 | my ( $yy, $mm, @dhms ) = reverse( ( gmtime $ls31 )[0 .. 5] ); | |||||||||||||||||||||||||||
| 536 | 14 | return sprintf '%d%02d%02d%02d%02d%02d', $yy + 1900, $mm + 1, @dhms; | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | ######################################## | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 2 | 1; | |||||||||||||||||||||||||||
| 543 | __END__ | ||||||||||||||||||||||||||||