Lite/Nonce.pm

filter: Statementstmt 100% 47 / 47 Branchbran 88.8% 16 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 92.7% 77 / 83 CC 11 SCAR 12.3
CC
11
Cov
97%
check_timestamp
6.0
split_nonce
4.0
gen_nonce
2.0
CRAP 3.4
« Lite/RelyingParty/Discover/Method/XRI.pm ↑ Summary Lite/RelyingParty/Discover/Parser/Yadis.pm »
1 package OpenID::Lite::Nonce;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use String::Random;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 my $SKEW = 60 * 60 * 5;
11  
12 10 ▶sub gen_nonce {
Subroutine gen_nonce: called CC=2 SCAR=6.9
Pod undocumented
13 10 my $class = shift;
14 10 my $t = shift;
15 10 ▶ $t = time() unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 3 7 10
16 10 my $time = POSIX::strftime( q{%FT%TZ}, gmtime($t) );
17 10 my $random = String::Random->new;
18 10 my $salt = $random->randregex('[a-zA-Z0-9]{6}');
19 10 return $time . $salt;
20 }
21  
22 30 ▶sub split_nonce {
Subroutine split_nonce: called CC=4 SCAR=13.9
Pod undocumented
23 30 my $class = shift;
24 30 my $nonce = shift;
25 30 my $pos = length(q{0000-00-00T00:00:00Z});
26 30 my $timestamp = substr( $nonce, 0, $pos );
27 30 ▶ return if length($timestamp) < $pos;
Branch: 1 branch
BranchTrueFalseTotal
if length $timestamp < $pos 3 27 30
28 27 ▶ return unless $timestamp =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $timestamp =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/ 3 24 27
29 24 my $time;
30 24 eval { $time = Time::Local::timegm($6, $5, $4, $3, $2 - 1, $1); };
31 24 ▶ if ($@) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 23 24
32 23 my $rest = substr( $nonce, $pos );
33 23 return ( $time, $rest );
34 }
35  
36 27 ▶sub skew {
Subroutine skew: called CC=2 SCAR=6.9
Pod undocumented
37 27 my ( $class, $new_skew ) = @_;
38 27 ▶ $SKEW = $new_skew if $new_skew;
Branch: 1 branch
BranchTrueFalseTotal
if $new_skew 4 23 27
39 27 return $SKEW;
40 }
41  
42 8 ▶sub check_timestamp {
Subroutine check_timestamp: called CC=6 SCAR=18.0
Pod undocumented
43 8 my ( $class, $nonce_str, $allowed_skew, $now ) = @_;
44 8 ▶ $allowed_skew = $class->skew() unless defined $allowed_skew;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $allowed_skew 0 8 8
45 8 ▶ $now = time() unless defined $now;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $now 0 8 8
46 8 ▶ my ( $stamp, $foo ) = $class->split_nonce($nonce_str)
Branch: 1 branch
BranchTrueFalseTotal
() = $class->split_nonce($nonce_str) or return 0 7 1 8
47 or return 0;
48 7 my $past = $now - $allowed_skew;
49 7 my $future = $now + $allowed_skew;
50 7 ▶ return ( $past <= $stamp && $stamp <= $future ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$past <= $stamp && $stamp <= $future ? : 4 3 7
Condition100%3/3
$past <= $stamp and $stamp <= $future
!ll&&!rl&&r
214
MC/DC100%2/2
$past <= $stamp and $stamp <= $future
$past <= $stamp $stamp <= $future
Truth table100%3/3
A and B
A= $past <= $stampB= $stamp <= $future
ABresult
0X0
100
111
51 }
52  
53 3 1;
54  
« Lite/RelyingParty/Discover/Method/XRI.pm ↑ Summary Lite/RelyingParty/Discover/Parser/Yadis.pm »