Random/Provider/Win32API.pm

filter: Statementstmt 35.4% 17 / 48 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 3 totaltotal 22.7% 23 / 101 CC 16 SCAR 42.5
CC
16
Cov
22%
get_data
132.0
__ANON__
30.0
available
2.1
CRAP 70.1
« Random/Provider/egd.pm ↑ Summary Random/Provider/File.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 ## The WIN32API implementation below is based on code written by
6 ## Leon Timmermans (Leont) as implemented here by Timothy Legge (timlegge)
7  
8 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 package Crypt::Random::Provider::Win32API;
11 3 ▶use Math::Pari qw(pari2num);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Crypt::URandom qw/urandom/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 our $VERSION = '1.57';
15  
16 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
17  
18 0 my ($class, %params) = @_;
19 0 my $self = { Source => $params{Source} };
20 0 return bless $self, $class;
21  
22 }
23  
24 0 ▶sub get_data {
Subroutine get_data: not called CC=11 SCAR=48.8
Pod undocumented
25  
26 0 my ($self, %params) = @_;
27 0 ▶ $self = {} unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
28  
29 0 my $size = $params{Size};
30 0 ▶ my $skip = $params{Skip} || $$self{Skip} || '';
Condition0%0/5
$params{'Skip'} || $self->{'Skip'} || ''
l!l
00
$params{"Skip"} or $self->{"Skip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'Skip'} || $self->{'Skip'} || ''
$params{"Skip"} $self->{"Skip"}
Truth table0%0/3
A or B
A= $params{"Skip"}B= $self->{"Skip"}
ABresult
1X1
011
000
31 0 my $q_skip = quotemeta($skip);
32  
33 0 ▶ if ($size && ref $size eq "Math::Pari") {
Branch: 1 branch
BranchTrueFalseTotal
if ($size and ref $size eq "Math::Pari") 0 0 0
Condition0%0/3
$size and ref $size eq "Math::Pari"
!ll&&!rl&&r
000
MC/DC0%0/2
$size and ref $size eq "Math::Pari"
$size ref $size eq "Math::Pari"
Truth table0%0/3
A and B
A= $sizeB= ref $size eq "Math::Pari"
ABresult
0X0
100
111
34 0 $size = pari2num($size);
35 }
36  
37 0 ▶ my $bytes = $params{Length} || (int($size / 8) + 1);
Condition0%0/3
$params{'Length'} || int($size / 8) + 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'Length'} || int($size / 8) + 1
$params{'Length'} int($size / 8) + 1
Truth table0%0/3
A || B
A= $params{'Length'}B= int($size / 8) + 1
ABresult
1X1
011
000
38 0 my $source;
39  
40 0 ▶ if (eval { require Win32::API }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Win32::API } }) { } 0 0 0
41 0 ▶ my $genrand = Win32::API->new('advapi32', 'INT SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength)')
Branch: 1 branch
BranchTrueFalseTotal
my $genrand = "Win32::API"->new("advapi32", "INT SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength)") or Carp::croak("Could not import SystemFunction036: $^E") 0 0 0
42 or Carp::croak("Could not import SystemFunction036: $^E");
43  
44 0 ▶ $source = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
45 0 my ($count) = @_;
46 0 ▶ return '' if $count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count == 0 0 0 0
47 0 ▶ Carp::croak('The Length argument must be supplied and must be an integer') if not defined $bytes or $bytes =~ /\D/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes or $bytes =~ /\D/ 0 0 0
Condition0%0/3
not defined $bytes or $bytes =~ /\D/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $bytes or $bytes =~ /\D/
not defined $bytes $bytes =~ /\D/
Truth table0%0/3
not(A) or B
A= not defined $bytesB= $bytes =~ /\D/
ABresult
1X1
011
000
48 0 my $buffer = chr(0) x $count;
49 0 ▶ $genrand->Call($buffer, $count) or Carp::croak("Could not read random data");
Branch: 1 branch
BranchTrueFalseTotal
$genrand->Call($buffer, $count) or Carp::croak("Could not read random data") 0 0 0
50 0 return $buffer;
51 0 };
52 }
53 else {
54 0 Carp::croak('Win32::API is required');
55 }
56  
57 0 my($r, $read, $rt) = ('', 0);
58 0 ▶ while ($read < $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read < $bytes) 0 0 0
59 0 $rt = &$source($bytes - $read);
60 0 ▶ $rt =~ s/[$q_skip]//g if $skip;
Branch: 1 branch
BranchTrueFalseTotal
if $skip 0 0 0
61 0 $r .= $rt;
62 0 $read = length $r;
63 }
64  
65 0 $r;
66 }
67  
68  
69 5 ▶sub available {
Subroutine available: called CC=2 SCAR=7.6
Pod undocumented
70 5 ▶ if (eval { require Win32::API }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Win32::API } }) { } 0 5 5
71 0 return 1;
72 } else {
73 5 return 0;
74 };
75 }
76  
77 3 1;
« Random/Provider/egd.pm ↑ Summary Random/Provider/File.pm »