blib/lib/Zuzu/Module/DigestSHA.pm

filter: Statementstmt 100% 63 / 63 Branchbran 66.6% 4 / 6 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 21 / 21 Podpod 0.0% 0 / 1 totaltotal 91.3% 95 / 104 CC 7 SCAR 7.0
CC
7
Cov
94%
_type_name
4.8
_assert_binary
4.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Zuzu/Module/DigestMD5.pm ↑ Summary blib/script/zuzu-plackup.pl »
1 package Zuzu::Module::DigestSHA;
2  
3 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = '0.007002';
6  
7 3 ▶use Digest::SHA qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 hmac_sha1
9 hmac_sha1_base64
10 hmac_sha1_hex
11 hmac_sha224
12 hmac_sha224_base64
13 hmac_sha224_hex
14 hmac_sha256
15 hmac_sha256_base64
16 hmac_sha256_hex
17 hmac_sha384
18 hmac_sha384_base64
19 hmac_sha384_hex
20 hmac_sha512
21 hmac_sha512_base64
22 hmac_sha512_hex
23 sha1
24 sha1_base64
25 sha1_hex
26 sha224
27 sha224_base64
28 sha224_hex
29 sha256
30 sha256_base64
31 sha256_hex
32 sha384
33 sha384_base64
34 sha384_hex
35 sha512
36 sha512_base64
37 sha512_hex
38 3 );
39 3 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 3 ▶use Zuzu::Util::NativeHelpers qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
42 native_function
43 3 );
44 3 ▶use Zuzu::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 3 ▶use Zuzu::Value::BinaryString;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶sub _type_name {
Subroutine _type_name: called CC=4 SCAR=15.6
48 2 my ( $value ) = @_;
49  
50 2 ▶ return 'Null' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
51 2 ▶ return 'BinaryString'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString") 0 2 2
Condition33%1/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
52 if blessed( $value )
53 and $value->isa( 'Zuzu::Value::BinaryString' );
54 2 return 'String';
55 }
56  
57 20 ▶sub _assert_binary {
Subroutine _assert_binary: called CC=4 SCAR=13.9
58 20 my ( $value, $label, $arg_name ) = @_;
59  
60 20 ▶ $arg_name //= 'BinaryString';
Condition100%2/2
$arg_name //= "BinaryString"
l!l
515
MC/DC100%1/1
$arg_name //= "BinaryString"
$arg_name
Truth table100%2/2
A
A= $arg_name
Aresult
11
00
61  
62 20 ▶ return if blessed( $value )
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString") 18 2 20
Condition66%2/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
2018
MC/DC50%1/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
63 and $value->isa( 'Zuzu::Value::BinaryString' );
64  
65 2 my $type = _type_name( $value );
66 2 die Zuzu::Error->new_runtime(
67 message => "TypeException: $label expects $arg_name, got $type",
68 file => '<std/digest/sha>',
69 line => 0,
70 );
71 }
72  
73 6 ▶sub _bin_digest {
Subroutine _bin_digest: called CC=1 SCAR=0.0
74 6 my ( $label, $func, $value ) = @_;
75  
76 6 _assert_binary( $value, $label );
77  
78 6 my $digest = $func->( $value->bytes );
79 6 return Zuzu::Value::BinaryString->new( bytes => $digest );
80 }
81  
82 4 ▶sub _str_digest {
Subroutine _str_digest: called CC=1 SCAR=0.0
83 4 my ( $label, $func, $value ) = @_;
84  
85 4 _assert_binary( $value, $label );
86  
87 3 return $func->( $value->bytes );
88 }
89  
90 55 ▶sub _export_triplet {
Subroutine _export_triplet: called CC=1 SCAR=0.0
91 55 my ( $name, $bin_func, $hex_func, $b64_func ) = @_;
92  
93 return (
94 $name => native_function(
95 name => $name,
96 6 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
97 6 my ( $value ) = @_;
98 6 return _bin_digest( $name, $bin_func, $value );
99 },
100 ),
101 "${name}_hex" => native_function(
102 name => "${name}_hex",
103 2 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
104 2 my ( $value ) = @_;
105 2 return _str_digest( "${name}_hex", $hex_func, $value );
106 },
107 ),
108 "${name}_b64" => native_function(
109 name => "${name}_b64",
110 2 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
111 2 my ( $value ) = @_;
112 2 return _str_digest( "${name}_b64", $b64_func, $value );
113 },
114 55 ),
115 );
116 }
117  
118 3 ▶sub _bin_hmac {
Subroutine _bin_hmac: called CC=1 SCAR=0.0
119 3 my ( $label, $func, $value, $key ) = @_;
120  
121 3 _assert_binary( $value, $label );
122 3 _assert_binary( $key, $label, 'BinaryString key' );
123  
124 2 my $digest = $func->( $value->bytes, $key->bytes );
125 2 return Zuzu::Value::BinaryString->new( bytes => $digest );
126 }
127  
128 2 ▶sub _str_hmac {
Subroutine _str_hmac: called CC=1 SCAR=0.0
129 2 my ( $label, $func, $value, $key ) = @_;
130  
131 2 _assert_binary( $value, $label );
132 2 _assert_binary( $key, $label, 'BinaryString key' );
133  
134 2 return $func->( $value->bytes, $key->bytes );
135 }
136  
137 55 ▶sub _export_hmac_triplet {
Subroutine _export_hmac_triplet: called CC=1 SCAR=0.0
138 55 my ( $name, $bin_func, $hex_func, $b64_func ) = @_;
139  
140 return (
141 $name => native_function(
142 name => $name,
143 3 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
144 3 my ( $value, $key ) = @_;
145 3 return _bin_hmac( $name, $bin_func, $value, $key );
146 },
147 ),
148 "${name}_hex" => native_function(
149 name => "${name}_hex",
150 1 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
151 1 my ( $value, $key ) = @_;
152 1 return _str_hmac(
153 "${name}_hex",
154 $hex_func,
155 $value,
156 $key,
157 );
158 },
159 ),
160 "${name}_b64" => native_function(
161 name => "${name}_b64",
162 1 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
163 1 my ( $value, $key ) = @_;
164 1 return _str_hmac(
165 "${name}_b64",
166 $b64_func,
167 $value,
168 $key,
169 );
170 },
171 55 ),
172 );
173 }
174  
175 11 ▶sub IMPORT {
Subroutine IMPORT: called CC=1 SCAR=0.0
Pod undocumented
176 11 my ( $class, $runtime ) = @_;
177  
178 return {
179 11 _export_triplet( 'sha1', \&sha1, \&sha1_hex, \&sha1_base64 ),
180 _export_triplet( 'sha224', \&sha224, \&sha224_hex, \&sha224_base64 ),
181 _export_triplet( 'sha256', \&sha256, \&sha256_hex, \&sha256_base64 ),
182 _export_triplet( 'sha384', \&sha384, \&sha384_hex, \&sha384_base64 ),
183 _export_triplet( 'sha512', \&sha512, \&sha512_hex, \&sha512_base64 ),
184 _export_hmac_triplet(
185 'hmac_sha1',
186 \&hmac_sha1,
187 \&hmac_sha1_hex,
188 \&hmac_sha1_base64,
189 ),
190 _export_hmac_triplet(
191 'hmac_sha224',
192 \&hmac_sha224,
193 \&hmac_sha224_hex,
194 \&hmac_sha224_base64,
195 ),
196 _export_hmac_triplet(
197 'hmac_sha256',
198 \&hmac_sha256,
199 \&hmac_sha256_hex,
200 \&hmac_sha256_base64,
201 ),
202 _export_hmac_triplet(
203 'hmac_sha384',
204 \&hmac_sha384,
205 \&hmac_sha384_hex,
206 \&hmac_sha384_base64,
207 ),
208 _export_hmac_triplet(
209 'hmac_sha512',
210 \&hmac_sha512,
211 \&hmac_sha512_hex,
212 \&hmac_sha512_base64,
213 ),
214 };
215 }
216  
217 3 1;
218  
219 =pod
220  
221 =head1 NAME
222  
223 Zuzu::Module::DigestSHA - std/digest/sha bindings.
224  
225 =head1 DESCRIPTION
226  
227 Implements C<std/digest/sha> and exports C<sha1>,
228 C<sha1_hex>, C<sha1_b64>, C<sha224>, C<sha224_hex>,
229 C<sha224_b64>, C<sha256>, C<sha256_hex>, C<sha256_b64>,
230 C<sha384>, C<sha384_hex>, C<sha384_b64>, C<sha512>,
231 C<sha512_hex>, C<sha512_b64>, C<hmac_sha1>,
232 C<hmac_sha1_hex>, C<hmac_sha1_b64>, C<hmac_sha224>,
233 C<hmac_sha224_hex>, C<hmac_sha224_b64>, C<hmac_sha256>,
234 C<hmac_sha256_hex>, C<hmac_sha256_b64>, C<hmac_sha384>,
235 C<hmac_sha384_hex>, C<hmac_sha384_b64>, C<hmac_sha512>,
236 C<hmac_sha512_hex>, and C<hmac_sha512_b64>.
237  
238 =head1 COPYRIGHT AND LICENCE
239  
240 B<< Zuzu::Module::DigestSHA >> is copyright Toby Inkster.
241  
242 It is free software; you may redistribute it and/or modify it under
243 the terms of either the Artistic License 1.0 or the GNU General Public
244 License version 2.
245  
246 =cut
« blib/lib/Zuzu/Module/DigestMD5.pm ↑ Summary blib/script/zuzu-plackup.pl »