blib/lib/PerlIO/via/CBC.pm

filter: Statementstmt 68.7% 44 / 64 Branchbran 53.8% 14 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 81.8% 9 / 11 Podpod 100% 4 / 4 totaltotal 63.4% 73 / 115 CC 16 SCAR 21.2
CC
16
Cov
62%
READ
30.0
PUSHED
5.5
FLUSH
4.2
CRAP 8.4
↑ Summary
1 package PerlIO::via::CBC;
2
3 2 ▶use strict vars;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 2 ▶use Crypt::CBC ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 $VERSION = '0.08';
10
11 2 my $Config = {};
12
13 1 ▶sub config {
Subroutine config: called CC=2 SCAR=7.4
Pod documented
14 1 my ($class, %args) = @_;
15 1 ▶ if(%args) {
Branch: 1 branch
BranchTrueFalseTotal
if (%args) { } 1 0 1
16 1 $Config = {%args};
17 } else {
18 0 $Config = {};
19 }
20 1 return $Config;
21 }
22
23 2 ▶sub PUSHED {
Subroutine PUSHED: called CC=5 SCAR=17.1
Pod documented
24 2 ▶ return -1 if $_[1] ne 'r' and $_[1] ne 'w';
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] ne "r" and $_[1] ne "w" 0 2 2
Condition66%2/3
$_[1] ne "r" and $_[1] ne "w"
!ll&&!rl&&r
110
MC/DC0%0/2
$_[1] ne "r" and $_[1] ne "w"
$_[1] ne "r" $_[1] ne "w"
Truth table66%2/3
A and B
A= $_[1] ne "r"B= $_[1] ne "w"
ABresult
0X0
100
111
25
26 2 my $cbc = Crypt::CBC->new($Config);
27 2 ▶ unless($cbc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cbc) 0 2 2
28 0 require Carp;
29 0 Carp::croak("Couldn't create CBC object");
30 }
31
32 2 ▶ if($_[1] eq 'r') { # open for reading: decrypt the data
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq 'r') { } 1 1 2
33 1 $cbc->start('decrypting');
34 } else { # open for writing: encrypt the data
35 1 $cbc->start('encrypting');
36 }
37
38 2 return (bless [$cbc, '', $_[1]], $_[0]);
39 }
40
41 3 ▶sub FILL {
Subroutine FILL: called CC=3 SCAR=11.0
Pod documented
42 3 my ($self, $fh) = @_;
43
44 # Read the line from the handle
45 3 my $line = readline($fh);
46
47 3 my $cbc = $self->[0];
48
49 # If there is something to be crypted, crypt it
50 3 ▶ if(defined $line) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $line) { } 1 2 3
elsif ($cbc) { } 1 1 2
51 1 return ($cbc->crypt($line));
52
53 # elsif we still have an object (and end of data reached)
54 # Remove the object from PerlIO::via::Crypt object (so we'll really exit next)
55 # and finish crypting
56 } elsif($cbc) {
57 1 $self->[0] = '';
58 1 return ($cbc->finish());
59
60 # else (end of data really reached)
61 # return signalling end of data reached
62 } else {
63 1 return (undef);
64 }
65 }
66
67 0 ▶sub BINMODE {
Subroutine BINMODE: not called CC=1 SCAR=6.9
68 0 return (0);
69 }
70
71 0 ▶sub READ {
Subroutine READ: not called CC=5 SCAR=34.0
72 0 my ($self, $buffer, $len, $fh) = @_;
73
74 # Read $len bytes from $fh into $buffer
75 0 my $ret = read $fh, $buffer, $len;
76
77 # On Error return undef
78 0 ▶ return $ret unless defined $ret;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret 0 0 0
79
80 0 my $cbc = $self->[0];
81
82 # If there is something to be crypted, crypt it
83 0 ▶ if($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) { } 0 0 0
84 0 $buffer = $cbc->crypt($buffer);
85
86 # elsif we still have an object (and end of data reached)
87 # Remove the object from PerlIO::via::Crypt object (so we'll really exit next)
88 # and finish crypting
89 } else {
90 0 $self->[0] = '';
91 0 $buffer = $cbc->finish();
92 }
93 0 $self->[1] = '';
94
95 # calc length
96 0 $ret = length $buffer;
97
98 # buffer is greater than required, shorten it but remember it
99 0 ▶ if($ret > $len and $self->[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($ret > $len and $self->[0]) 0 0 0
Condition0%0/3
$ret > $len and $self->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$ret > $len and $self->[0]
$ret > $len $self->[0]
Truth table0%0/3
A and B
A= $ret > $lenB= $self->[0]
ABresult
0X0
100
111
100 {
101 0 $self->[1] = substr($buffer, $len);
102 0 $buffer = substr(0, $len);
103 0 $ret = $len;
104 }
105
106 # return length of data (hopefully always less equal than $len)
107 0 return $ret;
108 }
109
110 1 ▶sub WRITE {
Subroutine WRITE: called CC=2 SCAR=7.0
111 1 my ($self, $buffer, $fh) = @_;
112
113 1 my $buf = $self->[0]->crypt($buffer);
114 1 ▶ return ((print {$fh} $buf) ? length ($buf) : -1);
Branch: 1 branch
BranchTrueFalseTotal
print({$fh;} $buf) ? : 1 0 1
115 }
116
117 2 ▶sub FLUSH {
Subroutine FLUSH: called CC=4 SCAR=14.3
Pod documented
118 2 my ($self, $fh) = @_;
119
120 2 ▶ return 0 if $self->[2] eq 'r';
Branch: 1 branch
BranchTrueFalseTotal
if $self->[2] eq "r" 1 1 2
121
122 1 my $buf = $self->[0]->finish();
123 1 ▶ if($buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf) 1 0 1
124 1 ▶ return ((print {$fh} $buf) ? 0 : -1);
Branch: 1 branch
BranchTrueFalseTotal
print({$fh;} $buf) ? : 1 0 1
125 }
126
127 0 return (0);
128 }
129
130 2 1;
131 __END__
↑ Summary