Random/Provider/egd.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 7.6% 2 / 26 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 3 totaltotal 25.7% 33 / 128 CC 22 SCAR 48.3
CC
22
Cov
25%
get_data
240.0
new
30.0
_defaultsource
3.5
CRAP 125.6
↑ Summary Random/Provider/Win32API.pm »
1 ##
2 ## Copyright (c) 1998-2025, Vipul Ved Prakash. All rights reserved.
3 ## This code is free software; you can redistribute it and/or modify
4 ## it under the same terms as Perl itself.
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 package Crypt::Random::Provider::egd;
9  
10 3 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Math::Pari qw(pari2num);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 our $VERSION = '1.57';
15  
16 5 ▶sub _defaultsource {
Subroutine _defaultsource: called CC=3 SCAR=12.5
17  
18 5 my $source;
19 5 for my $d (qw( /var/run/egd-pool /dev/egd-pool /etc/entropy )) {
20 0 ▶ if (IO::Socket::UNIX->new(Peer => $d)) { $source = $d; last }
Branch: 1 branch
BranchTrueFalseTotal
if ("IO::Socket::UNIX"->new("Peer", $d)) 0 15 15
21 }
22 5 return $source;
23  
24 }
25  
26  
27 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
28  
29 0 my ($class, %args) = @_;
30 0 ▶ my $self = { Source => $args{Source} || $args{Device} || $args{Filename} };
Condition0%0/6
$args{'Source'} || $args{'Device'} || $args{'Filename'}
l!l&&r!l&&!r
000
$args{"Source"} or $args{"Device"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{'Source'} || $args{'Device'} || $args{'Filename'}
$args{"Source"} $args{"Device"} $args{'Filename'}
Truth table0%0/4
A or B || C
A= $args{"Source"}B= $args{"Device"}C= $args{'Filename'}
ABCresult
1XX1
01X1
0011
0000
31 0 ▶ $$self{Source} = $class->_defaultsource() unless $$self{Source};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Source"} 0 0 0
32 0 ▶ croak "egd entropy pool file not found.\n" unless $$self{Source};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Source"} 0 0 0
33 0 return bless $self, $class;
34  
35 }
36  
37  
38 0 ▶sub get_data {
Subroutine get_data: not called CC=15 SCAR=54.8
Pod undocumented
39
40 0 my ( $self, %params ) = @_;
41 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
42 0 ▶ $self = {} unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
43
44 my $bytes = $params{Length} ||
45 0 ▶ (int( pari2num($params{ Size }) / 8) + 1);
Condition0%0/3
$params{'Length'} || int(&pari2num($params{'Size'}) / 8) + 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'Length'} || int(&pari2num($params{'Size'}) / 8) + 1
$params{'Length'} int(&pari2num($params{'Size'}) / 8) + 1
Truth table0%0/3
A || B
A= $params{'Length'}B= int(&pari2num($params{'Size'}) / 8) + 1
ABresult
1X1
011
000
46 0 ▶ my $dev = $params{Source} || $$self{Source};
Condition0%0/3
$params{'Source'} || $self->{'Source'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'Source'} || $self->{'Source'}
$params{'Source'} $self->{'Source'}
Truth table0%0/3
A || B
A= $params{'Source'}B= $self->{'Source'}
ABresult
1X1
011
000
47 0 my $skip = $params{Skip};
48  
49 0 ▶ croak "$dev doesn't exist. aborting." unless $dev && -e $dev;
Branch: 1 branch
BranchTrueFalseTotal
unless $dev and -e $dev 0 0 0
Condition0%0/3
$dev and -e $dev
!ll&&!rl&&r
000
MC/DC0%0/2
$dev and -e $dev
$dev -e $dev
Truth table0%0/3
A and B
A= $devB= -e $dev
ABresult
0X0
100
111
50  
51 0 my $s = IO::Socket::UNIX->new(Peer => $dev);
52 0 ▶ croak "couldn't talk to egd. $!" unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 0 0
53  
54 0 my($r, $read) = ('', 0);
55 0 ▶ while ($read < $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read < $bytes) 0 0 0
56 0 my $msg = pack "CC", 0x01, 1;
57 0 $s->syswrite($msg, length $msg);
58 0 my $rt;
59 0 my $nread = $s->sysread($rt, 1);
60 0 ▶ croak "read from entropy socket failed" unless $nread == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $nread == 1 0 0 0
61 0 my $count = unpack("C", $rt);
62 0 $nread = $s->sysread($rt, $count);
63 0 ▶ croak "couldn't get all the requested entropy. aborting."
Branch: 1 branch
BranchTrueFalseTotal
unless $nread == $count 0 0 0
64 unless $nread == $count;
65 0 ▶ unless ($skip && $skip =~ /\Q$rt\E/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($skip and $skip =~ /\Q$rt\E/) 0 0 0
Condition0%0/3
$skip and $skip =~ /\Q$rt\E/
!ll&&!rl&&r
000
MC/DC0%0/2
$skip and $skip =~ /\Q$rt\E/
$skip $skip =~ /\Q$rt\E/
Truth table0%0/3
A and B
A= $skipB= $skip =~ /\Q$rt\E/
ABresult
0X0
100
111
66 0 ▶ if ($params{Verbosity}) { print '.' unless $read % 2 }
Branch: 2 branches
BranchTrueFalseTotal
if ($params{"Verbosity"}) 0 0 0
unless $read % 2 0 0 0
67 0 $r .= $rt;
68 0 $read++;
69 }
70 }
71  
72 0 $r;
73 }
74  
75  
76 5 ▶sub available {
Subroutine available: called CC=2 SCAR=7.1
Pod undocumented
77
78 5 my $class = shift;
79 5 ▶ return 1 if $class->_defaultsource();
Branch: 1 branch
BranchTrueFalseTotal
if $class->_defaultsource 0 5 5
80 5 return;
81  
82 }
83  
84  
85 3 1;
86  
87  
↑ Summary Random/Provider/Win32API.pm »