line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Keyczar::Util; |
2
|
16
|
|
|
16
|
|
100737
|
use base 'Exporter'; |
|
16
|
|
|
|
|
38
|
|
|
16
|
|
|
|
|
1102
|
|
3
|
16
|
|
|
16
|
|
92
|
use strict; |
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
267
|
|
4
|
16
|
|
|
16
|
|
70
|
use warnings; |
|
16
|
|
|
|
|
38
|
|
|
16
|
|
|
|
|
326
|
|
5
|
|
|
|
|
|
|
|
6
|
16
|
|
|
16
|
|
71
|
use Carp; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
868
|
|
7
|
16
|
|
|
16
|
|
5953
|
use MIME::Base64; |
|
16
|
|
|
|
|
8233
|
|
|
16
|
|
|
|
|
821
|
|
8
|
16
|
|
|
16
|
|
5129
|
use Crypt::Keyczar::Engine; |
|
16
|
|
|
|
|
41
|
|
|
16
|
|
|
|
|
4899
|
|
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
|
207
|
sub encode_json { return Crypt::Keyczar::Util::JSON::encode(@_); } |
29
|
330
|
|
|
330
|
0
|
25659
|
sub decode_json { return Crypt::Keyczar::Util::JSON::decode(@_); } |
30
|
162
|
|
|
162
|
0
|
301
|
sub json_true { return Crypt::Keyczar::Util::JSON::true(); } |
31
|
518
|
|
|
518
|
0
|
2932
|
sub json_false { return Crypt::Keyczar::Util::JSON::false(); } |
32
|
9
|
|
|
9
|
0
|
28
|
sub json_null { return Crypt::Keyczar::Util::JSON::null(); } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode { |
36
|
85
|
|
|
85
|
0
|
164
|
my $src = shift; |
37
|
85
|
50
|
|
|
|
237
|
return undef if !defined $src; |
38
|
|
|
|
|
|
|
|
39
|
85
|
|
|
|
|
286
|
my $result = encode_base64($src, ''); |
40
|
85
|
|
|
|
|
201
|
$result =~ tr{+/}{-_}; |
41
|
85
|
|
|
|
|
2834
|
$result =~ s/=*\r?\n?$//; |
42
|
85
|
|
|
|
|
320
|
return $result; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub decode { |
47
|
564
|
|
|
564
|
0
|
1868
|
my $src = shift; |
48
|
564
|
50
|
|
|
|
1235
|
return undef if !defined $src; |
49
|
|
|
|
|
|
|
|
50
|
564
|
|
|
|
|
1073
|
$src =~ tr{-_}{+/}; |
51
|
564
|
100
|
|
|
|
1412
|
if (length($src) % 4 != 0) { |
52
|
492
|
|
|
|
|
1056
|
$src .= '=' x (4 - length($src) % 4); |
53
|
|
|
|
|
|
|
} |
54
|
564
|
|
|
|
|
2812
|
return decode_base64($src); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Crypt::Keyczar::Util::JSON; |
62
|
16
|
|
|
16
|
|
173
|
use strict; |
|
16
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
314
|
|
63
|
16
|
|
|
16
|
|
70
|
use warnings; |
|
16
|
|
|
|
|
28
|
|
|
16
|
|
|
|
|
451
|
|
64
|
16
|
|
|
16
|
|
8183
|
use JSON; |
|
16
|
|
|
|
|
168878
|
|
|
16
|
|
|
|
|
78
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
1102
|
|
|
1102
|
|
3339
|
sub is_v1 { return $JSON::VERSION < 2.0; } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub encode { |
71
|
83
|
|
|
83
|
|
145
|
my $data = shift; |
72
|
83
|
|
|
|
|
399
|
my $enc = JSON->new; |
73
|
83
|
50
|
|
|
|
194
|
return $enc->objToJson($data) if is_v1(); |
74
|
83
|
|
|
|
|
309
|
$enc->utf8(1); |
75
|
83
|
|
|
|
|
1159
|
return $enc->encode($data); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub decode { |
80
|
330
|
|
|
330
|
|
666
|
my $data = shift; |
81
|
330
|
|
|
|
|
1604
|
my $dec = JSON->new; |
82
|
330
|
50
|
|
|
|
809
|
return $dec->jsonToObj($data) if is_v1(); |
83
|
330
|
|
|
|
|
1164
|
$dec->utf8(1); |
84
|
330
|
|
|
|
|
3803
|
return $dec->decode($data); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
162
|
50
|
|
162
|
|
280
|
sub true { return is_v1() ? JSON::True() : JSON::true(); } |
89
|
518
|
50
|
|
518
|
|
940
|
sub false { return is_v1() ? JSON::False() : JSON::false(); } |
90
|
9
|
50
|
|
9
|
|
18
|
sub null { return is_v1() ? JSON::Null() : JSON::null(); } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |