From 2a03eac098be689fa11c371b926d3f2d8ae4c96d Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 4 Jul 2011 10:00:53 +0200 Subject: Raps2.pm: Add pw_load_info method (pw_load for unencrypted data) --- Changelog | 1 + bin/raps2 | 4 ++-- lib/App/Raps2.pm | 48 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Changelog b/Changelog index 8096a3c..86f6b64 100644 --- a/Changelog +++ b/Changelog @@ -7,6 +7,7 @@ git HEAD * pw_load now also returns the salt * file_to_hash now returns a hashref instead of a hash * Allow password to be passed as argument to get_master_password + * Add pw_load_info method App::Raps2 0.4 - Sun Jul 03 2011 diff --git a/bin/raps2 b/bin/raps2 index 689ecd2..cb74009 100755 --- a/bin/raps2 +++ b/bin/raps2 @@ -141,7 +141,7 @@ sub cmd_info { exit 2; } - my $key = $raps2->file_to_hash($pwfile); + my $key = $raps2->pw_load_info( file => $pwfile ); $raps2->ui->output( [ 'URL', $key->{url} ], [ 'Login', $key->{login} ], ); return; @@ -151,7 +151,7 @@ sub cmd_list { my @files = read_dir( data_home('raps2') ); for my $file ( sort @files ) { - my $key = $raps2->file_to_hash( data_files("raps2/${file}") ); + my $key = $raps2->pw_load_info( name => $file ); $raps2->ui->list( [ 'Account', $file ], [ 'Login', $key->{login} ], diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm index 720e942..96f37d7 100644 --- a/lib/App/Raps2.pm +++ b/lib/App/Raps2.pm @@ -177,6 +177,20 @@ sub pw_load { }; } +sub pw_load_info { + my ( $self, %data ) = @_; + + $data{file} //= $self->{xdg_data} . "/$data{name}"; + + my $key = $self->file_to_hash( $data{file} ); + + return { + url => $key->{url}, + login => $key->{login}, + salt => $key->{salt}, + }; +} + 1; __END__ @@ -203,7 +217,7 @@ This manual documents App::Raps2 version 0.4 =over -=item $raps2 = App::Raps2->new(I<%conf>) +=item $raps2 = App::Raps2->new( I<%conf> ) Returns a new B object. @@ -217,17 +231,12 @@ B of key setup, passed on to App::Raps2::Password(3pm). =back -=item $raps2->file_to_hash(I<$file>) - -Reads $file (lines with key/value separated by whitespace) and returns a -hashref with its key/value pairs. - -=item $raps2->get_master_password([I<$password>]) +=item $raps2->get_master_password( [I<$password>] ) Sets the master password used to encrypt all accounts. Uses I if specified, otherwise it asks the user via App::Raps2::UI(3pm). -=item $raps2->pw_save(I<%data>) +=item $raps2->pw_save( I<%data> ) Write an account as specified by I to the store. Requires B to have been called before. @@ -250,11 +259,21 @@ The following I keys are supported: =back -=item $raps2->pw_load(B => I | B => I) +=item $raps2->pw_load( B => I | B => I ) + +Load a password from I (or account I), requires +B to have been called before. + +Returns a hashref containing its url, login, salt and decrypted password and +extra. + +=item $raps2->pw_load_info( B => I | B => I ) -Loads a password from I (or account I), requires -B to have been called before. Returns a hashref -containing its url, login and decrypted password and extra. +Load all unencrypted data from I (or account I). Unlike +B, this method does not require a prior call to +B. + +Returns a hashref with url, login and salt. =back @@ -288,6 +307,11 @@ Returns the App::Raps2::Password(3pm) object. Returns the App::Raps2::UI(3pm) object. +=item $raps2->file_to_hash( I<$file> ) + +Reads $file (lines with key/value separated by whitespace) and returns a +hashref with its key/value pairs. + =back =head1 DIAGNOSTICS -- cgit v1.2.3