| 1 | package Net::DNS::RR::HIP; | ||||||||||||
| 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: HIP.pm 2003 2025-01-21 12:06:06Z 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::HIP - DNS HIP 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 Net::DNS::DomainName; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 1 | ▶ | use MIME::Base64; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | |||||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | sub _decode_rdata { ## decode rdata from wire-format octet string | ||||||||||
|
Subroutine
_decode_rdata: called CC=3 SCAR=11.0
| |||||||||||||
| 24 | 2 | my ( $self, $data, $offset ) = @_; | |||||||||||
| 25 | |||||||||||||
| 26 | 2 | my ( $hitlen, $pklen ) = unpack "\@$offset Cxn", $$data; | |||||||||||
| 27 | 2 | @{$self}{qw(algorithm hitbin keybin)} = unpack "\@$offset xCxx a$hitlen a$pklen", $$data; | |||||||||||
| 28 | |||||||||||||
| 29 | 2 | my $limit = $offset + $self->{rdlength}; | |||||||||||
| 30 | 2 | $offset += 4 + $hitlen + $pklen; | |||||||||||
| 31 | 2 | $self->{servers} = []; | |||||||||||
| 32 | 2 | ▶ | while ( $offset < $limit ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 4 | my $item; | |||||||||||
| 34 | 4 | ( $item, $offset ) = Net::DNS::DomainName->decode( $data, $offset ); | |||||||||||
| 35 | 4 | push @{$self->{servers}}, $item; | |||||||||||
| 36 | } | ||||||||||||
| 37 | 2 | ▶ | croak('corrupt HIP data') unless $offset == $limit; # more or less FUBAR | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 1 | return; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | 7 | ▶ | sub _encode_rdata { ## encode rdata as wire-format octet string | ||||||||||
|
Subroutine
_encode_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | 7 | my $self = shift; | |||||||||||
| 44 | |||||||||||||
| 45 | 7 | my $hit = $self->hitbin; | |||||||||||
| 46 | 7 | my $key = $self->keybin; | |||||||||||
| 47 | 7 | my $nos = pack 'C2n a* a*', length($hit), $self->algorithm, length($key), $hit, $key; | |||||||||||
| 48 | 7 | return join '', $nos, map { $_->encode } @{$self->{servers}}; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 3 | ▶ | sub _format_rdata { ## format rdata portion of RR string. | ||||||||||
|
Subroutine
_format_rdata: called CC=1 SCAR=0.0
| |||||||||||||
| 53 | 3 | my $self = shift; | |||||||||||
| 54 | |||||||||||||
| 55 | 3 | my $base64 = MIME::Base64::encode( $self->{keybin}, '' ); | |||||||||||
| 56 | 3 | my @server = map { $_->string } @{$self->{servers}}; | |||||||||||
| 57 | 3 | my @rdata = ( $self->algorithm, $self->hit, $base64, @server ); | |||||||||||
| 58 | 3 | return @rdata; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | 3 | ▶ | sub _parse_rdata { ## populate RR from rdata in argument list | ||||||||||
|
Subroutine
_parse_rdata: called CC=2 SCAR=6.9
| |||||||||||||
| 63 | 3 | my ( $self, @argument ) = @_; | |||||||||||
| 64 | |||||||||||||
| 65 | 3 | foreach (qw(algorithm hit key)) { $self->$_( shift @argument ) } | |||||||||||
| 66 | 3 | $self->servers(@argument); | |||||||||||
| 67 | 3 | return; | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | 18 | ▶ | sub algorithm { | ||||||||||
|
Subroutine
algorithm: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 72 | 18 | my ( $self, @value ) = @_; | |||||||||||
| 73 | 18 | for (@value) { $self->{algorithm} = 0 + $_ } | |||||||||||
| 74 | 18 | ▶ | return $self->{algorithm} || 0; | ||||||||||
|
Condition100%2/2
$self->{'algorithm'} || 0
MC/DC100%1/1
$self->{'algorithm'} || 0
$self->{'algorithm'}
Truth table100%2/2
A
A= $self->{'algorithm'}
| |||||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | |||||||||||||
| 78 | 10 | ▶ | sub hit { | ||||||||||
|
Subroutine
hit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 79 | 10 | my ( $self, @value ) = @_; | |||||||||||
| 80 | 10 | ▶ | return unpack "H*", $self->hitbin() unless scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 5 | ▶ | my @hex = map { /^"*([\dA-Fa-f]*)"*$/ || croak("corrupt hex"); $1 } @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 4 | return $self->hitbin( pack "H*", join "", @hex ); | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | |||||||||||||
| 86 | 16 | ▶ | sub hitbin { | ||||||||||
|
Subroutine
hitbin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 87 | 16 | my ( $self, @value ) = @_; | |||||||||||
| 88 | 16 | for (@value) { $self->{hitbin} = $_ } | |||||||||||
| 89 | 16 | ▶ | return $self->{hitbin} || ""; | ||||||||||
|
Condition100%2/2
$self->{'hitbin'} || ''
MC/DC100%1/1
$self->{'hitbin'} || ''
$self->{'hitbin'}
Truth table100%2/2
A
A= $self->{'hitbin'}
| |||||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | |||||||||||||
| 93 | 8 | ▶ | sub key { | ||||||||||
|
Subroutine
key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 94 | 8 | my ( $self, @value ) = @_; | |||||||||||
| 95 | 8 | ▶ | return MIME::Base64::encode( $self->keybin(), "" ) unless scalar @value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 4 | return $self->keybin( MIME::Base64::decode( join "", @value ) ); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | |||||||||||||
| 100 | 17 | ▶ | sub keybin { | ||||||||||
|
Subroutine
keybin: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 101 | 17 | my ( $self, @value ) = @_; | |||||||||||
| 102 | 17 | for (@value) { $self->{keybin} = $_ } | |||||||||||
| 103 | 17 | ▶ | return $self->{keybin} || ""; | ||||||||||
|
Condition100%2/2
$self->{'keybin'} || ''
MC/DC100%1/1
$self->{'keybin'} || ''
$self->{'keybin'}
Truth table100%2/2
A
A= $self->{'keybin'}
| |||||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | |||||||||||||
| 107 | 8 | ▶ | sub servers { | ||||||||||
|
Subroutine
servers: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 108 | 8 | my ( $self, @names ) = @_; | |||||||||||
| 109 | 8 | ▶ | my $servers = $self->{servers} ||= []; | ||||||||||
|
Condition100%2/2
$self->{"servers"} ||= []
MC/DC100%1/1
$self->{"servers"} ||= []
$self->{"servers"}
Truth table100%2/2
A
A= $self->{"servers"}
| |||||||||||||
| 110 | 8 | for (@names) { push @$servers, Net::DNS::DomainName->new($_) } | |||||||||||
| 111 | 8 | ▶ | return defined(wantarray) ? map( { $_->name } @$servers ) : (); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 2 | ▶ | sub rendezvousservers { ## historical | ||||||||||
|
Subroutine
rendezvousservers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 115 | 2 | my @servers = &servers; # uncoverable pod | |||||||||||
| 116 | 2 | return \@servers; | |||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | 2 | ▶ | sub pkalgorithm { ## historical | ||||||||||
|
Subroutine
pkalgorithm: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 120 | 2 | return &algorithm; # uncoverable pod | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | 2 | ▶ | sub pubkey { ## historical | ||||||||||
|
Subroutine
pubkey: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 124 | 2 | return &key; # uncoverable pod | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | |||||||||||||
| 128 | 1 | 1; | |||||||||||
| 129 | __END__ | ||||||||||||