Crypt/Util.pm

filter: Statementstmt 64.8% 314 / 484 Branchbran 39.0% 50 / 128 Conditioncond 45.0% 18 / 40 MC/DCmcdc 16.6% 4 / 24 Subroutinesub 67.3% 68 / 101 Podpod 74.1% 43 / 58 totaltotal 59.5% 497 / 835 CC 81 SCAR 16.3
CC
81
Cov
59%
_authenticated_mode
26.6
__ANON__
16.7
_flag_hash_to_int
12.0
CRAP 5.1
↑ Summary Digest/MultiHash.pm »
1 6 ▶#!/usr/bin/perl
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=3 SCAR=12.7
Branch: 1 branch
BranchTrueFalseTotal
open F or die "Cannot open ${F}: $!" 6 0 6
2 6 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (unpack("%32N*", $F = readline *F) != 1204322646) 0 6 6
3 0 ▶package Crypt::Util;
Subroutine BEGIN: called CC=1 SCAR=0.2
4 0 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine __ANON__: not called CC=2 SCAR=12.2
Branch: 1 branch
BranchTrueFalseTotal
&filter_read and do { '???' } 0 0 0
5  
6 6 our $VERSION = "0.11";
7  
8 6 ▶use Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Digest::MoreFallbacks;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use Sub::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Data::OptList;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use namespace::clean -except => [qw(meta)];
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 our %DEFAULT_ACCESSORS = (
19 mode => { isa => "Str" },
20 authenticated_mode => { isa => "Str" },
21 encode => { isa => "Bool" },
22 encoding => { isa => "Str" },
23 printable_encoding => { isa => "Str" },
24 alphanumerical_encoding => { isa => "Str" },
25 uri_encoding => { isa => "Str" },
26 digest => { isa => "Str" },
27 cipher => { isa => "Str" },
28 mac => { isa => "Str" },
29 key => { isa => "Str" },
30 uri_encoding => { isa => "Str" },
31 printable_encoding => { isa => "Str" },
32 use_literal_key => { isa => "Bool" },
33 tamper_proof_unencrypted => { isa => "Bool" },
34 nonce => { isa => "Str", default => "" },
35 );
36  
37 6 our @DEFAULT_ACCESSORS = keys %DEFAULT_ACCESSORS;
38  
39 my %export_groups = (
40 'crypt' => [qw/
41 encrypt_string decrypt_string
42 authenticated_encrypt_string
43 tamper_proof thaw_tamper_proof
44 cipher_object
45 /],
46 digest => [qw/
47 digest_string verify_hash verify_digest
48 digest_object
49 mac_digest_string
50 verify_mac
51 /],
52 encoding => [qw/
53 encode_string decode_string
54 encode_string_hex decode_string_hex
55 encode_string_base64 decode_string_base64 encode_string_base64_wrapped
56 encode_string_base32 decode_string_base32
57 encode_string_uri_base64 decode_string_uri_base64
58 encode_string_uri decode_string_uri
59 encode_string_alphanumerical decode_string_alphanumerical
60 encode_string_printable decode_string_printable
61 encode_string_uri_escape decode_string_uri_escape
62 /],
63 6 params => [ "exported_instance", "disable_fallback", map { "default_$_" } @DEFAULT_ACCESSORS ],
64 );
65  
66 6 my %exports = map { $_ => \&__curry_instance } map { @$_ } values %export_groups;
67  
68 Sub::Exporter->import( -setup => {
69 exports => \%exports,
70 groups => \%export_groups,
71 collectors => {
72 1 ▶ defaults => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
73 },
74 6 });
75  
76 6 our @KNOWN_AUTHENTICATING_MODES = qw(EAX OCB GCM CWC CCM); # IACBC & IAPM will probably never be implemented
77  
78 6 our %KNOWN_AUTHENTICATING_MODES = map { $_ => 1 } @KNOWN_AUTHENTICATING_MODES;
79  
80 6 our %FALLBACK_LISTS = (
81 mode => [qw/CFB CBC Ctr OFB/],
82 stream_mode => [qw/CFB Ctr OFB/],
83 block_mode => [qw/CBC/],
84 authenticated_mode => [qw/EAX GCM CCM/], # OCB/], OCB is patented
85 cipher => [qw/Rijndael Serpent Twofish RC6 Blowfish RC5/],
86 #authenticated_cipher => [qw/Phelix SOBER-128 Helix/], # not yet ready
87 digest => [qw/SHA-1 SHA-256 RIPEMD160 Whirlpool MD5 Haval256/],
88 mac => [qw/HMAC CMAC/],
89 encoding => [qw/hex/],
90 printable_encoding => [qw/base64 hex/],
91 alphanumerical_encoding => [qw/base32 hex/],
92 uri_encoding => [qw/uri_base64 base32 hex/],
93 );
94  
95 6 foreach my $fallback ( keys %FALLBACK_LISTS ) {
96 66 my @list = @{ $FALLBACK_LISTS{$fallback} };
97  
98 66 my $list_method = "fallback_${fallback}_list";
99  
100 18 ▶ my $list_method_sub = sub { # derefed list accessors
Subroutine __ANON__: called CC=6 SCAR=28.1
101 18 my ( $self, @args ) = @_;
102 18 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 18 18
103 0 ▶ @args = @{ $args[0] } if @args == 1 and (ref($args[0])||'') eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 and (ref $args[0] || "") eq "ARRAY" 0 0 0
Condition0%0/5
@args == 1 and (ref $args[0] || "") eq "ARRAY"
!ll&&!rl&&r
000
ref $args[0] || ''
l!l
00
MC/DC0%0/2
@args == 1 and (ref $args[0] || "") eq "ARRAY"
@args == 1 ref $args[0]
Truth table0%0/3
A and B
A= @args == 1B= ref $args[0]
ABresult
0X0
100
111
104 0 $self->{$list_method} = \@args;
105 }
106 18 ▶ @{ $self->{$list_method} || \@list };
Condition50%1/2
$self->{$list_method} || \@list
l!l
018
MC/DC0%0/1
$self->{$list_method} || \@list
$self->{$list_method}
Truth table50%1/2
A
A= $self->{$list_method}
Aresult
11
00
107 66 };
108  
109 66 ▶ my $type = ( $fallback =~ /(encoding|mode)/ )[0] || $fallback;
Condition66%2/3
($fallback =~ /(encoding|mode)/)[0] || $fallback
l!l&&r!l&&!r
48180
MC/DC0%0/2
($fallback =~ /(encoding|mode)/)[0] || $fallback
($fallback =~ /(encoding|mode)/)[0] $fallback
Truth table66%2/3
A || B
A= ($fallback =~ /(encoding|mode)/)[0]B= $fallback
ABresult
1X1
011
000
110 66 my $try = "_try_${type}_fallback";
111  
112 18 ▶ my $fallback_sub = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
113 18 my $self = shift;
114  
115 18 ▶ $self->_find_fallback(
Branch: 1 branch
BranchTrueFalseTotal
$self->_find_fallback($fallback, $try, $self->$list_method) or croak("Couldn't load any $fallback") 16 0 16
116 $fallback,
117 $try,
118 $self->$list_method,
119 ) || croak "Couldn't load any $fallback";
120 66 };
121  
122 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
123 66 *{ "fallback_$fallback" } = $fallback_sub;
124 66 *{ $list_method } = $list_method_sub;
125 }
126  
127 6 foreach my $attr ( @DEFAULT_ACCESSORS ) {
128 has "default_$attr" => (
129 is => "rw",
130 predicate => "has_default_$attr",
131 clearer => "clear_default_$attr",
132 ( __PACKAGE__->can("fallback_$attr") ? (
133 lazy_build => 1,
134 builder => "fallback_$attr",
135 ) : () ),
136 84 ▶ %{ $DEFAULT_ACCESSORS{$attr} },
Branch: 1 branch
BranchTrueFalseTotal
__PACKAGE__->can("fallback_$attr") ? : 54 30 84
137 );
138 }
139  
140 6 has disable_fallback => (
141 isa => "Bool",
142 is => "rw",
143 );
144  
145 6 ▶__PACKAGE__->meta->make_immutable if __PACKAGE__->meta->can("make_immutable");
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->meta->can("make_immutable") 6 0 6
146  
147 {
148 6 my %fallback_caches;
149  
150 18 ▶ sub _find_fallback {
Subroutine _find_fallback: called CC=7 SCAR=20.9
151 18 my ( $self, $key, $test, @list ) = @_;
152  
153 18 ▶ my $cache = $fallback_caches{$key} ||= {};
Condition100%2/2
$fallback_caches{$key} ||= {}
l!l
414
MC/DC100%1/1
$fallback_caches{$key} ||= {}
$fallback_caches{$key}
Truth table100%2/2
A
A= $fallback_caches{$key}
Aresult
11
00
154  
155 18 ▶ @list = $list[0] if @list and $self->disable_fallback;
Branch: 1 branch
BranchTrueFalseTotal
if @list and $self->disable_fallback 0 18 18
Condition33%1/3
@list and $self->disable_fallback
!ll&&!rl&&r
0180
MC/DC0%0/2
@list and $self->disable_fallback
@list $self->disable_fallback
Truth table33%1/3
A and B
A= @listB= $self->disable_fallback
ABresult
0X0
100
111
156  
157 18 foreach my $elem ( @list ) {
158 18 ▶ $cache->{$elem} = $self->$test( $elem ) unless exists $cache->{$elem};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $cache->{$elem} 14 4 18
159 16 ▶ return $elem if $cache->{$elem};
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$elem} 16 0 16
160 }
161  
162  
163 0 return;
164 }
165 }
166  
167 6 ▶sub _try_cipher_fallback {
Subroutine _try_cipher_fallback: called CC=1 SCAR=0.0
168 3 my ( $self, $name ) = @_;
169 3 $self->_try_loading_module("Crypt::$name");
170 }
171  
172 3 ▶sub _try_digest_fallback {
Subroutine _try_digest_fallback: called CC=3 SCAR=12.7
173 3 my ( $self, $name ) = @_;
174  
175 3 my $e;
176  
177 {
178 3 local $@;
179 3 eval { $self->digest_object( digest => $name ) };
180 3 $e = $@;
181 };
182  
183 3 ▶ return 1 if !$e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 3 0 3
184 0 ( my $file = $name ) =~ s{::}{/}g;
185 0 ▶ die $e if $e !~ m{^Can't locate Digest/\Q${file}.pm\E in \@INC};
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ m[^Can't locate Digest/\Q$file.pm\E in \@INC] 0 0 0
186 0 return;
187 }
188  
189 2 ▶sub _try_mode_fallback {
Subroutine _try_mode_fallback: called CC=1 SCAR=0.0
190 2 my ( $self, $mode ) = @_;
191 2 $self->_try_loading_module("Crypt::$mode");
192 }
193  
194 2 ▶sub _try_mac_fallback {
Subroutine _try_mac_fallback: called CC=1 SCAR=0.0
195 2 my ( $self, $mac ) = @_;
196 2 $self->_try_loading_module("Digest::$mac");
197 }
198  
199 11 ▶sub _try_loading_module {
Subroutine _try_loading_module: called CC=3 SCAR=11.1
200 11 my ( $self, $name ) = @_;
201  
202 11 (my $file = "${name}.pm") =~ s{::}{/}g;
203  
204 11 my ( $r, $e );
205 {
206 11 local $@;
207 11 $r = eval { require $file }; # yes it's portable
208 11 $e = $@;
209 };
210  
211 11 ▶ return $r if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 9 2 11
212 2 ▶ die $e if $e !~ /^Can't locate \Q$file\E in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /^Can't locate \Q$file\E in \@INC/ 2 0 2
213 0 return $r;
214 }
215  
216 {
217 6 my %encoding_module = (
218 base64 => "MIME::Base64",
219 uri_base64 => "MIME::Base64::URLSafe",
220 base32 => "MIME::Base32",
221 uri_escape => "URI::Escape",
222 );
223  
224 9 ▶ sub _try_encoding_fallback {
Subroutine _try_encoding_fallback: called CC=4 SCAR=14.6
225 9 my ( $self, $encoding ) = @_;
226  
227 9 ▶ return 1 if $encoding eq "hex";
Branch: 1 branch
BranchTrueFalseTotal
if $encoding eq "hex" 2 7 9
228  
229 7 my $module = $encoding_module{$encoding};
230 7 $module =~ s{::}{/}g;
231 7 $module .= ".pm";
232  
233 7 my $e = do {
234 7 local $@;
235 7 eval { require $module }; # yes it's portable
236 7 $@;
237 };
238  
239 7 ▶ return 1 if !$e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 7 0 7
240 0 ▶ die $e if $e !~ /^Can't locate \Q$module\E in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /^Can't locate \Q$module\E in \@INC/ 0 0 0
241 0 return;
242 }
243 }
244  
245 6 ▶sub _args (\@;$) {
Subroutine _args: called CC=4 SCAR=13.9
246 262 my ( $args, $odd ) = @_;
247  
248 262 my ( $self, @args ) = @$args;
249  
250 262 my %params;
251 262 ▶ if ( @args % 2 == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args % 2 == 1) { } 4 258 262
252 4 ▶ croak "The parameters must be an even sized list of key value pairs" unless defined $odd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $odd 0 4 4
253 4 ( my $odd_value, %params ) = @args;
254 4 ▶ croak "Can't provide the positional param in the named list as well" if exists $params{$odd};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{$odd} 0 4 4
255 4 $params{$odd} = $odd_value;
256 } else {
257 258 %params = @args;
258 }
259  
260 262 return ( $self, %params );
261 }
262  
263 228 ▶sub _process_params {
Subroutine _process_params: called CC=3 SCAR=11.0
264 228 my ( $self, $params, @required ) = @_;
265  
266 228 foreach my $param ( @required ) {
267 232 ▶ next if exists $params->{$param};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params->{$param} 208 24 232
268  
269 24 $params->{$param} = $self->_process_param( $param );
270 }
271 }
272  
273 74 ▶sub _process_param {
Subroutine _process_param: called CC=2 SCAR=6.9
274 74 my ( $self, $param ) = @_;
275  
276 74 my $default = "default_$param";
277  
278 74 ▶ if ( $self->can($default) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($default)) 72 2 74
279 72 return $self->$default;
280 }
281  
282 2 croak "No default value for required parameter '$param'";
283 }
284  
285 8 ▶sub cipher_object {
Subroutine cipher_object: called CC=2 SCAR=7.0
Pod documented
286 8 my ( $self, %params ) = _args @_;
287  
288 8 $self->_process_params( \%params, qw/mode/);
289  
290 8 my $method = "cipher_object_" . lc(my $mode = delete $params{mode});
291  
292 8 ▶ croak "mode $mode is unsupported" unless $self->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 0 8 8
293  
294 8 $self->$method( %params );
295 }
296  
297 0 ▶sub cipher_object_eax {
Subroutine cipher_object_eax: not called CC=1 SCAR=6.9
Pod documented
298 0 my ( $self, %params ) = _args @_;
299  
300 0 $self->_process_params( \%params, qw/cipher nonce/ );
301  
302 0 require Crypt::EAX;
303  
304 Crypt::EAX->new(
305 %params,
306 cipher => "Crypt::$params{cipher}", # FIXME take a ref, but Crypt::CFB will barf
307 key => $self->process_key(%params),
308 nonce => $params{nonce},
309 0 );
310 }
311  
312 3 ▶sub cipher_object_cbc {
Subroutine cipher_object_cbc: called CC=1 SCAR=0.0
Pod undocumented
313 3 my ( $self, %params ) = _args @_;
314  
315 3 $self->_process_params( \%params, qw/cipher/ );
316  
317 3 require Crypt::CBC;
318  
319 Crypt::CBC->new(
320 -cipher => $params{cipher},
321 3 -key => $self->process_key(%params),
322 );
323 }
324  
325 1 ▶sub cipher_object_ofb {
Subroutine cipher_object_ofb: called CC=1 SCAR=2.2
Pod undocumented
326 1 my ( $self, %params ) = _args @_;
327  
328 1 $self->_process_params( \%params, qw/cipher/ );
329  
330 1 require Crypt::OFB;
331 0 my $c = Crypt::OFB->new;
332  
333 0 $c->padding( Crypt::ECB::PADDING_AUTO() );
334  
335 0 $c->key( $self->process_key(%params) );
336  
337 0 $c->cipher( $params{cipher} );
338  
339 0 return $c;
340 }
341  
342 1 ▶sub cipher_object_cfb {
Subroutine cipher_object_cfb: called CC=1 SCAR=0.4
Pod undocumented
343 1 my ( $self, @args ) = _args @_;
344 1 require Crypt::CFB;
345 0 $self->_cipher_object_baurem( "Crypt::CFB", @args );
346 }
347  
348 1 ▶sub cipher_object_ctr {
Subroutine cipher_object_ctr: called CC=1 SCAR=0.4
Pod undocumented
349 1 my ( $self, @args ) = _args @_;
350 1 require Crypt::Ctr;
351 0 $self->_cipher_object_baurem( "Crypt::Ctr", @args );
352 }
353  
354 0 ▶sub _cipher_object_baurem {
Subroutine _cipher_object_baurem: not called CC=2 SCAR=17.9
355 0 my ( $self, $class, %params ) = @_;
356  
357 0 my $prefix = "Crypt";
358 0 ▶ ( $prefix, $params{cipher} ) = ( Digest => delete $params{digest} ) if exists $params{encryption_digest};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"encryption_digest"} 0 0 0
359  
360 0 $self->_process_params( \%params, qw/cipher/ );
361  
362 0 $class->new( $self->process_key(%params), join("::", $prefix, $params{cipher}) );
363 }
364  
365 use tt;
366 1 ▶[% FOR mode IN ["stream", "block", "authenticated"] %]
Subroutine cipher_object_stream: called CC=1 SCAR=0.4
Pod undocumented
367 1 sub cipher_object_[% mode %] {
368 1 my ( $self, @args ) = _args @_;
369 0 my $mode = $self->_process_param("[% mode %]_mode");
370 $self->cipher_object( @args, mode => $mode );
371 }
372 1 ▶[% END %]
Subroutine cipher_object_block: called CC=1 SCAR=0.4
Pod undocumented
373 1 no tt;
374 1  
375 0 sub process_nonce {
376 my ( $self, %params ) = _args @_, 'nonce';
377  
378 0 ▶ my $nonce = $self->_process_params( \%params, 'nonce' );
Subroutine cipher_object_authenticated: not called CC=1 SCAR=6.9
Pod undocumented
379 0  
380 0 if ( length($nonce) ) {
381 0 return $nonce;
382 } else {
383 require Data::GUID;
384 Data::GUID->new->as_binary;
385 0 ▶ }
Subroutine process_nonce: not called CC=2 SCAR=17.9
Pod documented
386 0 }
387  
388 0 sub process_key {
389 my ( $self, %params ) = _args @_, "key";
390 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (length $nonce) { } 0 0 0
391 0 if ( $params{literal_key} || $self->default_use_literal_key ) {
392 $self->_process_params( \%params, qw/key/ );
393 0 return $params{key};
394 0 } else {
395 my $size = $params{key_size};
396  
397 unless ( $size ) {
398 12 ▶ $self->_process_params( \%params, qw/key cipher/ );
Subroutine process_key: called CC=8 SCAR=22.1
Pod documented
399 12 my $cipher = $params{cipher};
400  
401 12 ▶ my $class = "Crypt::$cipher";
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'literal_key'} or $self->default_use_literal_key) { } 8 4 12
Condition100%3/3
$params{"literal_key"} or $self->default_use_literal_key
l!l&&r!l&&!r
714
MC/DC100%2/2
$params{"literal_key"} or $self->default_use_literal_key
$params{"literal_key"} $self->default_use_literal_key
Truth table100%3/3
A or B
A= $params{"literal_key"}B= $self->default_use_literal_key
ABresult
1X1
011
000
402 8  
403 8 $self->_try_loading_module($class);
404  
405 4 if ( my $size_method = $class->can("keysize") || $class->can("blocksize") ) {
406 $size = $class->$size_method;
407 4 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
unless ($size) 4 0 4
408 4  
409 4 $size ||= $cipher eq "Blowfish" ? 56 : 32;
410 }
411 4  
412 return $self->digest_string(
413 4 string => $params{key},
414 digest => "MultiHash",
415 4 ▶ encode => 0,
Branch: 1 branch
BranchTrueFalseTotal
if (my $size_method = $class->can("keysize") || $class->can("blocksize")) 4 0 4
Condition33%1/3
$class->can('keysize') || $class->can('blocksize')
l!l&&r!l&&!r
400
MC/DC0%0/2
$class->can('keysize') || $class->can('blocksize')
$class->can('keysize') $class->can('blocksize')
Truth table33%1/3
A || B
A= $class->can('keysize')B= $class->can('blocksize')
ABresult
1X1
011
000
416 4 digest_args => [{
417 width => $size,
418 hashes => ["SHA-512"], # no need to be overkill, we just need the variable width
419 4 ▶ }],
Branch: 1 branch
BranchTrueFalseTotal
$cipher eq 'Blowfish' ? : 0 0 0
Condition33%1/3
$size ||= $cipher eq "Blowfish" ? 56 : 32
l!l&&r!l&&!r
400
MC/DC0%0/2
$size ||= $cipher eq "Blowfish" ? 56 : 32
$size $cipher eq "Blowfish" ? 56 : 32
Truth table33%1/3
A ||= B
A= $sizeB= $cipher eq "Blowfish" ? 56 : 32
ABresult
1X1
011
000
420 );
421 }
422 }
423  
424 4 sub digest_object {
425 my ( $self, %params ) = _args @_;
426  
427 $self->_process_params( \%params, qw/
428 digest
429 /);
430  
431 Digest->new( $params{digest}, @{ $params{digest_args} || [] } );
432 }
433  
434 21 ▶{
Subroutine digest_object: called CC=2 SCAR=6.9
Pod documented
435 21 # this is a hack that gives to Digest::HMAC something that responds to ->new
436  
437 21 package
438 Crypt::Util::HMACDigestFactory;
439  
440 sub new {
441 21 ▶ my $self = shift;
Condition100%2/2
$params{'digest_args'} || []
l!l
417
MC/DC100%1/1
$params{'digest_args'} || []
$params{'digest_args'}
Truth table100%2/2
A
A= $params{'digest_args'}
Aresult
11
00
442 $$self->clone;
443 }
444  
445 sub new_factory {
446 my ( $self, $thing ) = @_;
447 return bless \$thing, $self;
448 }
449 }
450 6 ▶ 
Subroutine new: called CC=1 SCAR=0.0
451 6 sub mac_object {
452 6 my ( $self, %params ) = _args @_;
453  
454 $self->_process_params( \%params, qw/
455 6 ▶ mac
Subroutine new_factory: called CC=1 SCAR=0.0
456 6 /);
457 6  
458 my $mac_type = delete $params{mac};
459  
460 my $method = lc( "mac_object_$mac_type" );
461 6 ▶ 
Subroutine mac_object: called CC=1 SCAR=0.0
Pod documented
462 6 $self->$method( %params );
463 }
464 6  
465 sub mac_object_hmac {
466 my ( $self, @args ) = _args @_;
467  
468 6 my $digest = $self->digest_object(@args);
469  
470 6 my $digest_factory = Crypt::Util::HMACDigestFactory->new_factory( $digest );
471  
472 6 my $key = $self->process_key(
473 literal_key => 1, # Digest::HMAC does it's own key processing, but we let the user force our own
474 key_size => 64, # if the user did force our own, the default key_size is Digest::HMAC's default block size
475 6 ▶ @args,
Subroutine mac_object_hmac: called CC=1 SCAR=0.0
Pod undocumented
476 6 );
477  
478 6 require Digest::HMAC;
479 Digest::HMAC->new(
480 6 $key,
481 $digest_factory,
482 6 # FIXME hmac_block_size param?
483 );
484 }
485  
486 sub mac_object_cmac {
487 my ( $self, %params ) = _args @_;
488 6  
489 6 my ( $key, $cipher );
490  
491 if ( ref $params{cipher} ) {
492 $cipher = $params{cipher};
493 } else {
494 $self->_process_params( \%params, qw(cipher) );
495 $cipher = "Crypt::" . $params{cipher};
496 0 ▶ $key = $self->process_key(%params);
Subroutine mac_object_cmac: not called CC=2 SCAR=17.9
Pod undocumented
497 0 }
498  
499 0 require Digest::CMAC;
500 Digest::CMAC->new( $key, $cipher );
501 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params{'cipher'}) { } 0 0 0
502 0  
503 use tt;
504 0 [% FOR f IN ["en", "de"] %]
505 0 sub [% f %]crypt_string {
506 0 my ( $self, %params ) = _args @_, "string";
507  
508 my $string = delete $params{string};
509 0 croak "You must provide the 'string' parameter" unless defined $string;
510 0  
511 my $c = $self->cipher_object( %params );
512  
513 [% IF f == "en" %]
514 1 ▶ $self->maybe_encode( $c->encrypt($string), \%params );
Subroutine encrypt_string: called CC=2 SCAR=7.0
Pod documented
515 1 [% ELSE %]
516 $c->decrypt( $self->maybe_decode($string, \%params ) );
517 1 [% END %]
518 1 ▶}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 1 1
519  
520 1 sub maybe_[% f %]code {
521 my ( $self, $string, $params ) = @_;
522  
523 1 my $should_encode = exists $params->{[% f %]code}
524 ? $params->{[% f %]code}
525 : exists $params->{encoding} || $self->default_encode;
526  
527 18 ▶ if ( $should_encode ) {
Subroutine maybe_encode: called CC=4 SCAR=15.2
Pod documented
528 18 return $self->[% f %]code_string(
529 %$params,
530 string => $string,
531 );
532 18 ▶ } else {
Branch: 1 branch
BranchTrueFalseTotal
exists $params->{'encode'} ? : 4 14 18
Condition33%1/3
exists $params->{"encoding"} or $self->default_encode
l!l&&r!l&&!r
0014
MC/DC0%0/2
exists $params->{"encoding"} or $self->default_encode
exists $params->{"encoding"} $self->default_encode
Truth table33%1/3
A or B
A= exists $params->{"encoding"}B= $self->default_encode
ABresult
1X1
011
000
533 return $string;
534 18 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if ($should_encode) { } 0 18 18
535 0 }
536 [% END %]
537 no tt;
538  
539 sub _digest_string_with_object {
540 18 my ( $self, $object, %params ) = @_;
541  
542 my $string = delete $params{string};
543 croak "You must provide the 'string' parameter" unless defined $string;
544 1 ▶ 
Subroutine decrypt_string: called CC=2 SCAR=7.0
Pod documented
545 1 $object->add($string);
546  
547 1 $self->maybe_encode( $object->digest, \%params );
548 1 ▶}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 1 1
549  
550 1 sub digest_string {
551 my ( $self, %params ) = _args @_, "string";
552  
553 1 my $d = $self->digest_object( %params );
554  
555 $self->_digest_string_with_object( $d, %params );
556 }
557 1 ▶ 
Subroutine maybe_decode: called CC=4 SCAR=16.4
Pod documented
558 1 sub mac_digest_string {
559 my ( $self, %params ) = _args @_, "string";
560  
561 my $d = $self->mac_object( %params );
562 1 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
exists $params->{'decode'} ? : 0 1 1
Condition33%1/3
exists $params->{"encoding"} or $self->default_encode
l!l&&r!l&&!r
001
MC/DC0%0/2
exists $params->{"encoding"} or $self->default_encode
exists $params->{"encoding"} $self->default_encode
Truth table33%1/3
A or B
A= exists $params->{"encoding"}B= $self->default_encode
ABresult
1X1
011
000
563 $self->_digest_string_with_object( $d, %params );
564 1 ▶}
Branch: 1 branch
BranchTrueFalseTotal
if ($should_encode) { } 0 1 1
565 0  
566 sub _do_verify_hash {
567 my ( $self, %params ) = _args @_;
568  
569 my $hash = delete $params{hash};
570 1 my $fatal = delete $params{fatal};
571 croak "You must provide the 'string' and 'hash' parameters" unless defined $params{string} and defined $hash;
572  
573 my $meth = $params{digest_method};
574  
575 17 ▶ return 1 if $hash eq $self->$meth(%params);
Subroutine _digest_string_with_object: called CC=2 SCAR=7.0
576 17  
577 if ( $fatal ) {
578 17 croak "Digest verification failed";
579 17 ▶ } else {
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 17 17
580 return;
581 17 }
582 }
583 17  
584 sub verify_hash {
585 my ( $self, @args ) = @_;
586 11 ▶ $self->_do_verify_hash(@args, digest_method => "digest_string");
Subroutine digest_string: called CC=1 SCAR=0.0
Pod documented
587 11 }
588  
589 11 sub verify_digest {
590 my ( $self, @args ) = @_;
591 11 $self->verify_hash(@args);
592 }
593  
594 6 ▶sub verify_mac {
Subroutine mac_digest_string: called CC=1 SCAR=0.0
Pod documented
595 6 my ( $self, @args ) = @_;
596 $self->_do_verify_hash(@args, digest_method => "mac_digest_string");
597 6 }
598  
599 6 {
600 my @flags = qw/serialized/;
601  
602 5 ▶ sub _flag_hash_to_int {
Subroutine _do_verify_hash: called CC=5 SCAR=16.3
603 5 my ( $self, $flags ) = @_;
604  
605 5 my $bit = 1;
606 5 my $flags_int = 0;
607 5 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"string"} and defined $hash 0 5 5
Condition33%1/3
defined $params{"string"} and defined $hash
!ll&&!rl&&r
005
MC/DC0%0/2
defined $params{"string"} and defined $hash
defined $params{"string"} defined $hash
Truth table33%1/3
A and B
A= defined $params{"string"}B= defined $hash
ABresult
0X0
100
111
608 foreach my $flag (@flags) {
609 5 $flags_int |= $bit if $flags->{$flag};
610 } continue {
611 5 ▶ $bit *= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $hash eq $self->$meth(%params) 2 3 5
612 }
613 3 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if ($fatal) { } 1 2 3
614 1 return $flags_int;
615 }
616 2  
617 sub _flag_int_to_hash {
618 my ( $self, $flags ) = @_;
619  
620 5 ▶ my $bit =1;
Subroutine verify_hash: called CC=1 SCAR=0.0
Pod undocumented
621 5 my %flags;
622 5  
623 foreach my $flag (@flags ) {
624 $flags{$flag} = $flags & $bit;
625 0 ▶ } continue {
Subroutine verify_digest: not called CC=1 SCAR=6.9
Pod documented
626 0 $bit *= 2;
627 0 }
628  
629 return wantarray ? %flags : \%flags;
630 0 ▶ }
Subroutine verify_mac: not called CC=1 SCAR=6.9
Pod documented
631 0 }
632 0  
633 sub tamper_proof {
634 my ( $self, %params ) = _args @_, "data";
635  
636 6 $params{string} = $self->pack_data( %params );
637 #$params{header} = $self->pack_data( %params, data => $params{header} ) if exists $params{header}; # FIXME this is not yet finished
638 0 ▶ 
Subroutine _flag_hash_to_int: not called CC=3 SCAR=24.8
639 0 $self->tamper_proof_string( %params );
640 }
641 0  
642 0 sub freeze_data {
643 my ( $self, %params ) = @_;
644 0 require Storable;
645 0 ▶ Storable::nfreeze($params{data});
Branch: 1 branch
BranchTrueFalseTotal
if $flags->{$flag} 0 0 0
646 }
647 0  
648 sub thaw_data {
649 my ( $self, %params ) = @_;
650 0 require Storable;
651 Storable::thaw($params{data});
652 }
653 0 ▶ 
Subroutine _flag_int_to_hash: not called CC=3 SCAR=24.8
654 0 sub tamper_proof_string {
655 my ( $self, %params ) = _args @_, "string";
656 0  
657 0 my $encrypted = exists $params{encrypt}
658 ? $params{encrypt}
659 0 : !$self->default_tamper_proof_unencrypted;
660 0  
661  
662 0 my $type = ( $encrypted ? "aead" : "mac" );
663  
664 my $method = "${type}_tamper_proof_string";
665 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
666 my $string = $self->$method( %params );
667  
668 return $self->_pack_tamper_proof( $type => $string );
669 6 ▶}
Subroutine tamper_proof: not called CC=1 SCAR=3.5
Pod documented
670 0  
671 {
672 0 my @tamper_proof_types = qw/mac aead/;
673 my %tamper_proof_type; @tamper_proof_type{@tamper_proof_types} = 1 .. @tamper_proof_types;
674  
675 0 sub _pack_tamper_proof {
676 my ( $self, $type, $proof ) = @_;
677 pack("C a*", $tamper_proof_type{$type}, $proof);
678 0 ▶ }
Subroutine freeze_data: not called CC=1 SCAR=6.9
Pod undocumented
679 0  
680 0 sub _unpack_tamper_proof {
681 0 my ( $self, $packed ) = @_;
682 my ( $type, $string ) = unpack("C a*", $packed);
683  
684 0 ▶ return (
Subroutine thaw_data: not called CC=1 SCAR=6.9
Pod undocumented
685 0 ($tamper_proof_types[ $type-1 ] || croak "Unknown tamper proofing method"),
686 0 $string,
687 0 );
688 }
689 }
690 0 ▶ 
Subroutine tamper_proof_string: not called CC=3 SCAR=24.8
Pod documented
691 0 sub _authenticated_mode {
692 my ( $self, $params ) = @_;
693  
694 # trust explicit param
695 0 ▶ if ( exists $params->{authenticated_mode} ) {
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'encrypt'} ? : 0 0 0
696 $params->{mode} = delete $params->{authenticated_mode};
697 return 1;
698 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
$encrypted ? : 0 0 0
699  
700 0 # check if the explicit param is authenticated
701 if ( exists $params->{mode} ) {
702 0 # allow overriding
703 if ( exists $params->{mode_is_authenticated} ) {
704 0 return $params->{mode_is_authenticated};
705 }
706  
707 if ( $KNOWN_AUTHENTICATING_MODES{uc($params->{mode})} ) {
708 6 return 1;
709 6 } else {
710 return;
711 0 ▶ }
Subroutine _pack_tamper_proof: not called CC=1 SCAR=6.9
712 0 }
713 0  
714 $params->{mode} = $self->_process_param('authenticated_mode');
715  
716 0 ▶ return 1;
Subroutine _unpack_tamper_proof: not called CC=2 SCAR=17.9
717 0 }
718 0  
719 sub _pack_hash_and_message {
720 my ( $self, $hash, $message ) = @_;
721 0 ▶ pack("n/a* a*", $hash, $message);
Condition0%0/2
$tamper_proof_types[$type - 1] || croak('Unknown tamper proofing method')
l!l
00
MC/DC0%0/1
$tamper_proof_types[$type - 1] || croak('Unknown tamper proofing method')
$tamper_proof_types[$type - 1]
Truth table0%0/2
A
A= $tamper_proof_types[$type - 1]
Aresult
11
00
722 }
723  
724 sub _unpack_hash_and_message {
725 my ( $self, $packed ) = @_;
726 unpack("n/a* a*", $packed);
727 6 ▶}
Subroutine _authenticated_mode: not called CC=5 SCAR=32.8
728 0  
729 our $PACK_FORMAT_VERSION = 1;
730  
731 0 ▶sub pack_data {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"authenticated_mode"}) 0 0 0
732 0 my ( $self, %params ) = _args @_, "data";
733 0  
734 $self->_process_params( \%params, qw/
735 data
736 /);
737 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"mode"}) 0 0 0
738 my $data = delete $params{data};
739 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"mode_is_authenticated"}) 0 0 0
740 0 my %flags;
741  
742 if ( ref $data ) {
743 0 ▶ $flags{serialized} = 1;
Branch: 1 branch
BranchTrueFalseTotal
if ($Crypt::Util::KNOWN_AUTHENTICATING_MODES{uc $params->{'mode'}}) { } 0 0 0
744 0 $data = $self->freeze_data( %params, data => $data );
745 }
746 0  
747 $self->_pack_version_flags_and_string( $PACK_FORMAT_VERSION, \%flags, $data );
748 }
749  
750 0 sub unpack_data {
751 my ( $self, %params ) = _args @_, "data";
752 0  
753 $self->_process_params( \%params, qw/
754 data
755 0 ▶ /);
Subroutine _pack_hash_and_message: not called CC=1 SCAR=6.9
756 0  
757 0 my ( $version, $flags, $data ) = $self->_unpack_version_flags_and_string($params{data});
758  
759 $self->_packed_string_version_check( $version );
760 0 ▶ 
Subroutine _unpack_hash_and_message: not called CC=1 SCAR=6.9
761 0 if ( $flags->{serialized} ) {
762 0 return $self->thaw_data( %params, data => $data );
763 } else {
764 return $data;
765 6 }
766 }
767 0 ▶ 
Subroutine pack_data: not called CC=2 SCAR=17.9
Pod documented
768 0 sub _pack_version_flags_and_string {
769 my ( $self, $version, $flags, $string ) = @_;
770 0 pack("n n N/a*", $version, $self->_flag_hash_to_int($flags), $string);
771 }
772  
773 sub _unpack_version_flags_and_string {
774 0 my ( $self, $packed ) = @_;
775  
776 0 my ( $version, $flags, $string ) = unpack("n n N/a*", $packed);
777  
778 0 ▶ $flags = $self->_flag_int_to_hash($flags);
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) 0 0 0
779 0  
780 0 return ( $version, $flags, $string );
781 }
782  
783 0 sub authenticated_encrypt_string {
784 my ( $self, %params ) = _args @_, "string";
785  
786 0 ▶ # FIXME some ciphers are authenticated, but none are implemented in perl yet
Subroutine unpack_data: not called CC=2 SCAR=17.9
Pod documented
787 0 if ( $self->_authenticated_mode(\%params) ) {
788 $self->_process_params( \%params, qw(nonce) );
789 0  
790 # generate a nonce unless one is explicitly provided
791 my $nonce = $self->process_nonce(%params); # FIMXE limit to 64k?
792  
793 0 # FIXME safely encode an arbitrary header as well
794 #my $header = $params{header};
795 0 #$header = '' unless defined $header;
796  
797 0 ▶ return pack("n/a* a*", $nonce, $self->encrypt_string( %params, nonce => $nonce ) );
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{'serialized'}) { } 0 0 0
798 0 } else {
799 croak "To use encrypted tamper resistent strings an authenticated encryption mode such as EAX must be selected";
800 0 }
801 }
802  
803 sub authenticated_decrypt_string {
804 0 ▶ my ( $self, %params ) = _args @_, "string";
Subroutine _pack_version_flags_and_string: not called CC=1 SCAR=6.9
805 0  
806 0 if ( $self->_authenticated_mode(\%params) ) {
807 $self->_process_params( \%params, qw(string) );
808  
809 0 ▶ my ( $nonce, $string ) = unpack("n/a* a*", $params{string});
Subroutine _unpack_version_flags_and_string: not called CC=1 SCAR=6.9
810 0  
811 return $self->decrypt_string(
812 0 fatal => 1,
813 %params,
814 0 nonce => $nonce,
815 string => $string,
816 0 );
817 } else {
818 croak "To use encrypted tamper resistent strings an authenticated encryption mode such as EAX must be selected";
819 0 ▶ }
Subroutine authenticated_encrypt_string: not called CC=2 SCAR=17.9
Pod documented
820 0 }
821  
822 sub aead_tamper_proof_string {
823 0 ▶ my ( $self, %params ) = _args @_, "string";
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_authenticated_mode(\%params)) { } 0 0 0
824 0  
825 $self->authenticated_encrypt_string( %params );
826 }
827 0  
828 sub mac_tamper_proof_string {
829 my ( $self, %params ) = _args @_, "string";
830  
831 0 my $string = delete $params{string};
832 croak "You must provide the 'string' parameter" unless defined $string;
833 0  
834 my $hash = $self->mac_digest_string(
835 %params,
836 encode => 0,
837 0 ▶ string => $string,
Subroutine authenticated_decrypt_string: not called CC=2 SCAR=17.9
Pod documented
838 0 );
839  
840 0 ▶ return $self->_pack_hash_and_message( $hash, $string );
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_authenticated_mode(\%params)) { } 0 0 0
841 0 }
842  
843 0 sub thaw_tamper_proof_string {
844 my ( $self, %params ) = _args @_, "string";
845 0  
846 my $string = delete $params{string};
847 croak "You must provide the 'string' parameter" unless defined $string;
848  
849 my ( $type, $message ) = $self->_unpack_tamper_proof($string);
850  
851 my $method = "thaw_tamper_proof_string_$type";
852 0  
853 my $packed = $self->$method( %params, string => $message );
854 }
855  
856 0 ▶sub thaw_tamper_proof {
Subroutine aead_tamper_proof_string: not called CC=1 SCAR=6.9
Pod documented
857 0 my ( $self, %params ) = _args @_, "string";
858 my $packed = $self->thaw_tamper_proof_string(%params);
859 0 $self->unpack_data(%params, data => $packed);
860 }
861  
862 0 ▶sub thaw_tamper_proof_string_aead {
Subroutine mac_tamper_proof_string: not called CC=2 SCAR=17.9
Pod documented
863 0 my ( $self, %params ) = _args @_, "string";
864  
865 0 $self->authenticated_decrypt_string( %params );
866 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
867  
868 0 sub thaw_tamper_proof_string_mac {
869 my ( $self, %params ) = _args @_, "string";
870  
871 my $hashed_packed = delete $params{string};
872 croak "You must provide the 'string' parameter" unless defined $hashed_packed;
873  
874 0 my ( $hash, $packed ) = $self->_unpack_hash_and_message( $hashed_packed );
875  
876 return unless $self->verify_mac(
877 0 ▶ fatal => 1,
Subroutine thaw_tamper_proof_string: not called CC=2 SCAR=17.9
Pod documented
878 0 %params,
879 hash => $hash,
880 0 decode => 0,
881 0 ▶ string => $packed,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
882 );
883 0  
884 return $packed;
885 0 }
886  
887 0 sub _packed_string_version_check {
888 my ( $self, $version ) = @_;
889  
890 0 ▶ croak "Incompatible packed string (I'm version $PACK_FORMAT_VERSION, thawing version $version)"
Subroutine thaw_tamper_proof: not called CC=1 SCAR=6.9
Pod documented
891 0 unless $version == $PACK_FORMAT_VERSION;
892 0 }
893 0  
894 use tt;
895 [% FOR f IN ["en","de"] %]
896 0 ▶sub [% f %]code_string {
Subroutine thaw_tamper_proof_string_aead: not called CC=1 SCAR=6.9
Pod undocumented
897 0 my ( $self, %params ) = _args @_, "string";
898  
899 0 my $string = delete $params{string};
900 croak "You must provide the 'string' parameter" unless defined $string;
901  
902 0 ▶ $self->_process_params( \%params, qw/
Subroutine thaw_tamper_proof_string_mac: not called CC=3 SCAR=24.8
Pod undocumented
903 0 encoding
904 /);
905 0  
906 0 ▶ my $encoding = delete $params{encoding};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hashed_packed 0 0 0
907 croak "Encoding method must be an encoding name" unless $encoding;
908 0 my $method = "[% f %]code_string_$encoding";
909 croak "Encoding method $encoding is not supported" unless $self->can($method);
910 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verify_mac("fatal", 1, %params, "hash", $hash, "decode", 0, "string", $packed) 0 0 0
911 $self->$method($string);
912 }
913 [% END %]
914 no tt;
915  
916 sub encode_string_hex {
917 my ( $self, $string ) = @_;
918 0 unpack("H*", $string);
919 }
920  
921 0 ▶sub decode_string_hex {
Subroutine _packed_string_version_check: not called CC=2 SCAR=17.9
922 0 my ( $self, $hex ) = @_;
923 pack("H*", $hex );
924 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
unless $version == $Crypt::Util::PACK_FORMAT_VERSION 0 0 0
925  
926 sub encode_string_base64 {
927 my ( $self, $string ) = @_;
928 require MIME::Base64;
929 89 ▶ MIME::Base64::encode_base64($string, "");
Subroutine encode_string: called CC=4 SCAR=14.2
Pod documented
930 89 }
931  
932 89 sub encode_string_base64_wrapped {
933 89 ▶ my ( $self, $string ) = @_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 89 89
934 require MIME::Base64;
935 89 MIME::Base64::encode_base64($string);
936 }
937  
938 sub decode_string_base64 {
939 89 my ( $self, $base64 ) = @_;
940 89 ▶ require MIME::Base64;
Branch: 1 branch
BranchTrueFalseTotal
unless $encoding 0 89 89
941 89 MIME::Base64::decode_base64($base64);
942 89 ▶}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 0 89 89
943  
944 89 # http://www.dev411.com/blog/2006/10/02/encoding-hashed-uids-base64-vs-hex-vs-base32
945 sub encode_string_uri_base64 {
946 my ( $self, $string ) = @_;
947 88 ▶ require MIME::Base64::URLSafe;
Subroutine decode_string: called CC=4 SCAR=14.2
Pod documented
948 88 MIME::Base64::URLSafe::encode($string);
949 }
950 88  
951 88 ▶sub decode_string_uri_base64 {
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 88 88
952 my ( $self, $base64 ) = @_;
953 88 require MIME::Base64::URLSafe;
954 MIME::Base64::URLSafe::decode($base64);
955 }
956  
957 88 sub encode_string_base32 {
958 88 ▶ my ( $self, $string ) = @_;
Branch: 1 branch
BranchTrueFalseTotal
unless $encoding 0 88 88
959 88 require MIME::Base32;
960 88 ▶ MIME::Base32::encode_rfc3548($string);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 0 88 88
961 }
962 88  
963 sub decode_string_base32 {
964 my ( $self, $base32 ) = @_;
965 require MIME::Base32;
966 9 ▶ MIME::Base32::decode_rfc3548(uc($base32));
Subroutine encode_string_hex: called CC=1 SCAR=0.0
Pod documented
967 9 }
968 9  
969 sub encode_string_uri_escape {
970 my ( $self, $string ) = @_;
971 8 ▶ require URI::Escape;
Subroutine decode_string_hex: called CC=1 SCAR=0.0
Pod documented
972 8 URI::Escape::uri_escape($string);
973 8 }
974  
975 sub decode_string_uri_escape {
976 16 ▶ my ( $self, $uri_escaped ) = @_;
Subroutine encode_string_base64: called CC=1 SCAR=0.0
Pod documented
977 16 require URI::Escape;
978 16 URI::Escape::uri_unescape($uri_escaped);
979 16 }
980  
981 use tt;
982 0 ▶[% FOR symbolic_encoding IN ["uri", "alphanumerical", "printable"] %]
Subroutine encode_string_base64_wrapped: not called CC=1 SCAR=6.9
Pod documented
983 0 [% FOR f IN ["en", "de"] %]
984 0 sub [% f %]code_string_[% symbolic_encoding %] {
985 0 my ( $self, $string ) = @_;
986 my $encoding = $self->_process_param("[% symbolic_encoding %]_encoding");
987 $self->[% f %]code_string( string => $string, encoding => $encoding );
988 16 ▶}
Subroutine decode_string_base64: called CC=1 SCAR=0.0
Pod documented
989 16 [% END %]
990 16 [% END %]
991 16 no tt;
992  
993 sub exported_instance {
994 my $self = shift;
995 24 ▶ return $self;
Subroutine encode_string_uri_base64: called CC=1 SCAR=0.0
Pod documented
996 24 }
997 24  
998 24 sub __curry_instance {
999 my ($class, $method_name, undef, $col) = @_;
1000  
1001 24 ▶ my $self = $col->{instance} ||= $class->__curry_flavoured_instance($col);
Subroutine decode_string_uri_base64: called CC=1 SCAR=0.0
Pod documented
1002 24  
1003 24 sub { $self->$method_name(@_) };
1004 24 }
1005  
1006 sub __curry_flavoured_instance {
1007 16 ▶ my ( $class, $col ) = @_;
Subroutine encode_string_base32: called CC=1 SCAR=0.0
Pod documented
1008 16  
1009 16 my %params; @params{ map { "default_$_" } keys %{ $col->{defaults} } } = values %{ $col->{defaults} };
1010 16  
1011 $class->new( \%params );
1012 }
1013 16 ▶ 
Subroutine decode_string_base32: called CC=1 SCAR=0.0
Pod documented
1014 16 __PACKAGE__;
1015 16  
1016 16 __END__
↑ Summary Digest/MultiHash.pm »