Strip.pm untested

filter: Statementstmt 0.0% 0 / 103 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 144 CC 5 SCAR 12.2
CC
5
Cov
0%
set_password
6.0
get_accounts
6.0
set_directory
6.0
CRAP 3.4
1 package Palm::Zetetic::Strip;
2  
3 use strict;
4 use Palm::PDB;
5 use Palm::Zetetic::Strip::PDB::ParserFactory;
6  
7 require Exporter;
8  
9 use vars qw(@ISA $VERSION);
10  
11 @ISA = qw(Exporter);
12 $VERSION = "1.02";
13  
14 =head1 NAME
15  
16 Palm::Zetetic::Strip - Manipulate Zetetic Strip Palm database files
17  
18 =head1 SYNOPSIS
19  
20 use Palm::Zetetic::Strip;
21  
22 $strip = new Palm::Zetetic::Strip('directory_to_pdb_files/');
23 if (! $strip->set_password('strip_password'))
24 {
25 print "Incorrect password\n";
26 exit(1);
27 }
28  
29 $strip->load();
30 @systems = $strip->get_systems();
31 @accounts = $strip->get_accounts($systems[0]);
32  
33 =head1 DESCRIPTION
34  
35 The Palm::Zetetic::Strip module provides access to database files
36 generated by the Strip (Secuure Tool for Recalling Important
37 Passwords) from Zetetic.
38  
39 =head1 METHODS
40  
41 =head2 new
42  
43 $strip = new Palm::Zetetic::Strip($pdb_directory);
44  
45 Creates a new Palm::Zetetic::Strip object. The directory provided
46 must contain the .pdb files.
47  
48 =cut
49  
50 sub new
51 {
52 my $class = shift;
53 my $self = {};
54  
55 bless $self, $class;
56  
57 $self->{systems} = [];
58 $self->{accounts} = [];
59 $self->{password} = "";
60 $self->{directory} = "";
61 $self->{parser_factory} = new Palm::Zetetic::Strip::PDB::ParserFactory;
62  
63 return $self;
64 }
65  
66 =head2 set_password
67  
68 $success = set_password('plaintext password');
69  
70 Sets the password to unlock the databases. Return true if the
71 password is correct, otherwise false.
72  
73 =cut
74  
75 sub set_password
76 {
77 my ($self, $password) = @_;
78 if ($self->verify_password($password))
79 {
80 $self->{password} = $password;
81 return 1;
82 }
83 else
84 {
85 return 0;
86 }
87 }
88  
89 =head2 load
90  
91 $strip->load()
92  
93 Loads the system and accounts databases into memory.
94  
95 =cut
96  
97 sub load
98 {
99 my ($self) = @_;
100  
101 $self->load_systems();
102 $self->load_accounts();
103 }
104  
105 =head2 get_systems
106  
107 @systems = $strip->get_systems();
108  
109 Returns an array of Palm::Zetetic::Strip::System objects.
110  
111 =cut
112  
113 sub get_systems
114 {
115 my ($self) = @_;
116 my @systems;
117  
118 @systems = values(%{$self->{systems}});
119 @systems = sort {$a->get_name() cmp $b->get_name()} @systems;
120 return @systems;
121 }
122  
123 sub get_system_name
124 {
125 my ($self, $system_id) = @_;
126 my $system;
127  
128 $system = $self->{systems}->{$system_id};
129 return $system->get_name();
130 }
131  
132 =head2 get_accounts
133  
134 @accounts = $strip->get_accounts();
135  
136 Returns an array of Palm::Zetetic::Strip::Account objects.
137  
138 =cut
139  
140 sub get_accounts
141 {
142 my ($self, $system) = @_;
143 my $accounts;
144  
145 $accounts = $self->{accounts}->{$system->get_id()};
146 $accounts = [] if (! defined($accounts));
147 return @$accounts;
148 }
149  
150 #
151 # All private methods go here
152 #
153  
154 sub verify_password
155 {
156 my ($self, $password) = @_;
157 my $password_pdb_file;
158 my $password_pdb_parser;
159  
160 $password_pdb_file = $self->get_password_pdb_file();
161 $password_pdb_parser = $self->{parser_factory}->get_password_parser();
162 $password_pdb_parser->load($password_pdb_file);
163 return $password_pdb_parser->verify_password($password);
164 }
165  
166 sub get_strip_version
167 {
168 my ($self) = @_;
169 return $self->{parser_factory}->get_strip_version();
170 }
171  
172 sub set_directory
173 {
174 my ($self, $directory, $version) = @_;
175 my $parser_factory;
176  
177 $parser_factory = $self->{parser_factory};
178 if (defined $version)
179 {
180 $parser_factory->set_strip_version($version);
181 }
182 else
183 {
184 $parser_factory->set_strip_version_autodetect($directory);
185 }
186  
187 $self->{directory} = $directory;
188 }
189  
190 sub get_password_pdb_file
191 {
192 my ($self) = @_;
193 return $self->{directory} . "/StripPassword-SJLO.pdb";
194 }
195  
196 sub get_systems_pdb_file
197 {
198 my ($self) = @_;
199 return $self->{directory} . "/StripSystems-SJLO.pdb";
200 }
201  
202 sub get_accounts_pdb_file
203 {
204 my ($self) = @_;
205 return $self->{directory} . "/StripAccounts-SJLO.pdb";
206 }
207  
208 sub load_systems
209 {
210 my ($self) = @_;
211 my $systems_pdb_file;
212 my $systems_pdb_parser;
213 my $systems;
214 my $system;
215  
216 $systems_pdb_file = $self->get_systems_pdb_file();
217 $systems_pdb_parser = $self->{parser_factory}->get_systems_parser();
218 $systems_pdb_parser->load($systems_pdb_file);
219 $self->{systems} = {};
220 $systems = $systems_pdb_parser->get_systems($self->{password});
221  
222 foreach $system (@$systems)
223 {
224 $self->{systems}->{$system->get_id()} = $system;
225 }
226  
227 return;
228 }
229  
230 sub load_accounts
231 {
232 my ($self) = @_;
233 my $accounts_pdb_file;
234 my $accounts_pdb_parser;
235 my $accounts;
236 my $account;
237 my $system_accounts;
238  
239 $accounts_pdb_file = $self->get_accounts_pdb_file();
240 $accounts_pdb_parser = $self->{parser_factory}->get_accounts_parser();
241 $accounts_pdb_parser->load($accounts_pdb_file);
242 $self->{accounts} = {};
243 $accounts = $accounts_pdb_parser->get_accounts($self->{password});
244  
245 foreach $account (@$accounts)
246 {
247 if (! defined($self->{accounts}->{$account->get_system_id()}))
248 {
249 $self->{accounts}->{$account->get_system_id()} = [];
250 }
251 $system_accounts = $self->{accounts}->{$account->get_system_id()};
252 push(@$system_accounts, $account);
253 }
254  
255 return;
256 }
257  
258 1;
259  
260 __END__