| 1 | package Net::DNS::RR::CERT; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | our $VERSION = (qw$Id: CERT.pm 2042 2025-12-24 10:23:11Z willem $)[2]; | |||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use base qw(Net::DNS::RR); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | |||||||||||||
| 10 | =head1 NAME | ||||||||||||
| 11 | |||||||||||||
| 12 | Net::DNS::RR::CERT - DNS CERT resource record | ||||||||||||
| 13 | |||||||||||||
| 14 | =cut | ||||||||||||
| 15 | |||||||||||||
| 16 | 1 | ▶ | use integer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 1 | ▶ | use MIME::Base64; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 1 | my %certtype = ( | |||||||||||
| 22 | PKIX => 1, # X.509 as per PKIX | ||||||||||||
| 23 | SPKI => 2, # SPKI certificate | ||||||||||||
| 24 | PGP => 3, # OpenPGP packet | ||||||||||||
| 25 | IPKIX => 4, # The URL of an X.509 data object | ||||||||||||
| 26 | ISPKI => 5, # The URL of an SPKI certificate | ||||||||||||
| 27 | IPGP => 6, # The fingerprint and URL of an OpenPGP packet | ||||||||||||
| 28 | ACPKIX => 7, # Attribute Certificate | ||||||||||||
| 29 | IACPKIX => 8, # The URL of an Attribute Certificate | ||||||||||||
| 30 | URI => 253, # URI private | ||||||||||||
| 31 | OID => 254, # OID private | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | |||||||||||||
| 35 | 1 | ▶ | sub _decode_rdata { ## decode rdata from wire-format octet string | ||||||||||
|
Subroutine
_decode_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | 1 | my ( $self, $data, $offset ) = @_; | |||||||||||
| 37 | |||||||||||||
| 38 | 1 | @{$self}{qw(certtype keytag algorithm)} = unpack "\@$offset n2 C", $$data; | |||||||||||
| 39 | 1 | $self->{certbin} = substr $$data, $offset + 5, $self->{rdlength} - 5; | |||||||||||
| 40 | 1 | return; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | |||||||||||||
| 44 | 5 | ▶ | sub _encode_rdata { ## encode rdata as wire-format octet string | ||||||||||
|
Subroutine
_encode_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | 5 | my $self = shift; | |||||||||||
| 46 | |||||||||||||
| 47 | 5 | return pack "n2 C a*", $self->certtype, $self->keytag, $self->algorithm, $self->{certbin}; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | 2 | ▶ | sub _format_rdata { ## format rdata portion of RR string. | ||||||||||
|
Subroutine
_format_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 52 | 2 | my $self = shift; | |||||||||||
| 53 | |||||||||||||
| 54 | 2 | my @param = ( $self->certtype, $self->keytag, $self->algorithm ); | |||||||||||
| 55 | 2 | my @rdata = ( @param, split /\s+/, encode_base64( $self->{certbin} ) ); | |||||||||||
| 56 | 2 | return @rdata; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | 6 | ▶ | sub _parse_rdata { ## populate RR from rdata in argument list | ||||||||||
|
Subroutine
_parse_rdata: called CC=2 SCAR=6.9
| |||||||||||||
| 61 | 6 | my ( $self, @argument ) = @_; | |||||||||||
| 62 | |||||||||||||
| 63 | 6 | foreach (qw(certtype keytag algorithm)) { | |||||||||||
| 64 | 18 | $self->$_( shift @argument ); | |||||||||||
| 65 | } | ||||||||||||
| 66 | 6 | $self->cert(@argument); | |||||||||||
| 67 | 6 | return; | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | 20 | ▶ | sub certtype { | ||||||||||
|
Subroutine
certtype: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 72 | 20 | my ( $self, @value ) = @_; | |||||||||||
| 73 | |||||||||||||
| 74 | 20 | ▶ | return $self->{certtype} unless scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | |||||||||||||
| 76 | 9 | my $certtype = shift @value; | |||||||||||
| 77 | 9 | ▶ | return $self->{certtype} = $certtype unless $certtype =~ /\D/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | |||||||||||||
| 79 | 2 | my $typenum = $certtype{$certtype}; | |||||||||||
| 80 | 2 | ▶ | $typenum || croak qq[unknown certtype $certtype]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 1 | return $self->{certtype} = $typenum; | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | |||||||||||||
| 85 | 18 | ▶ | sub keytag { | ||||||||||
|
Subroutine
keytag: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 86 | 18 | my ( $self, @value ) = @_; | |||||||||||
| 87 | 18 | for (@value) { $self->{keytag} = 0 + $_ } | |||||||||||
| 88 | 18 | ▶ | 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'}
| |||||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | |||||||||||||
| 92 | 20 | ▶ | sub algorithm { | ||||||||||
|
Subroutine
algorithm: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 93 | 20 | my ( $self, $arg ) = @_; | |||||||||||
| 94 | |||||||||||||
| 95 | 20 | ▶ | return $self->{algorithm} unless defined $arg; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 11 | ▶ | return _algbyval( $self->{algorithm} ) if uc($arg) eq 'MNEMONIC'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 9 | return $self->{algorithm} = _algbyname($arg); | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | |||||||||||||
| 101 | 2 | ▶ | sub certificate { return &certbin; } | ||||||||||
|
Subroutine
certificate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 102 | |||||||||||||
| 103 | |||||||||||||
| 104 | 11 | ▶ | sub certbin { | ||||||||||
|
Subroutine
certbin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 105 | 11 | my ( $self, @value ) = @_; | |||||||||||
| 106 | 11 | for (@value) { $self->{certbin} = $_ } | |||||||||||
| 107 | 11 | ▶ | return $self->{certbin} || ""; | ||||||||||
|
Condition100%2/2
$self->{'certbin'} || ''
MC/DC100%1/1
$self->{'certbin'} || ''
$self->{'certbin'}
Truth table100%2/2
A
A= $self->{'certbin'}
| |||||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | |||||||||||||
| 111 | 9 | ▶ | sub cert { | ||||||||||
|
Subroutine
cert: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 112 | 9 | my ( $self, @value ) = @_; | |||||||||||
| 113 | 9 | ▶ | return MIME::Base64::encode( $self->certbin(), "" ) unless scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 7 | return $self->certbin( MIME::Base64::decode( join "", @value ) ); | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | |||||||||||||
| 118 | 2 | ▶ | sub format { return &certtype; } # uncoverable pod | ||||||||||
|
Subroutine
format: called CC=1 SCAR=0.0
Pod
undocumented (uncoverable)
| |||||||||||||
| 119 | |||||||||||||
| 120 | 2 | ▶ | sub tag { return &keytag; } # uncoverable pod | ||||||||||
|
Subroutine
tag: called CC=1 SCAR=0.0
Pod
undocumented (uncoverable)
| |||||||||||||
| 121 | |||||||||||||
| 122 | |||||||||||||
| 123 | ######################################## | ||||||||||||
| 124 | |||||||||||||
| 125 | { | ||||||||||||
| 126 | 1 | my @algbyname = ( | |||||||||||
| 127 | 'DELETE' => 0, # [RFC4034][RFC4398][RFC8078] | ||||||||||||
| 128 | 'RSAMD5' => 1, # [RFC3110][RFC4034] | ||||||||||||
| 129 | 'DH' => 2, # [RFC2539] | ||||||||||||
| 130 | 'DSA' => 3, # [RFC3755][RFC2536] | ||||||||||||
| 131 | ## Reserved => 4, # [RFC6725] | ||||||||||||
| 132 | 'RSASHA1' => 5, # [RFC3110][RFC4034] | ||||||||||||
| 133 | 'DSA-NSEC3-SHA1' => 6, # [RFC5155] | ||||||||||||
| 134 | 'RSASHA1-NSEC3-SHA1' => 7, # [RFC5155] | ||||||||||||
| 135 | 'RSASHA256' => 8, # [RFC5702] | ||||||||||||
| 136 | ## Reserved => 9, # [RFC6725] | ||||||||||||
| 137 | 'RSASHA512' => 10, # [RFC5702] | ||||||||||||
| 138 | ## Reserved => 11, # [RFC6725] | ||||||||||||
| 139 | 'ECC-GOST' => 12, # [RFC5933] | ||||||||||||
| 140 | 'ECDSAP256SHA256' => 13, # [RFC6605] | ||||||||||||
| 141 | 'ECDSAP384SHA384' => 14, # [RFC6605] | ||||||||||||
| 142 | 'ED25519' => 15, # [RFC8080] | ||||||||||||
| 143 | 'ED448' => 16, # [RFC8080] | ||||||||||||
| 144 | 'SM2SM3' => 17, # [RFC9563] | ||||||||||||
| 145 | 'ECC-GOST12' => 23, # [RFC9558] | ||||||||||||
| 146 | |||||||||||||
| 147 | 'INDIRECT' => 252, # [RFC4034] | ||||||||||||
| 148 | 'PRIVATEDNS' => 253, # [RFC4034] | ||||||||||||
| 149 | 'PRIVATEOID' => 254, # [RFC4034] | ||||||||||||
| 150 | ## Reserved => 255, # [RFC4034] | ||||||||||||
| 151 | ); | ||||||||||||
| 152 | |||||||||||||
| 153 | 1 | my %algbyval = reverse @algbyname; | |||||||||||
| 154 | |||||||||||||
| 155 | 1 | foreach (@algbyname) { s/[\W_]//g; } # strip non-alphanumerics | |||||||||||
| 156 | 1 | ▶ | my @algrehash = map { /^\d/ ? ($_) x 3 : uc($_) } @algbyname; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 157 | 1 | my %algbyname = @algrehash; # work around broken cperl | |||||||||||
| 158 | |||||||||||||
| 159 | 9 | ▶ | sub _algbyname { | ||||||||||
|
Subroutine
_algbyname: called CC=3 SCAR=11.0
| |||||||||||||
| 160 | 9 | my $arg = shift; | |||||||||||
| 161 | 9 | my $key = uc $arg; # synthetic key | |||||||||||
| 162 | 9 | $key =~ s/[\W_]//g; # strip non-alphanumerics | |||||||||||
| 163 | 9 | my $val = $algbyname{$key}; | |||||||||||
| 164 | 9 | ▶ | return $val if defined $val; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 165 | 2 | ▶ | return $key =~ /^\d/ ? $arg : croak qq[unknown algorithm $arg]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 166 | } | ||||||||||||
| 167 | |||||||||||||
| 168 | 2 | ▶ | sub _algbyval { | ||||||||||
|
Subroutine
_algbyval: called CC=2 SCAR=6.9
| |||||||||||||
| 169 | 2 | my $value = shift; | |||||||||||
| 170 | 2 | ▶ | 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}
| |||||||||||||
| 171 | } | ||||||||||||
| 172 | } | ||||||||||||
| 173 | |||||||||||||
| 174 | ######################################## | ||||||||||||
| 175 | |||||||||||||
| 176 | |||||||||||||
| 177 | 1 | 1; | |||||||||||
| 178 | __END__ | ||||||||||||