blib/lib/SagePay/XORForm.pm

filter: Statementstmt 39.5% 17 / 43 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 2 / 2 totaltotal 37.5% 24 / 64 CC 6 SCAR 18.7
CC
6
Cov
32%
_init
12.0
_simpleXor
12.0
sage_xor_string
6.0
CRAP 6.5
↑ Summary
1 package SagePay::XORForm;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.05';
12  
13  
14 ## * Constructor and methods....
15  
16 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
17 0 my $class = shift;
18 0 my $self = {};
19 0 bless $self, $class;
20 0 $self->_init(@_);
21 0 return $self;
22 }
23  
24 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
25 0 my $self = shift;
26 0 my (%part) = @_;
27
28 croak "Must have load the query string to encrypt"
29 0 ▶ unless defined $part{'query_string'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $part{"query_string"} 0 0 0
30
31 croak "Must have load the key with which to encrypt message"
32 0 ▶ unless defined $part{'key'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $part{"key"} 0 0 0
33
34 0 $self->{'query_string'} = $part{'query_string'};
35 0 $self->{'key'} = $part{'key'};
36 }
37  
38  
39 0 ▶sub sage_xor_string {
Subroutine sage_xor_string: not called CC=2 SCAR=17.9
Pod documented
40 0 my $self = shift;
41 0 my ($options) = @_;
42
43 0 my $ret = encode_base64($self->_simpleXor);
44 0 ▶ $ret =~ s/(\r|\n)//g if $options->{'strip_newlines'};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"strip_newlines"} 0 0 0
45 0 return $ret;
46
47 }
48  
49  
50
51 ## * -------------------------------------------------
52 ## * do the simple method to return an xor'd str
53 ##
54 0 ▶sub _simpleXor {
Subroutine _simpleXor: not called CC=3 SCAR=24.8
55 0 my $self = shift;
56
57 0 my $InString = $self->{'query_string'};
58 0 my $Key = $self->{'key'};
59
60 0 my @KeyList = ();
61 #Initialise out variable
62 0 my $output = "";
63
64 #Convert $Key into array of ASCII values
65 0 ▶ for(my $i = 0; $i < length($Key); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $Key) 0 0 0
66 0 $KeyList[$i] = ord(substr($Key, $i, 1));
67 }
68
69 # Step through string a character at a time
70 0 ▶ for(my $i = 0; $i < length($InString); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $InString) 0 0 0
71 # Get ASCII code from string, get ASCII code from key (loop through with MOD), XOR the two, get the character from the result
72 #% is MOD (modulus), ^ is XOR
73 0 $output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % length($Key)]));
74 }
75  
76 0 return $output;
77 }
78  
79  
80  
81 1 1;
82 __END__
↑ Summary