| 1 | package Sys::GetRandom; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 11 | 2 | XSLoader::load __PACKAGE__, $VERSION; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 15 | GRND_RANDOM | ||||||||||||||||||||||||||||
| 16 | GRND_NONBLOCK | ||||||||||||||||||||||||||||
| 17 | getrandom | ||||||||||||||||||||||||||||
| 18 | random_bytes | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub random_bytes { | ||||||||||||||||||||||||||
|
Subroutine
random_bytes: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 1 | my ($n) = @_; | |||||||||||||||||||||||||||
| 23 | 1 | $n |= 0; | |||||||||||||||||||||||||||
| 24 | 1 | ▶ | $n >= 0 && $n <= 256 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$n >= 0 and $n <= 256
MC/DC0%0/2
$n >= 0 and $n <= 256
$n >= 0
$n <= 256
Truth table33%1/3
A and B
A= $n >= 0B= $n <= 256
| |||||||||||||||||||||||||||||
| 25 | or croak "Argument to random_bytes() must be an integer between 0 and 256, not $n"; | ||||||||||||||||||||||||||||
| 26 | 1 | ▶ | return '' if $n == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | defined(my $r = getrandom(my $buf, $n)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | or die "Internal error: getrandom(\$buf, $n) failed: $!"; | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | $r == $n | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | or die "Internal error: getrandom(\$buf, $n) returned $r"; | ||||||||||||||||||||||||||||
| 31 | 1 | $buf | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | 1 | |||||||||||||||||||||||||||
| 35 | __END__ | ||||||||||||||||||||||||||||