line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Random::Source::Weak::openssl; # git description: v0.02-6-g14c3ddf |
2
|
|
|
|
|
|
|
# ABSTRACT: Get random bytes from the OpenSSL command line utility |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
70875
|
use Moo; |
|
1
|
|
|
|
|
11248
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1537
|
use File::Which qw(which); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
440
|
use namespace::clean; |
|
1
|
|
|
|
|
11266
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub available { |
13
|
0
|
|
|
0
|
1
|
0
|
which("openssl"); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
extends qw( |
17
|
|
|
|
|
|
|
Crypt::Random::Source::Weak |
18
|
|
|
|
|
|
|
Crypt::Random::Source::Base::Proc |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has openssl => ( |
22
|
|
|
|
|
|
|
is => "rw", |
23
|
|
|
|
|
|
|
default => sub { which("openssl") }, |
24
|
|
|
|
|
|
|
trigger => sub { shift->clear_command }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has default_chunk_size => ( |
28
|
|
|
|
|
|
|
is => "rw", |
29
|
|
|
|
|
|
|
default => 1 << 16, |
30
|
|
|
|
|
|
|
trigger => sub { shift->clear_command }, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'command' => ( |
34
|
|
|
|
|
|
|
isa => sub { die "$_[0] must be an arrayref" unless ref $_[0] eq 'ARRAY' }, |
35
|
|
|
|
|
|
|
is => 'lazy', |
36
|
|
|
|
|
|
|
clearer => "clear_command", |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _build_command { |
40
|
4
|
|
|
4
|
|
563
|
my $self = shift; |
41
|
4
|
|
|
|
|
74
|
return [$self->openssl, "rand", $self->default_chunk_size]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub BUILD { |
45
|
1
|
|
|
1
|
0
|
266
|
my $self = shift; |
46
|
1
|
|
|
|
|
4
|
$self->set_default_command; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set_default_command { |
50
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
20
|
$self->default_chunk_size(1 << 16) # about 1.5x the overhead of simply spawning openssl rand 0 on my computer |
53
|
|
|
|
|
|
|
unless $self->default_chunk_size; |
54
|
|
|
|
|
|
|
|
55
|
1
|
50
|
|
|
|
29
|
$self->command([qw(openssl rand), $self->default_chunk_size]) |
56
|
|
|
|
|
|
|
unless defined $self->command; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _read_too_short { |
60
|
3
|
|
|
3
|
|
25778
|
my ( $self, $buf, $got, $req ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
30
|
$self->close; # will cause openssl to be respawned |
63
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
281
|
return $buf . $self->get( $req - $got ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__PACKAGE__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |