EncodedColumn/Digest.pm

filter: Statementstmt 100% 48 / 48 Branchbran 58.3% 7 / 12 Conditioncond 70.5% 12 / 17 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 84.6% 83 / 98 CC 14 SCAR 19.1
CC
14
Cov
87%
make_encode_sub
11.8
make_check_sub
3.0
__ANON__
2.0
CRAP 6.8
« EncodedColumn.pm ↑ Summary EncodedColumn/Crypt/OpenPGP.pm »
1 package DBIx::Class::EncodedColumn::Digest;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.00001';
8  
9 1 my %digest_lengths =
10 (
11 'MD2' => { base64 => 22, binary => 16, hex => 32 },
12 'MD4' => { base64 => 22, binary => 16, hex => 32 },
13 'MD5' => { base64 => 22, binary => 16, hex => 32 },
14  
15 'SHA-1' => { base64 => 27, binary => 20, hex => 40 },
16 'SHA-256' => { base64 => 43, binary => 32, hex => 64 },
17 'SHA-384' => { base64 => 64, binary => 48, hex => 96 },
18 'SHA-512' => { base64 => 86, binary => 64, hex => 128 },
19  
20 'CRC-CCITT' => { base64 => 2, binary => 3, hex => 3 },
21 'CRC-16' => { base64 => 6, binary => 5, hex => 4 },
22 'CRC-32' => { base64 => 14, binary => 10, hex => 8 },
23  
24 'Adler-32' => { base64 => 6, binary => 4, hex => 8 },
25 'Whirlpool' => { base64 => 86, binary => 64, hex => 128 },
26 'Haval-256' => { base64 => 44, binary => 32, hex => 64 },
27 );
28 1 my @salt_pool = ('A' .. 'Z', 'a' .. 'z', 0 .. 9, '+','/','=');
29  
30 sub make_encode_sub {
31 7 ▶ my($class, $col, $args) = @_;
Subroutine make_encode_sub: called CC=11 SCAR=24.7
Pod documented
32 7 ▶ my $for = $args->{format} ||= 'base64';
Condition100%2/2
$args->{"format"} ||= "base64"
l!l
34
MC/DC100%1/1
$args->{"format"} ||= "base64"
$args->{"format"}
Truth table100%2/2
A
A= $args->{"format"}
Aresult
11
00
33 7 ▶ my $alg = $args->{algorithm} ||= 'SHA-256';
Condition100%2/2
$args->{"algorithm"} ||= "SHA-256"
l!l
43
MC/DC100%1/1
$args->{"algorithm"} ||= "SHA-256"
$args->{"algorithm"}
Truth table100%2/2
A
A= $args->{"algorithm"}
Aresult
11
00
34 7 ▶ my $slen = $args->{salt_length} ||= 0;
Condition100%2/2
$args->{"salt_length"} ||= 0
l!l
16
MC/DC100%1/1
$args->{"salt_length"} ||= 0
$args->{"salt_length"}
Truth table100%2/2
A
A= $args->{"salt_length"}
Aresult
11
00
35  
36 7 ▶ die("Valid Digest formats are 'binary', 'hex' or 'base64'. You used '$for'.")
Branch: 1 branch
BranchTrueFalseTotal
unless $for =~ /^(?:hex|base64|binary)$/ 0 7 7
37 unless $for =~ /^(?:hex|base64|binary)$/;
38 7 ▶ defined(my $object = eval{ Digest->new($alg) }) ||
Branch: 1 branch
BranchTrueFalseTotal
defined(my $object = eval { do { "Digest"->new($alg) } }) or die "Can't use Digest algorithm ${alg}: $@" 0 7 7
39 die("Can't use Digest algorithm ${alg}: $@");
40  
41 7 ▶ my $format_method = $for eq 'binary' ? 'digest' :
Branch: 2 branches
BranchTrueFalseTotal
$for eq 'binary' ? : 0 7 7
$for eq 'hex' ? : 3 4 7
42 ($for eq 'hex' ? 'hexdigest' : 'b64digest');
43 #thanks Haval for breaking the standard. thanks!
44 7 ▶ $format_method = 'base64digest 'if ($alg eq 'Haval-256' && $for eq 'base64');
Branch: 1 branch
BranchTrueFalseTotal
if $alg eq "Haval-256" and $for eq "base64" 0 7 7
Condition33%1/3
$alg eq "Haval-256" and $for eq "base64"
!ll&&!rl&&r
700
MC/DC0%0/2
$alg eq "Haval-256" and $for eq "base64"
$alg eq "Haval-256" $for eq "base64"
Truth table33%1/3
A and B
A= $alg eq "Haval-256"B= $for eq "base64"
ABresult
0X0
100
111
45  
46 my $encoder = sub {
47 18 ▶ my ($plain_text, $salt) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
48 18 ▶ $salt ||= join('', map { $salt_pool[int(rand(65))] } 1 .. $slen);
Condition100%3/3
$salt ||= join("", map({$salt_pool[int rand 65];} 1 .. $slen))
l!l&&r!l&&!r
1215
MC/DC100%2/2
$salt ||= join("", map({$salt_pool[int rand 65];} 1 .. $slen))
$salt join("", map({$salt_pool[int rand 65];} 1 .. $slen))
Truth table100%3/3
A ||= B
A= $saltB= join("", map({$salt_pool[int rand 65];} 1 .. $slen))
ABresult
1X1
011
000
49 18 $object->reset()->add($plain_text.$salt);
50 18 my $digest = $object->$format_method;
51 #print "${plain_text}\t ${salt}:\t${digest}${salt}\n" if $salt;
52 18 return $digest.$salt;
53 7 };
54  
55 #in case i didn't prepopulate it
56 7 ▶ $digest_lengths{$alg}{$for} ||= length($encoder->('test1'));
Condition33%1/3
$digest_lengths{$alg}{$for} ||= length &$encoder("test1")
l!l&&r!l&&!r
700
MC/DC0%0/2
$digest_lengths{$alg}{$for} ||= length &$encoder("test1")
$digest_lengths{$alg}{$for} length &$encoder("test1")
Truth table33%1/3
A ||= B
A= $digest_lengths{$alg}{$for}B= length &$encoder("test1")
ABresult
1X1
011
000
57 7 return $encoder;
58 }
59  
60 sub make_check_sub {
61 5 ▶ my($class, $col, $args) = @_;
Subroutine make_check_sub: called CC=3 SCAR=11.0
Pod documented
62  
63 #this is the digest length
64 5 my $len = $digest_lengths{$args->{algorithm}}{$args->{format}};
65 5 ▶ die("Unable to find digest length") unless defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 5 5
66  
67 #fast fast fast
68 5 ▶ return eval qq^ sub {
Subroutine check_sha1_b64: called CC=1 SCAR=0.0
Subroutine check_sha1_hex: called CC=1 SCAR=0.0
Subroutine check_sha256_b64_salted: called CC=1 SCAR=0.0
Condition50%1/2
eval " sub {\n my \$col_v = \$_[0]->get_column('${col}');\n my \$salt = substr(\$col_v, $len);\n \$_[0]->_column_encoders->{$col}->(\$_[1], \$salt) eq \$col_v;\n } " || die($@)
l!l
50
MC/DC0%0/1
eval " sub {\n my \$col_v = \$_[0]->get_column('${col}');\n my \$salt = substr(\$col_v, $len);\n \$_[0]->_column_encoders->{$col}->(\$_[1], \$salt) eq \$col_v;\n } " || die($@)
eval " sub {\n my \$col_v = \$_[0]->get_column('${col}');\n my \$salt = substr(\$col_v, $len);\n \$_[0]->_column_encoders->{$col}->(\$_[1], \$salt) eq \$col_v;\n } "
Truth table50%1/2
A
A= eval " sub {\n my \$col_v = \$_[0]->get_column('${col}');\n my \$salt = substr(\$col_v, $len);\n \$_[0]->_column_encoders->{$col}->(\$_[1], \$salt) eq \$col_v;\n } "
Aresult
11
00
69 my \$col_v = \$_[0]->get_column('${col}');
70 my \$salt = substr(\$col_v, ${len});
71 \$_[0]->_column_encoders->{${col}}->(\$_[1], \$salt) eq \$col_v;
72 } ^ || die($@);
73 }
74  
75 1 1;
76  
77 __END__;
« EncodedColumn.pm ↑ Summary EncodedColumn/Crypt/OpenPGP.pm »