| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Crypt::Age::Stanza; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Base class for age recipient stanzas |
|
5
|
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
22
|
use Moo; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
21
|
|
|
7
|
4
|
|
|
4
|
|
1401
|
use Carp qw(croak); |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
273
|
|
|
8
|
4
|
|
|
4
|
|
2824
|
use MIME::Base64 qw(encode_base64 decode_base64); |
|
|
4
|
|
|
|
|
3255
|
|
|
|
4
|
|
|
|
|
341
|
|
|
9
|
4
|
|
|
4
|
|
38
|
use namespace::clean; |
|
|
4
|
|
|
|
|
13
|
|
|
|
4
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has type => ( |
|
13
|
|
|
|
|
|
|
is => 'ro', |
|
14
|
|
|
|
|
|
|
required => 1, |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has args => ( |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
default => sub { [] }, |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has body => ( |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
default => '', |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub encode_body_base64 { |
|
31
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
|
32
|
0
|
|
|
|
|
0
|
return encode_base64_no_padding($self->body); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode_base64_no_padding { |
|
36
|
65
|
|
|
65
|
1
|
142
|
my ($data) = @_; |
|
37
|
65
|
|
|
|
|
219
|
my $encoded = encode_base64($data, ''); |
|
38
|
65
|
|
|
|
|
422
|
$encoded =~ s/=+$//; # Remove padding |
|
39
|
65
|
|
|
|
|
9627
|
return $encoded; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub decode_base64_no_padding { |
|
43
|
33
|
|
|
33
|
1
|
81
|
my ($encoded) = @_; |
|
44
|
|
|
|
|
|
|
# Add padding back if needed |
|
45
|
33
|
|
|
|
|
65
|
my $pad = (4 - length($encoded) % 4) % 4; |
|
46
|
33
|
|
|
|
|
62
|
$encoded .= '=' x $pad; |
|
47
|
33
|
|
|
|
|
172
|
return decode_base64($encoded); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub to_string { |
|
51
|
41
|
|
|
41
|
1
|
79
|
my ($self) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
41
|
|
|
|
|
102
|
my @parts = ('->', $self->type, @{$self->args}); |
|
|
41
|
|
|
|
|
134
|
|
|
54
|
41
|
|
|
|
|
114
|
my $header_line = join(' ', @parts); |
|
55
|
|
|
|
|
|
|
|
|
56
|
41
|
|
|
|
|
132
|
my $body_b64 = encode_base64_no_padding($self->body); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Split into 64-char lines |
|
59
|
41
|
|
|
|
|
89
|
my @lines = ($header_line); |
|
60
|
41
|
|
|
|
|
131
|
while (length($body_b64) > 64) { |
|
61
|
0
|
|
|
|
|
0
|
push @lines, substr($body_b64, 0, 64, ''); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
41
|
|
|
|
|
72
|
push @lines, $body_b64; # Last line (may be empty for exact multiple of 64) |
|
64
|
|
|
|
|
|
|
|
|
65
|
41
|
|
|
|
|
190
|
return join("\n", @lines); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub to_bytes_for_mac { |
|
70
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
71
|
|
|
|
|
|
|
# For MAC computation, stanzas are serialized as in the header |
|
72
|
0
|
|
|
|
|
|
return $self->to_string . "\n"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |