| 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
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my $size = $params{Size}; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $skip = $params{Skip} || $$self{Skip} || ''; | ||||||||||||||||||||||||||
|
Condition0%0/5
$params{'Skip'} || $self->{'Skip'} || ''
$params{"Skip"} or $self->{"Skip"}
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"}
| |||||||||||||||||||||||||||||
| 31 | 0 | my $q_skip = quotemeta($skip); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($size && ref $size eq "Math::Pari") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$size and ref $size eq "Math::Pari"
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"
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 38 | 0 | my $source; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (eval { require Win32::API }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $genrand = Win32::API->new('advapi32', 'INT SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength)') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $bytes or $bytes =~ /\D/
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/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 59 | 0 | $rt = &$source($bytes - $read); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | $rt =~ s/[$q_skip]//g if $skip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||
| 73 | 5 | return 0; | |||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | 1; | |||||||||||||||||||||||||||