Pandora/Cryptor.pm

filter: Statementstmt 100% 44 / 44 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 98.5% 67 / 68 CC 7 SCAR 7.6
CC
7
Cov
98%
encrypt
3.0
decrypt
3.0
new
2.0
CRAP 2.1
« Pandora/Partner/WindowsMobile.pm ↑ Summary Pandora/Partner/iOS.pm »
1 package WebService::Pandora::Cryptor;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Crypt::ECB;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ### constructor ###
10  
11 3 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12  
13 3 my $caller = shift;
14  
15 3 my $class = ref( $caller );
16 3 ▶ $class = $caller if ( !$class );
Branch: 1 branch
BranchTrueFalseTotal
unless $class 3 0 3
17  
18 3 my $self = {'encryption_key' => undef,
19 'decryption_key' => undef,
20 @_};
21  
22 3 bless( $self, $class );
23  
24 3 my $crypt = Crypt::ECB->new();
25  
26 3 $crypt->padding( 'standard' );
27 3 $crypt->cipher( 'Blowfish' );
28  
29 3 $self->{'crypt'} = $crypt;
30  
31 3 return $self;
32 }
33  
34 ### getters/setters ###
35  
36 8 ▶sub error {
Subroutine error: called CC=2 SCAR=6.9
Pod documented
37  
38 8 my ( $self, $error ) = @_;
39  
40 8 ▶ $self->{'error'} = $error if ( defined( $error ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 4 4 8
41  
42 8 return $self->{'error'};
43 }
44  
45 ### public methods ###
46  
47 3 ▶sub encrypt {
Subroutine encrypt: called CC=3 SCAR=11.0
Pod documented
48  
49 3 my ( $self, $data ) = @_;
50  
51 # make sure encryption_key defined
52 3 ▶ if ( !defined( $self->{'encryption_key'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"encryption_key"}) 1 2 3
53  
54 1 $self->error( 'An encryption_key must be provided to the constructor.' );
55 1 return;
56 }
57  
58 # make sure data to encrypt was given
59 2 ▶ if ( !defined( $data ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 1 1 2
60  
61 1 $self->error( 'A string of data to encrypt must be given.' );
62 1 return;
63 }
64  
65 # give the crypt object the encryption key
66 1 $self->{'crypt'}->key( $self->{'encryption_key'} );
67  
68 # return the hex-encrypted form
69 1 return $self->{'crypt'}->encrypt_hex( $data );
70 }
71  
72 3 ▶sub decrypt {
Subroutine decrypt: called CC=3 SCAR=11.0
Pod documented
73  
74 3 my ( $self, $data ) = @_;
75  
76 # make sure decryption_key defined
77 3 ▶ if ( !defined( $self->{'decryption_key'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"decryption_key"}) 1 2 3
78  
79 1 $self->error( 'A decryption_key must be provided to the constructor.' );
80 1 return;
81 }
82  
83 # make sure data to decrypt was given
84 2 ▶ if ( !defined( $data ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 1 1 2
85  
86 1 $self->error( 'A string of data to decrypt must be given.' );
87 1 return;
88 }
89  
90 # give the crypt object the decryption key
91 1 $self->{'crypt'}->key( $self->{'decryption_key'} );
92  
93 # return the hex-encrypted form
94 1 return $self->{'crypt'}->decrypt_hex( $data );
95 }
96  
97 4 1;
« Pandora/Partner/WindowsMobile.pm ↑ Summary Pandora/Partner/iOS.pm »