line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Keyczar::Util; |
2
|
16
|
|
|
16
|
|
289776
|
use base 'Exporter'; |
|
16
|
|
|
|
|
44
|
|
|
16
|
|
|
|
|
2227
|
|
3
|
16
|
|
|
16
|
|
91
|
use strict; |
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
481
|
|
4
|
16
|
|
|
16
|
|
86
|
use warnings; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
399
|
|
5
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
75
|
use Carp; |
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
2422
|
|
7
|
16
|
|
|
16
|
|
39151
|
use MIME::Base64; |
|
16
|
|
|
|
|
18764
|
|
|
16
|
|
|
|
|
1091
|
|
8
|
16
|
|
|
16
|
|
10407
|
use Crypt::Keyczar::Engine; |
|
16
|
|
|
|
|
54
|
|
|
16
|
|
|
|
|
9509
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
11
|
|
|
|
|
|
|
encode_json decode_json |
12
|
|
|
|
|
|
|
json_true json_false |
13
|
|
|
|
|
|
|
json_null |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub create_from_json { |
19
|
0
|
|
|
0
|
0
|
0
|
my $json = shift; |
20
|
0
|
|
|
|
|
0
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
my $opts = decode_json($json); |
23
|
0
|
0
|
|
|
|
0
|
return undef if !defined $opts; |
24
|
0
|
|
|
|
|
0
|
return $class->new(%{$opts}); |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
83
|
|
|
83
|
0
|
300
|
sub encode_json { return Crypt::Keyczar::Util::JSON::encode(@_); } |
29
|
330
|
|
|
330
|
0
|
36463
|
sub decode_json { return Crypt::Keyczar::Util::JSON::decode(@_); } |
30
|
162
|
|
|
162
|
0
|
331
|
sub json_true { return Crypt::Keyczar::Util::JSON::true(); } |
31
|
518
|
|
|
518
|
0
|
2942
|
sub json_false { return Crypt::Keyczar::Util::JSON::false(); } |
32
|
9
|
|
|
9
|
0
|
26
|
sub json_null { return Crypt::Keyczar::Util::JSON::null(); } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode { |
36
|
85
|
|
|
85
|
0
|
171
|
my $src = shift; |
37
|
85
|
50
|
|
|
|
215
|
return undef if !defined $src; |
38
|
|
|
|
|
|
|
|
39
|
85
|
|
|
|
|
577
|
my $result = encode_base64($src, ''); |
40
|
85
|
|
|
|
|
183
|
$result =~ tr{+/}{-_}; |
41
|
85
|
|
|
|
|
4802
|
$result =~ s/=*\r?\n?$//; |
42
|
85
|
|
|
|
|
339
|
return $result; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub decode { |
47
|
564
|
|
|
564
|
0
|
2174
|
my $src = shift; |
48
|
564
|
50
|
|
|
|
1203
|
return undef if !defined $src; |
49
|
|
|
|
|
|
|
|
50
|
564
|
|
|
|
|
1006
|
$src =~ tr{-_}{+/}; |
51
|
564
|
100
|
|
|
|
1610
|
if (length($src) % 4 != 0) { |
52
|
492
|
|
|
|
|
1090
|
$src .= '=' x (4 - length($src) % 4); |
53
|
|
|
|
|
|
|
} |
54
|
564
|
|
|
|
|
3761
|
return decode_base64($src); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Crypt::Keyczar::Util::JSON; |
62
|
16
|
|
|
16
|
|
224
|
use strict; |
|
16
|
|
|
|
|
27
|
|
|
16
|
|
|
|
|
3327
|
|
63
|
16
|
|
|
16
|
|
97
|
use warnings; |
|
16
|
|
|
|
|
30
|
|
|
16
|
|
|
|
|
907
|
|
64
|
16
|
|
|
16
|
|
25445
|
use JSON; |
|
16
|
|
|
|
|
1545445
|
|
|
16
|
|
|
|
|
121
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
1102
|
|
|
1102
|
|
4558
|
sub is_v1 { return $JSON::VERSION < 2.0; } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub encode { |
71
|
83
|
|
|
83
|
|
137
|
my $data = shift; |
72
|
83
|
|
|
|
|
535
|
my $enc = JSON->new; |
73
|
83
|
50
|
|
|
|
208
|
return $enc->objToJson($data) if is_v1(); |
74
|
83
|
|
|
|
|
358
|
$enc->utf8(1); |
75
|
83
|
|
|
|
|
2445
|
return $enc->encode($data); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub decode { |
80
|
330
|
|
|
330
|
|
562
|
my $data = shift; |
81
|
330
|
|
|
|
|
2123
|
my $dec = JSON->new; |
82
|
330
|
50
|
|
|
|
791
|
return $dec->jsonToObj($data) if is_v1(); |
83
|
330
|
|
|
|
|
1264
|
$dec->utf8(1); |
84
|
330
|
|
|
|
|
5761
|
return $dec->decode($data); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
162
|
50
|
|
162
|
|
279
|
sub true { return is_v1() ? JSON::True() : JSON::true(); } |
89
|
518
|
50
|
|
518
|
|
868
|
sub false { return is_v1() ? JSON::False() : JSON::false(); } |
90
|
9
|
50
|
|
9
|
|
39
|
sub null { return is_v1() ? JSON::Null() : JSON::null(); } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |