| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Crypt::Random::Source::Base; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Abstract base class for L classes |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
4883
|
use Moo; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
45
|
|
|
7
|
7
|
|
|
7
|
|
2093
|
use namespace::clean; |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
41
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
0
|
|
|
0
|
1
|
|
sub available { 0 } |
|
10
|
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
1
|
|
sub rank { 0 } |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
0
|
1
|
|
sub seed { } |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
1
|
|
sub get { die "abstract" } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# cannibalized from IO::Scalar |
|
18
|
|
|
|
|
|
|
sub read { |
|
19
|
0
|
|
|
0
|
1
|
|
my $self = $_[0]; |
|
20
|
0
|
|
|
|
|
|
my $n = $_[2]; |
|
21
|
0
|
|
0
|
|
|
|
my $off = $_[3] || 0; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $read = $self->get($n); |
|
24
|
0
|
|
|
|
|
|
$n = length($read); |
|
25
|
0
|
0
|
|
|
|
|
($off ? substr($_[1], $off) : $_[1]) = $read; |
|
26
|
0
|
|
|
|
|
|
return $n; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_data { |
|
30
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if ( my $n = $params{Length} ) { |
|
33
|
0
|
|
|
|
|
|
return $self->get($n); |
|
34
|
|
|
|
|
|
|
} else { |
|
35
|
0
|
|
|
|
|
|
my $size = $params{Size}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
|
if (ref $size && ref $size eq "Math::Pari") { |
|
38
|
0
|
|
|
|
|
|
$size = Math::Pari::pari2num($size); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return $self->get( int($size / 8) + 1 ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=encoding UTF-8 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Crypt::Random::Source::Base - Abstract base class for L classes |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 0.11 |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Moose; |
|
62
|
|
|
|
|
|
|
extends qw(Crypt::Random::Source::Base); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This is an abstract base class. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
In the future it will be a role. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 METHODS |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 get $n, %args |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Gets C<$n> random bytes and returns them as a string. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This method may produce fatal errors if the source was unable to provide enough |
|
77
|
|
|
|
|
|
|
data. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 read $buf, $n, [ $off ] |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This method is cannibalized from L. It provides an L |
|
82
|
|
|
|
|
|
|
work-alike. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Note that subclasses override this to operate on a real handle directly if |
|
85
|
|
|
|
|
|
|
available. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 seed @stuff |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
On supporting sources this method will add C<@stuff>, whatever it may be, to |
|
90
|
|
|
|
|
|
|
the random seed. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Some sources may not support this, so be careful. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 available |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This is a class method, such that when it returns true calling C without |
|
97
|
|
|
|
|
|
|
arguments on the class should provide a working source of random data. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This is use by L. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 rank |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This is a class method, with some futz value for a ranking, to help known good |
|
104
|
|
|
|
|
|
|
sources be tried before known bad (slower, less available) sources. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 get_data %Params |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Provided for compatibility with L |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SUPPORT |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Bugs may be submitted through L |
|
113
|
|
|
|
|
|
|
(or L). |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This software is copyright (c) 2008 by Yuval Kogman. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
124
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |