| 1 | package Linux::Event::WebSocket::_Random; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Fcntl qw(FD_CLOEXEC F_GETFD F_SETFD O_RDONLY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | my $RANDOM_FH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | sub _random_fh () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_random_fh: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | return $RANDOM_FH if $RANDOM_FH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | sysopen($RANDOM_FH, '/dev/urandom', O_RDONLY) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | or die "open /dev/urandom: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | my $flags = fcntl($RANDOM_FH, F_GETFD, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | die "fcntl(F_GETFD) /dev/urandom: $!" if !defined $flags; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | fcntl($RANDOM_FH, F_SETFD, $flags | FD_CLOEXEC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | or die "fcntl(F_SETFD) /dev/urandom: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | return $RANDOM_FH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub mask_key ($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask_key: not called CC=7 SCAR=37.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $fh = $RANDOM_FH // _random_fh(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$RANDOM_FH // _random_fh()
MC/DC0%0/2
$RANDOM_FH // _random_fh()
$RANDOM_FH
_random_fh()
Truth table0%0/3
A // B
A= $RANDOM_FHB= _random_fh()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | while (length($bytes) < 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $read = sysread($fh, $bytes, 4 - length($bytes), length($bytes)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | next if !defined($read) && $!{EINTR}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Branch: 1 branch
Condition0%0/3
not defined $read and $!{"EINTR"}
MC/DC0%0/2
not defined $read and $!{"EINTR"}
not defined $read
$!{"EINTR"}
Truth table0%0/3
not(A) and B
A= not defined $readB= $!{"EINTR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die "read /dev/urandom: $!" if !defined $read; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | die "read /dev/urandom: unexpected EOF" if $read == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | sub bytes ($class, $length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytes: called CC=10 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | croak 'bytes(): length must be a positive integer' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u or $length < 1
not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u
not defined $length or ref $length
MC/DC0%0/4
not defined $length or ref $length or not "$length" =~ /\A[0-9]+\z/u or $length < 1
not defined $length
ref $length
not "$length" =~ /\A[0-9]+\z/u
$length < 1
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $lengthB= ref $lengthC= not "$length" =~ /\A[0-9]+\z/uD= $length < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | if !defined($length) || ref($length) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | || "$length" !~ /\A[0-9]+\z/ || $length < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | my $fh = _random_fh(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | while (length($bytes) < $length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | my $read = sysread($fh, $bytes, $length - length($bytes), length($bytes)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | next if !defined($read) && $!{EINTR}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $read and $!{"EINTR"}
MC/DC0%0/2
not defined $read and $!{"EINTR"}
not defined $read
$!{"EINTR"}
Truth table33%1/3
not(A) and B
A= not defined $readB= $!{"EINTR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | die "read /dev/urandom: $!" if !defined $read; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | ▶ | die "read /dev/urandom: unexpected EOF" if $read == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||