blib/lib/DBIx/Class/EncodedColumn/Digest.pm

filter: Statementstmt 100% 57 / 57 Branchbran 57.1% 8 / 14 Conditioncond 73.6% 14 / 19 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 85.8% 97 / 113 CC 16 SCAR 18.7
CC
16
Cov
88%
make_encode_sub
11.8
make_check_sub
4.0
__ANON__
3.0
CRAP 6.5
« blib/lib/DBIx/Class/EncodedColumn.pm ↑ Summary blib/lib/DBIx/Class/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 2 ▶use Encode qw( str2bytes );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.00001';
9  
10 1 my %digest_lengths =
11 (
12 'MD2' => { base64 => 22, binary => 16, hex => 32 },
13 'MD4' => { base64 => 22, binary => 16, hex => 32 },
14 'MD5' => { base64 => 22, binary => 16, hex => 32 },
15  
16 'SHA-1' => { base64 => 27, binary => 20, hex => 40 },
17 'SHA-256' => { base64 => 43, binary => 32, hex => 64 },
18 'SHA-384' => { base64 => 64, binary => 48, hex => 96 },
19 'SHA-512' => { base64 => 86, binary => 64, hex => 128 },
20  
21 'CRC-CCITT' => { base64 => 2, binary => 3, hex => 3 },
22 'CRC-16' => { base64 => 6, binary => 5, hex => 4 },
23 'CRC-32' => { base64 => 14, binary => 10, hex => 8 },
24  
25 'Adler-32' => { base64 => 6, binary => 4, hex => 8 },
26 'Whirlpool' => { base64 => 86, binary => 64, hex => 128 },
27 'Haval-256' => { base64 => 44, binary => 32, hex => 64 },
28 );
29 1 my @salt_pool = ('A' .. 'Z', 'a' .. 'z', 0 .. 9, '+','/','=');
30  
31 sub make_encode_sub {
32 7 ▶ my($class, $col, $args) = @_;
Subroutine make_encode_sub: called CC=11 SCAR=24.7
Pod documented
33 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
34 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
35 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
36  
37 7 my $encode = $args->{charset};
38  
39 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
40 unless $for =~ /^(?:hex|base64|binary)$/;
41 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
42 die("Can't use Digest algorithm ${alg}: $@");
43  
44 7 ▶ my $format_method = $for eq 'binary' ? 'digest' :
Branch: 2 branches
BranchTrueFalseTotal
$for eq 'binary' ? : 0 7 7
$for eq 'hex' ? : 3 4 7
45 ($for eq 'hex' ? 'hexdigest' : 'b64digest');
46 #thanks Haval for breaking the standard. thanks!
47 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
48  
49 my $encoder = sub {
50 28 ▶ my ($plain_text, $salt) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
51 28 ▶ $plain_text = str2bytes($encode, $plain_text, Encode::FB_PERLQQ | Encode::LEAVE_SRC) if $encode;
Branch: 1 branch
BranchTrueFalseTotal
if $encode 28 0 28
52 28 ▶ $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
1324
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
53 28 $object->reset()->add($plain_text.$salt);
54 28 my $digest = $object->$format_method;
55 #print "${plain_text}\t ${salt}:\t${digest}${salt}\n" if $salt;
56 28 return $digest.$salt;
57 7 };
58  
59 #in case i didn't prepopulate it
60 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
61 7 return $encoder;
62 }
63  
64 sub make_check_sub {
65 5 ▶ my($class, $col, $args) = @_;
Subroutine make_check_sub: called CC=4 SCAR=13.9
Pod documented
66  
67 #this is the digest length
68 5 my $len = $digest_lengths{$args->{algorithm}}{$args->{format}};
69 5 ▶ die("Unable to find digest length") unless defined $len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 5 5
70 5 ▶ my $encode = $args->{charset} || '';
Condition100%2/2
$args->{'charset'} || ''
l!l
32
MC/DC100%1/1
$args->{'charset'} || ''
$args->{'charset'}
Truth table100%2/2
A
A= $args->{'charset'}
Aresult
11
00
71  
72 #fast fast fast
73 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 \$col_v = str2bytes('${encode}', \$col_v, Encode::FB_PERLQQ | Encode::LEAVE_SRC) if '${encode}';\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 \$col_v = str2bytes('${encode}', \$col_v, Encode::FB_PERLQQ | Encode::LEAVE_SRC) if '${encode}';\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 \$col_v = str2bytes('${encode}', \$col_v, Encode::FB_PERLQQ | Encode::LEAVE_SRC) if '${encode}';\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 \$col_v = str2bytes('${encode}', \$col_v, Encode::FB_PERLQQ | Encode::LEAVE_SRC) if '${encode}';\n my \$salt = substr(\$col_v, $len);\n \$_[0]->_column_encoders->{$col}->(\$_[1], \$salt) eq \$col_v;\n } "
Aresult
11
00
74 my \$col_v = \$_[0]->get_column('${col}');
75 \$col_v = str2bytes('${encode}', \$col_v, Encode::FB_PERLQQ | Encode::LEAVE_SRC) if '${encode}';
76 my \$salt = substr(\$col_v, ${len});
77 \$_[0]->_column_encoders->{${col}}->(\$_[1], \$salt) eq \$col_v;
78 } ^ || die($@);
79 }
80  
81 1 1;
82  
83 __END__;
« blib/lib/DBIx/Class/EncodedColumn.pm ↑ Summary blib/lib/DBIx/Class/EncodedColumn/Crypt/OpenPGP.pm »