diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-04-03 16:54:40 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-04-03 16:54:40 +0200 |
commit | 3f2a49b697a6eb5ff8db78c05c65070b46bb75a6 (patch) | |
tree | 3c8597bbd372ec704d96c28f31935a6c733acfcd /lib | |
parent | c9b94ac51383501ea80e0485cba4f891dbcce3fa (diff) |
Use confess instead of return undef, Test::Exception for App::Raps2::Password test
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/Raps2.pm | 11 | ||||
-rw-r--r-- | lib/App/Raps2/Password.pm | 12 | ||||
-rw-r--r-- | lib/App/Raps2/UI.pm | 3 |
3 files changed, 12 insertions, 14 deletions
diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm index 4746e5a..8078653 100644 --- a/lib/App/Raps2.pm +++ b/lib/App/Raps2.pm @@ -12,6 +12,7 @@ use base 'Exporter'; use App::Raps2::Password; use App::Raps2::UI; +use Carp q(confess); use File::Path qw(make_path); use File::Slurp qw(slurp write_file); @@ -82,9 +83,7 @@ sub get_master_password { passphrase => $pass, ); - if (not $self->{'pass'}->verify($self->{'master_hash'})) { - return undef; - } + $self->{'pass'}->verify($self->{'master_hash'}); } sub create_config { @@ -122,7 +121,7 @@ sub cmd_add { my $ui = $self->{'ui'}; if (-e $pwfile) { - return undef; + confess('Password file already exists'); } $self->get_master_password(); @@ -157,7 +156,7 @@ sub cmd_dump { my $pwfile = $self->{'xdg_data'} . "/${name}"; if (not -e $pwfile) { - return undef; + confess('Password file does not exist'); } my %key = file_to_hash($pwfile); @@ -182,7 +181,7 @@ sub cmd_info { my $pwfile = $self->{'xdg_data'} . "/${name}"; if (not -e $pwfile) { - return undef; + confess('Password file does not exist'); } my %key = file_to_hash($pwfile); diff --git a/lib/App/Raps2/Password.pm b/lib/App/Raps2/Password.pm index 2ac1a51..ca7874b 100644 --- a/lib/App/Raps2/Password.pm +++ b/lib/App/Raps2/Password.pm @@ -1,8 +1,5 @@ package App::Raps2::Password; - - - use strict; use warnings; use autodie; @@ -10,6 +7,7 @@ use 5.010; use base 'Exporter'; +use Carp 'confess'; use Crypt::CBC; use Crypt::Eksblowfish; use Crypt::Eksblowfish::Bcrypt qw(bcrypt_hash en_base64 de_base64); @@ -23,11 +21,11 @@ sub new { $conf{'cost'} //= 12; if (not (defined $conf{'salt'} and length($conf{'salt'}) == 16)) { - return undef; + confess('incorrect salt length'); } if (not (defined $conf{'passphrase'} and length $conf{'passphrase'})) { - return undef; + confess('no passphrase given'); } my $ref = \%conf; @@ -39,7 +37,7 @@ sub salt { my ($self, $salt) = @_; if (not (defined $salt and length($salt) == 16)) { - return undef; + confess('incorrect salt length'); } $self->{'salt'} = $salt; @@ -92,7 +90,7 @@ sub verify { if ($testhash eq $myhash) { return 1; } - return undef; + confess('Passwords did not match'); } 1; diff --git a/lib/App/Raps2/UI.pm b/lib/App/Raps2/UI.pm index 43abf29..427270c 100644 --- a/lib/App/Raps2/UI.pm +++ b/lib/App/Raps2/UI.pm @@ -7,6 +7,7 @@ use 5.010; use base 'Exporter'; +use Carp qw(confess); use POSIX; our @EXPORT_OK = (); @@ -63,7 +64,7 @@ sub read_pw { $term->setattr(0, POSIX::TCSANOW); if ($verify and $in1 ne $in2) { - return undef; + confess('Input lines did not match'); } chomp $in1; |