| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Crypt::Random::Source::Weak::openssl; |
|
4
|
1
|
|
|
1
|
|
23926
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use File::Which qw(which); |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use namespace::clean -except => [qw(meta)]; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub available { |
|
13
|
|
|
|
|
|
|
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 => "ArrayRef", |
|
35
|
|
|
|
|
|
|
is => "ro", |
|
36
|
|
|
|
|
|
|
lazy_build => 1, |
|
37
|
|
|
|
|
|
|
clearer => "clear_command", |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _build_command { |
|
41
|
|
|
|
|
|
|
my $self = shift; |
|
42
|
|
|
|
|
|
|
return [$self->openssl, "rand", $self->default_chunk_size]; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub BUILD { |
|
46
|
|
|
|
|
|
|
my $self = shift; |
|
47
|
|
|
|
|
|
|
$self->set_default_command; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub set_default_command { |
|
51
|
|
|
|
|
|
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->default_chunk_size(1 << 16) # about 1.5x the overhead of simply spawning openssl rand 0 on my computer |
|
54
|
|
|
|
|
|
|
unless $self->default_chunk_size; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->command([qw(openssl rand), $self->default_chunk_size]) |
|
57
|
|
|
|
|
|
|
unless defined $self->command; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _read_too_short { |
|
61
|
|
|
|
|
|
|
my ( $self, $buf, $got, $req ) = @_; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->close; # will cause openssl to be respawned |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $buf . $self->get( $req - $got ); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__PACKAGE__ |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |