=================================================================== RCS file: /cvs/palm/Palm-Keyring/lib/Palm/Keyring.pm,v retrieving revision 1.57 retrieving revision 1.60 diff -u -r1.57 -r1.60 --- palm/Palm-Keyring/lib/Palm/Keyring.pm 2008/09/19 03:04:34 1.57 +++ palm/Palm-Keyring/lib/Palm/Keyring.pm 2008/09/19 06:53:08 1.60 @@ -1,5 +1,5 @@ package Palm::Keyring; -# $RedRiver: Keyring.pm,v 1.56 2008/09/18 06:04:55 andrew Exp $ +# $RedRiver: Keyring.pm,v 1.59 2008/09/19 05:39:07 andrew Exp $ ######################################################################## # Keyring.pm *** Perl class for Keyring for Palm OS databases. # @@ -292,10 +292,6 @@ my $self = shift; my $rec = shift; - if (!defined $rec->{encrypted}) { - $rec->{encrypted} = $EMPTY; - } - if ($self->{version} == 4) { if ($rec->{encrypted}) { my $name = $rec->{plaintext}->{0}->{data} || $EMPTY; @@ -303,9 +299,8 @@ } } elsif ($self->{version} == 5) { - if (!$rec->{ivec}) { - $rec->{ivec} = $EMPTY; - } + croak 'No encrypted data in record' if !defined $rec->{encrypted}; + croak 'No ivec!' if !$rec->{ivec}; my $field; if ($rec->{plaintext}->{0}) { @@ -329,6 +324,8 @@ delete $rec->{plaintext}; delete $rec->{encrypted}; + croak 'No data in record to pack' if !$rec->{data}; + return $self->SUPER::PackRecord($rec, @_); } @@ -355,7 +352,7 @@ # Nothing extra for version 4 } elsif ($self->{version} == 5) { - _parse_appinfo_v5($appinfo) || return; + _parse_appinfo_v5($appinfo); } else { croak "Unsupported Version $self->{version}"; @@ -368,10 +365,7 @@ { my $appinfo = shift; - if (! exists $appinfo->{other}) { - # XXX Corrupt appinfo? - return; - } + croak 'Corrupt appinfo? no {other}' if ! $appinfo->{other}; my $unpackstr = ("C1" x 8) # 8 uint8s in an array for the salt @@ -440,23 +434,25 @@ my $self = shift; my $rec = shift; my $pass = shift || $self->{password}; + + if ( !$rec ) { + croak('Needed parameter [record] not passed!'); + } + my $data = shift || $rec->{plaintext}; my $ivec = shift; + if ( ! $pass && ! $self->{appinfo}->{key}) { - croak("password not set!\n"); + croak('password not set!'); } - if ( ! $rec) { - croak("Needed parameter 'record' not passed!\n"); - } - if ( ! $data) { - croak("Needed 'plaintext' not passed!\n"); + croak('Needed parameter [plaintext] not passed!'); } if ( $pass && ! $self->Password($pass)) { - croak("Incorrect Password!\n"); + croak('Incorrect Password!'); } my $acct; @@ -495,7 +491,7 @@ } } else { - croak "Unsupported Version $self->{version}"; + croak "Unsupported version $self->{version}"; } $rec->{plaintext}->{0} = $data->{0}; @@ -595,7 +591,9 @@ my $c = crypts($cipher) or croak('Unknown cipher ' . $cipher); if (! defined $ivec) { - $ivec = pack("C*",map {rand(256)} 1..$c->{blocksize}); + while (! $ivec) { + $ivec = pack("C*",map {rand(256)} 1..$c->{blocksize}); + } } my $changed = 0; @@ -625,7 +623,7 @@ } } - return 1, 0 if $changed == 0; + return (1, $ivec) if $changed == 0; if ($need_newdate) { my ($day, $month, $year) = (localtime)[3,4,5];