Session/ID/Urandom.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 85.7% 42 / 49 CC 3 SCAR 4.8
CC
3
Cov
89%
generate_id
3.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« Session/State/URI.pm ↑ Summary Session/Finalized.pm »
1 package HTTP::Session::ID::Urandom;
2 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Crypt::URandom ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 52 ▶sub generate_id {
Subroutine generate_id: called CC=3 SCAR=11.8
Pod undocumented
12 52 my ($class, $sid_length) = @_;
13 52 ▶ if ( !defined($sid_length) || $sid_length !~ /\A[1-9][0-9]*\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sid_length and $sid_length =~ /\A[1-9][0-9]*\z/) 0 52 52
Condition33%1/3
defined $sid_length and $sid_length =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
0052
MC/DC0%0/2
defined $sid_length and $sid_length =~ /\A[1-9][0-9]*\z/
defined $sid_length $sid_length =~ /\A[1-9][0-9]*\z/
Truth table33%1/3
A and B
A= defined $sid_lengthB= $sid_length =~ /\A[1-9][0-9]*\z/
ABresult
0X0
100
111
14 0 Carp::croak "sid_length must be a positive integer";
15 }
16 # bytes of CSPRNG input needed to yield at least $sid_length base64url chars
17 52 my $src_len = POSIX::ceil($sid_length * 3.0 / 4.0);
18 # Generate session id from a cryptographically secure source.
19 52 my $buf = Crypt::URandom::urandom($src_len);
20 52 my $result = MIME::Base64::encode_base64($buf, '');
21 52 $result =~ tr|+/=|\-_|d; # make it url safe
22 52 return substr($result, 0, $sid_length);
23 }
24  
25 19 1;
« Session/State/URI.pm ↑ Summary Session/Finalized.pm »