line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## NSEC and NSEC3 bitmaps and base32 |
2
|
|
|
|
|
|
|
package Net::DNS::Extlang::Nsechelp; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::DNS::Extlang::Nsechelp - Helper routines for compiled NSEC and |
8
|
|
|
|
|
|
|
NSEC3 resource records |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Called only from Extlang generated code. No user servicable parts. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
3151914
|
use base qw(Exporter); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
105
|
|
15
|
1
|
|
|
1
|
|
9
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
90
|
|
16
|
|
|
|
|
|
|
@EXPORT = qw(_type2bm _bm2type _encode_base32 _decode_base32); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
12
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
19
|
1
|
|
|
1
|
|
9
|
use Net::DNS::Parameters qw(typebyname typebyval); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1127
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _type2bm { |
22
|
1
|
|
|
1
|
|
246029
|
my @typearray; |
23
|
1
|
|
|
|
|
17
|
foreach my $typename ( map split(), @_ ) { |
24
|
9
|
|
|
|
|
38
|
my $number = typebyname($typename); |
25
|
9
|
|
|
|
|
252306
|
my $window = $number >> 8; |
26
|
9
|
|
|
|
|
20
|
my $bitnum = $number & 255; |
27
|
9
|
|
|
|
|
22
|
my $octet = $bitnum >> 3; |
28
|
9
|
|
|
|
|
17
|
my $bit = $bitnum & 7; |
29
|
9
|
|
|
|
|
33
|
$typearray[$window][$octet] |= 0x80 >> $bit; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
6
|
my $bitmap = ''; |
33
|
1
|
|
|
|
|
3
|
my $window = 0; |
34
|
1
|
|
|
|
|
5
|
foreach (@typearray) { |
35
|
17
|
100
|
|
|
|
49
|
if ( my $pane = $typearray[$window] ) { |
36
|
2
|
|
100
|
|
|
28
|
my @content = map $_ || 0, @$pane; |
37
|
2
|
|
|
|
|
39
|
$bitmap .= pack 'CC C*', $window, scalar(@content), @content; |
38
|
|
|
|
|
|
|
} |
39
|
17
|
|
|
|
|
50
|
$window++; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
7
|
return $bitmap; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _bm2type { |
47
|
3
|
|
|
3
|
|
2869
|
my @typelist; |
48
|
3
|
|
50
|
|
|
15
|
my $bitmap = shift || return @typelist; |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
6
|
my $index = 0; |
51
|
3
|
|
|
|
|
5
|
my $limit = length $bitmap; |
52
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
9
|
while ( $index < $limit ) { |
54
|
6
|
|
|
|
|
22
|
my ( $block, $size ) = unpack "\@$index C2", $bitmap; |
55
|
6
|
|
|
|
|
13
|
my $typenum = $block << 8; |
56
|
6
|
|
|
|
|
19
|
foreach my $octet ( unpack "\@$index xxC$size", $bitmap ) { |
57
|
30
|
|
|
|
|
48
|
my $i = $typenum += 8; |
58
|
30
|
|
|
|
|
38
|
my @name; |
59
|
30
|
|
|
|
|
61
|
while ($octet) { |
60
|
102
|
|
|
|
|
136
|
--$i; |
61
|
102
|
100
|
|
|
|
227
|
unshift @name, typebyval($i) if $octet & 1; |
62
|
102
|
|
|
|
|
316
|
$octet = $octet >> 1; |
63
|
|
|
|
|
|
|
} |
64
|
30
|
|
|
|
|
67
|
push @typelist, @name; |
65
|
|
|
|
|
|
|
} |
66
|
6
|
|
|
|
|
19
|
$index += $size + 2; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
22
|
return @typelist; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _decode_base32 { |
73
|
0
|
|
0
|
0
|
|
|
local $_ = shift || ''; |
74
|
0
|
|
|
|
|
|
tr [0-9a-vA-V] [\000-\037\012-\037]; |
75
|
0
|
|
|
|
|
|
$_ = unpack 'B*', $_; |
76
|
0
|
|
|
|
|
|
s/000(.....)/$1/g; |
77
|
0
|
|
|
|
|
|
my $l = length; |
78
|
0
|
0
|
|
|
|
|
$_ = substr $_, 0, $l & ~7 if $l & 7; |
79
|
0
|
|
|
|
|
|
pack 'B*', $_; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _encode_base32 { |
84
|
0
|
|
|
0
|
|
|
local $_ = unpack 'B*', shift; |
85
|
0
|
|
|
|
|
|
s/(.....)/000$1/g; |
86
|
0
|
|
|
|
|
|
my $l = length; |
87
|
0
|
|
|
|
|
|
my $x = substr $_, $l & ~7; |
88
|
0
|
|
|
|
|
|
my $n = length $x; |
89
|
0
|
0
|
|
|
|
|
substr( $_, $l & ~7 ) = join '', '000', $x, '0' x ( 5 - $n ) if $n; |
90
|
0
|
|
|
|
|
|
$_ = pack( 'B*', $_ ); |
91
|
0
|
|
|
|
|
|
tr [\000-\037] [0-9a-v]; |
92
|
0
|
|
|
|
|
|
return $_; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |