Blossom/_Bech32.pm

filter: Statementstmt 100% 54 / 54 Branchbran 69.2% 18 / 26 Conditioncond 50.0% 9 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 76.7% 89 / 116 CC 23 SCAR 21.7
CC
23
Cov
83%
_parts
12.2
convert_5_to_8
10.5
_polymod
4.0
CRAP 8.7
« Blossom/BlobDescriptor.pm ↑ Summary Blossom/Response.pm »
1 package Net::Blossom::_Bech32;
2  
3 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 my $CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
6 1 my %VALUE = map { substr($CHARSET, $_, 1) => $_ } 0 .. length($CHARSET) - 1;
7 1 my @GENERATOR = (0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3);
8  
9 36 ▶sub decode {
Subroutine decode: called CC=3 SCAR=11.0
Pod undocumented
10 36 my ($value, $checksum) = @_;
11 36 my ($hrp, $data) = _parts($value);
12 36 ▶ return unless defined $hrp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hrp 1 35 36
13  
14 35 my @values = (_hrp_expand($hrp), map { $VALUE{$_} } split //, $data);
15 35 ▶ return unless _polymod(\@values) == $checksum;
Branch: 1 branch
BranchTrueFalseTotal
unless _polymod(\@values) == $checksum 2 33 35
16  
17 33 my @payload = map { $VALUE{$_} } split //, substr($data, 0, -6);
18 33 return ($hrp, \@payload);
19 }
20  
21 33 ▶sub convert_5_to_8 {
Subroutine convert_5_to_8: called CC=9 SCAR=23.5
Pod undocumented
22 33 my ($values) = @_;
23 33 my ($accumulator, $bits) = (0, 0);
24 33 my $bytes = '';
25  
26 33 for my $value (@$values) {
27 2683 ▶ return unless defined $value && $value >= 0 && $value < 32;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value >= 0 and $value < 32 0 2683 2683
Condition33%2/6
defined $value and $value >= 0 and $value < 32
!ll&&!rl&&r
002683
defined $value and $value >= 0
!ll&&!rl&&r
002683
MC/DC0%0/3
defined $value and $value >= 0 and $value < 32
defined $value $value >= 0 $value < 32
Truth table25%1/4
A and B and C
A= defined $valueB= $value >= 0C= $value < 32
ABCresult
0XX0
10X0
1100
1111
28 2683 $accumulator = (($accumulator << 5) | $value) & 0xfff;
29 2683 $bits += 5;
30  
31 2683 ▶ while ($bits >= 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits >= 8) 1668 2683 4351
32 1668 $bits -= 8;
33 1668 $bytes .= chr(($accumulator >> $bits) & 0xff);
34 }
35 }
36  
37 33 ▶ return if $bits >= 5;
Branch: 1 branch
BranchTrueFalseTotal
if $bits >= 5 0 33 33
38 33 ▶ return if $bits && (($accumulator << (8 - $bits)) & 0xff);
Branch: 1 branch
BranchTrueFalseTotal
if $bits and $accumulator << 8 - $bits & 255 0 33 33
Condition66%2/3
$bits and $accumulator << 8 - $bits & 255
!ll&&!rl&&r
5280
MC/DC0%0/2
$bits and $accumulator << 8 - $bits & 255
$bits $accumulator << 8 - $bits & 255
Truth table66%2/3
A and B
A= $bitsB= $accumulator << 8 - $bits & 255
ABresult
0X0
100
111
39 33 return $bytes;
40 }
41  
42 36 ▶sub _parts {
Subroutine _parts: called CC=10 SCAR=25.0
43 36 my ($value) = @_;
44 36 ▶ return unless defined $value && !ref($value) && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and length $value 0 36 36
Condition33%2/6
defined $value and not ref $value and length $value
!ll&&!rl&&r
0036
defined $value and not ref $value
!ll&&!rl&&r
0036
MC/DC0%0/3
defined $value and not ref $value and length $value
defined $value not ref $value length $value
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value
ABCresult
0XX0
10X0
1100
1111
45 36 ▶ return if $value =~ /[^\x21-\x7e]/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[^\x21-\x7e]/ 0 36 36
46 36 ▶ return if lc($value) ne $value && uc($value) ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if lc $value ne $value and uc $value ne $value 1 35 36
Condition100%3/3
lc $value ne $value and uc $value ne $value
!ll&&!rl&&r
3411
MC/DC100%2/2
lc $value ne $value and uc $value ne $value
lc $value ne $value uc $value ne $value
Truth table100%3/3
A and B
A= lc $value ne $valueB= uc $value ne $value
ABresult
0X0
100
111
47  
48 35 my $normalized = lc $value;
49 35 my $separator = rindex($normalized, '1');
50 35 ▶ return if $separator < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $separator < 1 0 35 35
51  
52 35 my $data = substr($normalized, $separator + 1);
53 35 ▶ return if length($data) < 6;
Branch: 1 branch
BranchTrueFalseTotal
if length $data < 6 0 35 35
54 35 ▶ return unless $data =~ /\A[$CHARSET]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /\A[$CHARSET]+\z/ 0 35 35
55  
56 35 return (substr($normalized, 0, $separator), $data);
57 }
58  
59 35 ▶sub _hrp_expand {
Subroutine _hrp_expand: called CC=1 SCAR=0.0
60 35 my ($hrp) = @_;
61 35 my @chars = split //, $hrp;
62 35 return ((map { ord($_) >> 5 } @chars), 0, (map { ord($_) & 31 } @chars));
63 }
64  
65 35 ▶sub _polymod {
Subroutine _polymod: called CC=4 SCAR=13.9
66 35 my ($values) = @_;
67 35 my $checksum = 1;
68  
69 35 for my $value (@$values) {
70 3414 my $top = $checksum >> 25;
71 3414 $checksum = (($checksum & 0x1ffffff) << 5) ^ $value;
72 3414 for my $i (0 .. 4) {
73 17070 ▶ $checksum ^= $GENERATOR[$i] if (($top >> $i) & 1);
Branch: 1 branch
BranchTrueFalseTotal
if $top >> $i & 1 7781 9289 17070
74 }
75 }
76  
77 35 return $checksum;
78 }
79  
80 1 1;
« Blossom/BlobDescriptor.pm ↑ Summary Blossom/Response.pm »