| 1 | package Linux::Perl::getrandom; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =encoding utf-8 | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | Linux::Perl::getrandom | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | my $numbytes = Linux::Perl::getrandom::x86_64->getrandom( | ||||||||||||||||||||
| 15 | buffer => \$buffer, | ||||||||||||||||||||
| 16 | flags => [ 'RANDOM', 'NONBLOCK' ], | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # … or, platform-neutral: | ||||||||||||||||||||
| 20 | my $numbytes = Linux::Perl::getrandom->getrandom( | ||||||||||||||||||||
| 21 | buffer => \$buffer, | ||||||||||||||||||||
| 22 | flags => [ 'RANDOM', 'NONBLOCK' ], | ||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | This is an interface to Linux’s C<getrandom> system call. This system | ||||||||||||||||||||
| 28 | call is documented only for kernel 3.17 and after; however, it appears | ||||||||||||||||||||
| 29 | to be present in some earlier kernel versions. | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | ▶ | use Linux::Perl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 1 | ▶ | use Linux::Perl::Pointer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | ▶ | use parent 'Linux::Perl::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | my %FLAG_VALUE = ( | |||||||||||||||||||
| 39 | NONBLOCK => 1, | ||||||||||||||||||||
| 40 | RANDOM => 2, | ||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | ▶ | sub getrandom { | ||||||||||||||||||
|
Subroutine
getrandom: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||
| 44 | 1 | my ($class, %opts) = @_; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | $class = $class->_get_arch_module(); | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | my $flags = 0; | |||||||||||||||||||
| 49 | 1 | ▶ | if ($opts{'flags'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | for my $f ( @{ $opts{'flags'} } ) { | |||||||||||||||||||
| 51 | 0 | ▶ | $flags |= $FLAG_VALUE{$f} || do { | ||||||||||||||||||
|
Condition0%0/3
$FLAG_VALUE{$f} || do {
die "Invalid flag: \342\200\234$f\342\200\235!"
}
MC/DC0%0/2
$FLAG_VALUE{$f} || do {
die "Invalid flag: \342\200\234$f\342\200\235!"
}
$FLAG_VALUE{$f}
do {
die "Invalid flag: \342\200\234$f\342\200\235!"
}
Truth table0%0/3
A || B
A= $FLAG_VALUE{$f}B= do {
die "Invalid flag: \342\200\234$f\342\200\235!"
}
| |||||||||||||||||||||
| 52 | 0 | die "Invalid flag: “$f”!"; | |||||||||||||||||||
| 53 | }; | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | ▶ | if ('SCALAR' ne ref $opts{'buffer'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | die "“buffer” must be a scalar reference, not “$opts{'buffer'}”!"; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | return Linux::Perl::call( | ||||||||||||||||||||
| 62 | $class->NR_getrandom(), | ||||||||||||||||||||
| 63 | 1 | Linux::Perl::Pointer::get_address( ${ $opts{'buffer'} } ), | |||||||||||||||||||
| 64 | 1 | length( ${ $opts{'buffer'} } ), | |||||||||||||||||||
| 65 | 0 + $flags, | ||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||