PIN.pm

filter: Statementstmt 27.0% 20 / 74 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 4 totaltotal 17.4% 26 / 149 CC 26 SCAR 51.9
CC
26
Cov
16%
pin
306.0
new
110.0
set
2.0
CRAP 180.3
↑ Summary sample.pl »
1 package Authen::PIN;
2
3 1 ▶use Digest::MD5 qw(md5);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Business::CreditCard;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Number::Encode qw(uniform);
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 1 our $VERSION = '1.10';
12
13 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod undocumented
14 0 my $type = shift;
15 0 ▶ my $class = ref($type) || $type || "Authen::PIN";
Condition0%0/5
ref $type || $type || 'Authen::PIN'
l!l
00
ref $type or $type
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $type || $type || 'Authen::PIN'
ref $type $type
Truth table0%0/3
A or B
A= ref $typeB= $type
ABresult
1X1
011
000
16
17 0 my $template = uc shift;
18 0 my $start = shift;
19
20 0 ▶ $start = 0 unless $start;
Branch: 1 branch
BranchTrueFalseTotal
unless $start 0 0 0
21
22 0 ▶ croak "Template contains unrecognized characters or is invalid"
Branch: 1 branch
BranchTrueFalseTotal
unless $template =~ /^[0-9PCHV]+$/ 0 0 0
23 unless $template =~ /^[0-9PCHV]+$/;
24
25 0 my $self = {
26 template => [ split(//, $template) ],
27 start => $start,
28 inc => 1,
29 count => $start,
30 p => 0,
31 c => 0,
32 h => 0,
33 v => 0,
34 };
35
36 0 for my $d (@{$self->{template}}) {
37 0 ▶ if ($d eq 'P') { $self->{p} ++; }
Branch: 4 branches
BranchTrueFalseTotal
if ($d eq 'P') { } 0 0 0
elsif ($d eq 'C') { } 0 0 0
elsif ($d eq 'H') { } 0 0 0
elsif ($d eq 'V') { } 0 0 0
38 0 elsif ($d eq 'C') {$self->{c} ++; }
39 0 elsif ($d eq 'H') {$self->{h} ++; }
40 0 elsif ($d eq 'V') {$self->{v} ++; }
41 }
42
43 0 bless $self, $class;
44 }
45
46 0 ▶sub set {
Subroutine set: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my $self = shift;
48 0 my $start = shift;
49
50 0 $self->{start} = $start;
51 }
52
53 0 ▶sub inc {
Subroutine inc: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my $self = shift;
55 0 my $inc = shift;
56
57 0 $self->{inc} = $inc;
58 }
59
60 0 ▶sub pin {
Subroutine pin: not called CC=17 SCAR=57.2
Pod undocumented
61 0 my $self = shift;
62
63 0 my $pas = undef;
64 0 my $ser = undef;
65 0 my $cnt = undef;
66 0 my $hsh = undef;
67 0 my $ret = undef;
68
69 0 my $pas_c = 0;
70 0 my $cnt_c = 0;
71 0 my $hsh_c = 0;
72
73 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
74 0 $ser = shift;
75 }
76 else {
77 0 $pas = shift;
78 0 $ser = join('', @_);
79 }
80
81 carp("Pass-through not defined in template")
82 0 ▶ if ($pas and not $self->{p});
Branch: 1 branch
BranchTrueFalseTotal
if $pas and not $self->{"p"} 0 0 0
Condition0%0/3
$pas and not $self->{"p"}
!ll&&!rl&&r
000
MC/DC0%0/2
$pas and not $self->{"p"}
$pas not $self->{"p"}
Truth table0%0/3
A and not(B)
A= $pasB= not $self->{"p"}
ABresult
0X0
100
111
83
84 0 ▶ if ($self->{c} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"c"} > 0) 0 0 0
85 0 $cnt = $self->{count};
86 0 $self->{count} += $self->{inc};
87 }
88
89 0 $hsh = uniform(md5($pas . $ser));
90
91 0 ▶ if (defined $pas and length($pas) < $self->{p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pas and length $pas < $self->{"p"}) 0 0 0
Condition0%0/3
defined $pas and length $pas < $self->{"p"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pas and length $pas < $self->{"p"}
defined $pas length $pas < $self->{"p"}
Truth table0%0/3
A and B
A= defined $pasB= length $pas < $self->{"p"}
ABresult
0X0
100
111
92 0 $pas = (0 x ($self->{p} - length($pas))) . $pas;
93 }
94
95 0 ▶ if (defined $cnt and length($cnt) < $self->{c}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cnt and length $cnt < $self->{"c"}) 0 0 0
Condition0%0/3
defined $cnt and length $cnt < $self->{"c"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cnt and length $cnt < $self->{"c"}
defined $cnt length $cnt < $self->{"c"}
Truth table0%0/3
A and B
A= defined $cntB= length $cnt < $self->{"c"}
ABresult
0X0
100
111
96 0 $cnt = (0 x ($self->{c} - length($cnt))) . $cnt;
97 }
98
99 0 ▶ if (defined $hsh and length($hsh) < $self->{h}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hsh and length $hsh < $self->{"h"}) 0 0 0
Condition0%0/3
defined $hsh and length $hsh < $self->{"h"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hsh and length $hsh < $self->{"h"}
defined $hsh length $hsh < $self->{"h"}
Truth table0%0/3
A and B
A= defined $hshB= length $hsh < $self->{"h"}
ABresult
0X0
100
111
100 0 $hsh = (0 x ($self->{h} - length($hsh))) . $hsh;
101 }
102
103 0 for my $t (@{$self->{template}}) {
104 0 ▶ if ($t =~ /[0-9]/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($t =~ /[0-9]/) { } 0 0 0
elsif ($t eq 'P') { } 0 0 0
elsif ($t eq 'C') { } 0 0 0
elsif ($t eq 'H') { } 0 0 0
elsif ($t eq 'V') { } 0 0 0
105 0 $ret .= $t;
106 }
107 elsif ($t eq 'P') {
108 0 $ret .= substr($pas, $pas_c ++, 1);
109 }
110 elsif ($t eq 'C') {
111 0 $ret .= substr($cnt, $cnt_c ++, 1);
112 }
113 elsif ($t eq 'H') {
114 0 $ret .= substr($hsh, $hsh_c ++, 1);
115 }
116 elsif ($t eq 'V') {
117 0 $ret .= generate_last_digit($ret);
118 }
119 }
120
121 0 return $ret;
122 }
123
124
125 1 1;
126 __END__
↑ Summary sample.pl »