File Coverage

blib/lib/Net/DNS/RR/DHCID.pm
Criterion Covered Total %
statement 44 44 100.0
branch n/a
condition 6 6 100.0
subroutine 12 12 100.0
pod 3 3 100.0
total 65 65 100.0


line stmt bran cond sub pod time code
1             package Net::DNS::RR::DHCID;
2              
3 1     1   7 use strict;
  1         2  
  1         29  
4 1     1   5 use warnings;
  1         2  
  1         44  
5             our $VERSION = (qw$Id: DHCID.pm 1896 2023-01-30 12:59:25Z willem $)[2];
6              
7 1     1   6 use base qw(Net::DNS::RR);
  1         3  
  1         96  
8              
9              
10             =head1 NAME
11              
12             Net::DNS::RR::DHCID - DNS DHCID resource record
13              
14             =cut
15              
16 1     1   6 use integer;
  1         2  
  1         4  
17              
18 1     1   37 use MIME::Base64;
  1         2  
  1         556  
19              
20              
21             sub _decode_rdata { ## decode rdata from wire-format octet string
22 1     1   2 my ( $self, $data, $offset ) = @_;
23              
24 1         2 my $size = $self->{rdlength} - 3;
25 1         19 @{$self}{qw(identifiertype digesttype digest)} = unpack "\@$offset nC a$size", $$data;
  1         4  
26 1         5 return;
27             }
28              
29              
30             sub _encode_rdata { ## encode rdata as wire-format octet string
31 10     10   13 my $self = shift;
32              
33 10         19 return pack 'nC a*', map { $self->$_ } qw(identifiertype digesttype digest);
  30         55  
34             }
35              
36              
37             sub _format_rdata { ## format rdata portion of RR string.
38 3     3   4 my $self = shift;
39              
40 3         6 my @rdata = split /\s+/, encode_base64( $self->_encode_rdata );
41 3         11 return @rdata;
42             }
43              
44              
45             sub _parse_rdata { ## populate RR from rdata in argument list
46 1     1   3 my ( $self, @argument ) = @_;
47              
48 1         11 my $data = MIME::Base64::decode( join "", @argument );
49 1         3 my $size = length($data) - 3;
50 1         6 @{$self}{qw(identifiertype digesttype digest)} = unpack "n C a$size", $data;
  1         3  
51 1         3 return;
52             }
53              
54              
55             # +------------------+------------------------------------------------+
56             # | Identifier Type | Identifier |
57             # | Code | |
58             # +------------------+------------------------------------------------+
59             # | 0x0000 | The 1-octet 'htype' followed by 'hlen' octets |
60             # | | of 'chaddr' from a DHCPv4 client's DHCPREQUEST |
61             # | | [7]. |
62             # | 0x0001 | The data octets (i.e., the Type and |
63             # | | Client-Identifier fields) from a DHCPv4 |
64             # | | client's Client Identifier option [10]. |
65             # | 0x0002 | The client's DUID (i.e., the data octets of a |
66             # | | DHCPv6 client's Client Identifier option [11] |
67             # | | or the DUID field from a DHCPv4 client's |
68             # | | Client Identifier option [6]). |
69             # | 0x0003 - 0xfffe | Undefined; available to be assigned by IANA. |
70             # | 0xffff | Undefined; RESERVED. |
71             # +------------------+------------------------------------------------+
72              
73              
74             sub identifiertype {
75 14     14 1 30 my ( $self, @value ) = @_;
76 14         24 for (@value) { $self->{identifiertype} = 0 + $_ }
  2         5  
77 14   100     51 return $self->{identifiertype} || 0;
78             }
79              
80              
81             sub digesttype {
82 14     14 1 1124 my ( $self, @value ) = @_;
83 14         26 for (@value) { $self->{digesttype} = 0 + $_ }
  2         4  
84 14   100     42 return $self->{digesttype} || 0;
85             }
86              
87              
88             sub digest {
89 14     14 1 1429 my ( $self, @value ) = @_;
90 14         20 for (@value) { $self->{digest} = $_ }
  2         4  
91 14   100     104 return $self->{digest} || "";
92             }
93              
94              
95             1;
96             __END__