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
|
|
702
|
use base qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
15
|
1
|
|
|
1
|
|
5
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
16
|
|
|
|
|
|
|
@EXPORT = qw(_type2bm _bm2type _encode_base32 _decode_base32); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
19
|
1
|
|
|
1
|
|
5
|
use Net::DNS::Parameters qw(typebyname typebyval); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
633
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _type2bm { |
22
|
3
|
|
|
3
|
|
1625
|
my @typearray; |
23
|
3
|
|
|
|
|
14
|
foreach my $typename ( map split(), @_ ) { |
24
|
3
|
|
|
|
|
11
|
my $number = typebyname($typename); |
25
|
3
|
|
|
|
|
19
|
my $window = $number >> 8; |
26
|
3
|
|
|
|
|
6
|
my $bitnum = $number & 255; |
27
|
3
|
|
|
|
|
4
|
my $octet = $bitnum >> 3; |
28
|
3
|
|
|
|
|
3
|
my $bit = $bitnum & 7; |
29
|
3
|
|
|
|
|
9
|
$typearray[$window][$octet] |= 0x80 >> $bit; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
6
|
my $bitmap = ''; |
33
|
3
|
|
|
|
|
4
|
my $window = 0; |
34
|
3
|
|
|
|
|
5
|
foreach (@typearray) { |
35
|
3
|
50
|
|
|
|
9
|
if ( my $pane = $typearray[$window] ) { |
36
|
3
|
|
100
|
|
|
16
|
my @content = map $_ || 0, @$pane; |
37
|
3
|
|
|
|
|
12
|
$bitmap .= pack 'CC C*', $window, scalar(@content), @content; |
38
|
|
|
|
|
|
|
} |
39
|
3
|
|
|
|
|
6
|
$window++; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
33
|
return $bitmap; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _bm2type { |
47
|
6
|
|
|
6
|
|
1008
|
my @typelist; |
48
|
6
|
|
50
|
|
|
16
|
my $bitmap = shift || return @typelist; |
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
|
|
7
|
my $index = 0; |
51
|
6
|
|
|
|
|
9
|
my $limit = length $bitmap; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
13
|
while ( $index < $limit ) { |
54
|
6
|
|
|
|
|
19
|
my ( $block, $size ) = unpack "\@$index C2", $bitmap; |
55
|
6
|
|
|
|
|
9
|
my $typenum = $block << 8; |
56
|
6
|
|
|
|
|
16
|
foreach my $octet ( unpack "\@$index xxC$size", $bitmap ) { |
57
|
12
|
|
|
|
|
16
|
my $i = $typenum += 8; |
58
|
12
|
|
|
|
|
12
|
my @name; |
59
|
12
|
|
|
|
|
20
|
while ($octet) { |
60
|
36
|
|
|
|
|
35
|
--$i; |
61
|
36
|
100
|
|
|
|
64
|
unshift @name, typebyval($i) if $octet & 1; |
62
|
36
|
|
|
|
|
93
|
$octet = $octet >> 1; |
63
|
|
|
|
|
|
|
} |
64
|
12
|
|
|
|
|
23
|
push @typelist, @name; |
65
|
|
|
|
|
|
|
} |
66
|
6
|
|
|
|
|
14
|
$index += $size + 2; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
6
|
|
|
|
|
16
|
return @typelist; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _decode_base32 { |
73
|
1
|
|
50
|
1
|
|
1269
|
local $_ = shift || ''; |
74
|
1
|
|
|
|
|
2
|
tr [0-9a-vA-V] [\000-\037\012-\037]; |
75
|
1
|
|
|
|
|
3
|
$_ = unpack 'B*', $_; |
76
|
1
|
|
|
|
|
2
|
s/000(.....)/$1/g; |
77
|
1
|
|
|
|
|
2
|
my $l = length; |
78
|
1
|
50
|
|
|
|
3
|
$_ = substr $_, 0, $l & ~7 if $l & 7; |
79
|
1
|
|
|
|
|
13
|
pack 'B*', $_; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _encode_base32 { |
84
|
2
|
|
|
2
|
|
529
|
local $_ = unpack 'B*', shift; |
85
|
2
|
|
|
|
|
5
|
s/(.....)/000$1/g; |
86
|
2
|
|
|
|
|
3
|
my $l = length; |
87
|
2
|
|
|
|
|
5
|
my $x = substr $_, $l & ~7; |
88
|
2
|
|
|
|
|
4
|
my $n = length $x; |
89
|
2
|
50
|
|
|
|
4
|
substr( $_, $l & ~7 ) = join '', '000', $x, '0' x ( 5 - $n ) if $n; |
90
|
2
|
|
|
|
|
6
|
$_ = pack( 'B*', $_ ); |
91
|
2
|
|
|
|
|
2
|
tr [\000-\037] [0-9a-v]; |
92
|
2
|
|
|
|
|
20
|
return $_; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |