| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sys::GetRandom::FFI; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: get random bytes from the system |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
254748
|
use v5.20; |
|
|
1
|
|
|
|
|
4
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
72
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
8
|
use Exporter qw( import ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
9
|
1
|
|
|
1
|
|
1006
|
use FFI::Platypus 2.00; |
|
|
1
|
|
|
|
|
11779
|
|
|
|
1
|
|
|
|
|
65
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
702
|
use experimental qw( signatures ); |
|
|
1
|
|
|
|
|
5404
|
|
|
|
1
|
|
|
|
|
7
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
220
|
use constant GRND_NONBLOCK => 0x0001; |
|
|
1
|
|
|
|
|
36
|
|
|
|
1
|
|
|
|
|
100
|
|
|
14
|
1
|
|
|
1
|
|
8
|
use constant GRND_RANDOM => 0x0002; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
360
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( GRND_RANDOM GRND_NONBLOCK getrandom ); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 'v0.1.1'; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
1
|
273605
|
sub getrandom( $size, $opts = 0 ) { |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
2
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
12
|
state $ffi = FFI::Platypus->new( |
|
24
|
|
|
|
|
|
|
api => 2, |
|
25
|
|
|
|
|
|
|
lib => undef, # libc |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
12084
|
state $random = $ffi->function( getrandom => [ 'string', 'size_t', 'int' ] => 'size_t' ); |
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
487
|
my $buffer = "\0" x $size; |
|
31
|
1
|
|
|
|
|
46
|
my $res = $random->call( $buffer, $size, $opts ); |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
50
|
|
|
|
17
|
return $res != -1 ? $buffer : undef; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |