Session/Generate/SHA256.pm

filter: Statementstmt 87.5% 21 / 24 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 81.0% 30 / 37 CC 4 SCAR 7.8
CC
4
Cov
83%
generate
3.5
validate
2.0
BEGIN
1.0
CRAP 2.2
« Session/Store/File.pm ↑ Summary Session/Cassandra.pm »
1 # Directly copied from LemonLDAP::NG project (http://lemonldap-ng.org/)
2 package Web::Session::Generate::SHA256;
3  
4 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 34 ▶use Crypt::URandom;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 34 $VERSION = '1.0.0';
9  
10 140 ▶sub generate {
Subroutine generate: called CC=3 SCAR=12.6
Pod undocumented
11 140 my $session = shift;
12 140 my $length = 64;
13  
14 140 ▶ if ( exists $session->{args}->{IDLength} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $session->{"args"}{"IDLength"}) 0 140 140
15 0 $length = $session->{args}->{IDLength};
16 }
17  
18 140 eval {
19 140 $session->{data}->{_session_id} = substr(
20 unpack( 'H*', Crypt::URandom::urandom( int( ( $length + 1 ) / 2 ) ) ),
21 0, $length
22 );
23 };
24 140 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 140 140
25 0 require Digest::SHA;
26 0 $session->{data}->{_session_id} = substr(
27 Digest::SHA::sha256_hex(
28 Digest::SHA::sha256_hex( time() . {} . rand() . $$ )
29 ),
30 0, $length
31 );
32 }
33 }
34  
35 83 ▶sub validate {
Subroutine validate: called CC=2 SCAR=6.9
Pod undocumented
36  
37 #This routine checks to ensure that the session ID is in the form
38 #we expect. This must be called before we start diddling around
39 #in the database or the disk.
40  
41 83 my $session = shift;
42  
43 83 ▶ if ( $session->{data}->{_session_id} =~ /^([a-fA-F0-9]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session->{'data'}{'_session_id'} =~ /^([a-fA-F0-9]+)$/) { } 82 1 83
44 82 $session->{data}->{_session_id} = $1;
45 }
46 else {
47 1 die "Invalid session ID: " . $session->{data}->{_session_id};
48 }
49 }
50  
51 34 1;
« Session/Store/File.pm ↑ Summary Session/Cassandra.pm »