[BACK]Return to Keyring.pm CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / lib / Palm

Diff for /palm/Palm-Keyring/lib/Palm/Keyring.pm between version 1.19 and 1.22

version 1.19, 2007/01/31 04:17:15 version 1.22, 2007/02/01 01:56:11
Line 1 
Line 1 
 package Palm::Keyring;  package Palm::Keyring;
   
 # $RedRiver: Keyring.pm,v 1.18 2007/01/30 05:18:06 andrew Exp $  # $RedRiver: Keyring.pm,v 1.21 2007/01/31 05:32:20 andrew Exp $
 #  #
 # Perl class for dealing with Keyring for Palm OS databases.  # Perl class for dealing with Keyring for Palm OS databases.
 #  #
Line 90 
Line 90 
     my $rec0_id = $self->{'records'}->[0]->{'id'};      my $rec0_id = $self->{'records'}->[0]->{'id'};
   
     if ($rec->{'encrypted'} && ! $rec->{'id'} == $rec0_id) {      if ($rec->{'encrypted'} && ! $rec->{'id'} == $rec0_id) {
           if (! defined $rec->{'name'}) {
               $rec->{'name'} = $EMPTY;
           }
         $rec->{'data'} = join $NULL, $rec->{'name'}, $rec->{'encrypted'};          $rec->{'data'} = join $NULL, $rec->{'name'}, $rec->{'encrypted'};
         delete $rec->{'name'};          delete $rec->{'name'};
         delete $rec->{'encrypted'};          delete $rec->{'encrypted'};
Line 120 
Line 123 
         croak("Incorrect Password!\n");          croak("Incorrect Password!\n");
     }      }
   
     $self->{'digest'} ||= _calc_keys( $pass );      $self->{'digest'}   ||= _calc_keys( $pass );
   
     $data->{'account'}  ||= $EMPTY;      $data->{'account'}  ||= $EMPTY;
     $data->{'password'} ||= $EMPTY;      $data->{'password'} ||= $EMPTY;
     $data->{'notes'}    ||= $EMPTY;      $data->{'notes'}    ||= $EMPTY;
   
     my %Modified;      my $changed      = 0;
     my ($day, $month, $year) = (localtime)[3,4,5];      my $need_newdate = 0;
       my $acct = {};
       if ($rec->{'encrypted'}) {
           $acct = $self->Decrypt($rec, $pass);
           foreach my $key (keys %{ $data }) {
               next if $key eq 'lastchange';
               if ($data->{$key} ne $acct->{$key}) {
                   $changed = 1;
                   last;
               }
           }
           if ( exists $data->{'lastchange'} && exists $acct->{'lastchange'} && (
               $data->{'lastchange'}->{day}   != $acct->{'lastchange'}->{day}   ||
               $data->{'lastchange'}->{month} != $acct->{'lastchange'}->{month} ||
               $data->{'lastchange'}->{year}  != $acct->{'lastchange'}->{year}
           )) {
               $changed = 1;
               $need_newdate = 0;
           } else {
               $need_newdate = 1;
           }
   
       } else {
           $changed = 1;
       }
   
       # no need to re-encrypt if it has not changed.
       return 1 if ! $changed;
   
       my ($day, $month, $year);
   
       if ($data->{'lastchange'} && ! $need_newdate ) {
           $day   = $data->{'lastchange'}->{'day'}   || 1;
           $month = $data->{'lastchange'}->{'month'} || 0;
           $year  = $data->{'lastchange'}->{'year'}  || 0;
   
           # XXX Need to actually validate the above information somehow
           if ($year >= 1900) {
               $year -= 1900;
           }
       } else {
           $need_newdate = 1;
       }
   
       if ($need_newdate) {
           ($day, $month, $year) = (localtime)[3,4,5];
       }
     $year -= 4;      $year -= 4;
     $month++;      $month++;
   
   
     my $p = $day | ($month << 5) | ($year << 9);      my $p = $day | ($month << 5) | ($year << 9);
     my $packeddate = pack 'n', $p;      my $packeddate = pack 'n', $p;
   
Line 192 
Line 242 
     }      }
   
     return {      return {
         name     => $rec->{'name'},          name       => $rec->{'name'},
         account  => $account,          account    => $account,
         password => $password,          password   => $password,
         notes    => $notes,          notes      => $notes,
         date     => \%Modified,          lastchange => \%Modified,
     };      };
 }  }
   
Line 233 
Line 283 
   
         foreach my $i (0..$#accts) {          foreach my $i (0..$#accts) {
             next if $i == 0;              next if $i == 0;
               delete $self->{'records'}->[$i]->{'encrypted'};
             $self->Encrypt($self->{'records'}->[$i], $accts[$i], $pass);              $self->Encrypt($self->{'records'}->[$i], $accts[$i], $pass);
         }          }
     }      }
Line 453 
Line 504 
 $acct is a hashref in the format below.  $acct is a hashref in the format below.
   
     my $acct = {      my $acct = {
         account  => $account,          name       => $rec->{'name'},
         password => $password,          account    => $account,
         notes    => $notes,          password   => $password,
           notes      => $notes,
           lastchange => {
               year  => 107, # years since 1900
               month =>   0, # 0-11, 0 = January, 11 = December
               day   =>  30, # 1-31, same as localtime
           },
     };      };
   
   If you have changed anything other than the lastchange, or don't pass in a
   lastchange record, Encrypt() will generate a new lastchange for you.
   
   If you pass in a lastchange field that is different than the one in the
   record, it will honor what you passed in.
   
   It also only uses the $acct->{'name'} if there is not already a $rec->{'name'}.
   
 =head2 Decrypt  =head2 Decrypt
   
     my $acct = $pdb->Decrypt($rec[, $password]);      my $acct = $pdb->Decrypt($rec[, $password]);
   
 Decrypts the record and returns a hashref for the account as described  Decrypts the record and returns a hashref for the account as described
 under Encrypt();  under Encrypt().
   
     foreach (0..$#{ $pdb->{'records'}) {      foreach (0..$#{ $pdb->{'records'}) {
         next if $_ == 0;          next if $_ == 0;

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.22

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>