line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Keyczar::Manager; |
2
|
1
|
|
|
1
|
|
5
|
use base 'Crypt::Keyczar'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
4
|
use Crypt::Keyczar::FileReader; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
6
|
1
|
|
|
1
|
|
4
|
use Crypt::Keyczar::Key; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
418
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub promote { |
11
|
13
|
|
|
13
|
0
|
25
|
my $self = shift; |
12
|
13
|
|
|
|
|
22
|
my $version_number = shift; |
13
|
|
|
|
|
|
|
|
14
|
13
|
|
|
|
|
44
|
my $version = $self->get_version_by_number($version_number); |
15
|
13
|
50
|
|
|
|
45
|
if ($version->status eq 'PRIMARY') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
croak "can't promote primary key#$version_number"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
elsif ($version->status eq 'ACTIVE') { |
19
|
12
|
|
|
|
|
37
|
$version->status('PRIMARY'); |
20
|
12
|
50
|
|
|
|
36
|
if ($self->primary) { |
21
|
12
|
|
|
|
|
31
|
$self->primary->status('ACTIVE'); |
22
|
|
|
|
|
|
|
} |
23
|
12
|
|
|
|
|
39
|
$self->primary($version); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ($version->status eq 'INACTIVE') { |
26
|
1
|
|
|
|
|
4
|
$version->status('ACTIVE'); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub demote { |
32
|
17
|
|
|
17
|
0
|
27
|
my $self = shift; |
33
|
17
|
|
|
|
|
27
|
my $version_number = shift; |
34
|
|
|
|
|
|
|
|
35
|
17
|
|
|
|
|
50
|
my $version = $self->get_version_by_number($version_number); |
36
|
17
|
100
|
|
|
|
50
|
if ($version->status eq 'PRIMARY') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
37
|
5
|
|
|
|
|
26
|
$version->status('ACTIVE'); |
38
|
5
|
|
|
|
|
18
|
$self->primary(undef); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ($version->status eq 'ACTIVE') { |
41
|
7
|
|
|
|
|
22
|
$version->status('INACTIVE'); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($version->status eq 'INACTIVE') { |
44
|
5
|
|
|
|
|
809
|
croak "can't demote inactive key#$version_number"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub revoke { |
50
|
11
|
|
|
11
|
0
|
22
|
my $self = shift; |
51
|
11
|
|
|
|
|
21
|
my $version_number = shift; |
52
|
|
|
|
|
|
|
|
53
|
11
|
|
|
|
|
29
|
my $version = $self->get_version_by_number($version_number); |
54
|
11
|
100
|
|
|
|
34
|
if ($version->status eq 'INACTIVE') { |
55
|
6
|
|
|
|
|
16
|
$self->metadata->remove_version($version_number); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
5
|
|
|
|
|
566
|
croak "can't revoke active or primary key#$version_number"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_version { |
64
|
17
|
|
|
17
|
0
|
34
|
my $self = shift; |
65
|
17
|
|
|
|
|
52
|
my ($status, $size) = @_; |
66
|
17
|
|
50
|
|
|
49
|
$status ||= 'ACTIVE'; |
67
|
|
|
|
|
|
|
|
68
|
17
|
|
|
|
|
50
|
my $num = scalar($self->metadata->get_versions) + 1; |
69
|
17
|
|
|
|
|
87
|
my $version = Crypt::Keyczar::KeyVersion->new($num, $status, undef); |
70
|
17
|
100
|
|
|
|
51
|
if (uc $status eq 'PRIMARY') { |
71
|
6
|
50
|
|
|
|
24
|
if ($self->primary) { |
72
|
0
|
|
|
|
|
0
|
$self->primary->status('ACTIVE'); |
73
|
|
|
|
|
|
|
} |
74
|
6
|
|
|
|
|
18
|
$self->primary($version); |
75
|
|
|
|
|
|
|
} |
76
|
17
|
100
|
|
|
|
53
|
if (!$size) { |
77
|
|
|
|
|
|
|
# find default size $self->metadata->get_type; |
78
|
|
|
|
|
|
|
} |
79
|
17
|
|
|
|
|
26
|
my $key; |
80
|
17
|
|
|
|
|
28
|
do { |
81
|
17
|
|
|
|
|
47
|
$key = Crypt::Keyczar::Key->generate_key($self->metadata->get_type, $size); |
82
|
|
|
|
|
|
|
} while ($self->get_key($key->hash)); |
83
|
17
|
|
|
|
|
75
|
$self->add_key($version, $key); |
84
|
17
|
|
|
|
|
61
|
return $version; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_version_by_number { |
89
|
41
|
|
|
41
|
0
|
67
|
my $self = shift; |
90
|
41
|
|
|
|
|
69
|
my $version_number = shift; |
91
|
41
|
|
|
|
|
103
|
my $version = $self->metadata->get_version($version_number); |
92
|
41
|
50
|
|
|
|
112
|
if (!defined $version) { |
93
|
0
|
|
|
|
|
0
|
croak "no such key version#$version_number"; |
94
|
|
|
|
|
|
|
} |
95
|
41
|
|
|
|
|
85
|
return $version; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |