diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-06-02 13:31:22 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-06-02 13:31:22 +0200 |
commit | 0d1c99e9dc83e169e492363ffe21596131e793a6 (patch) | |
tree | 8a5975a8723180f384544f593c73cb6c55522ad6 | |
parent | 605a9ac29633cb853d83141e54ea887d0d1a2d05 (diff) |
App/Raps2.pm: Add pw_add / pw_get methods
-rw-r--r-- | lib/App/Raps2.pm | 78 |
1 files changed, 56 insertions, 22 deletions
diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm index 531e629..133b898 100644 --- a/lib/App/Raps2.pm +++ b/lib/App/Raps2.pm @@ -123,6 +123,30 @@ sub ui { return $self->{ui}; } +sub pw_add { + my ( $self, %data ) = @_; + + $self->pw->salt( $data{salt} ); + + my $pass_hash = $self->pw->encrypt( $data{password} ); + my $extra_hash = ( + $data{extra} + ? $self->pw->encrypt( $data{extra} ) + : q{} + ); + + write_file( + $data{file}, + "url $data{url}\n", + "login $data{login}\n", + "salt $data{salt}\n", + "hash ${pass_hash}\n", + "extra ${extra_hash}\n", + ); + + return; +} + sub cmd_add { my ( $self, $name ) = @_; @@ -140,25 +164,37 @@ sub cmd_add { my $pass = $self->ui->read_pw( 'Password', 1 ); my $extra = $self->ui->read_multiline('Additional content'); - $self->pw->salt($salt); - my $pass_hash = $self->pw->encrypt($pass); - my $extra_hash = ( - $extra - ? $self->pw->encrypt($extra) - : q{} - ); - - write_file( - $pwfile, "url ${url}\n", - "login ${login}\n", - "salt ${salt}\n", - "hash ${pass_hash}\n", - "extra ${extra_hash}\n", + $self->pw_add( + file => $pwfile, + salt => $salt, + url => $url, + login => $login, + password => $pass, + extra => $extra, ); return; } +sub pw_get { + my ( $self, %data ) = @_; + + my %key = $self->file_to_hash( $data{file} ); + + $self->pw->salt( $key{salt} ); + + return { + url => $key{url}, + login => $key{login}, + password => $self->pw->decrypt( $key{hash} ), + extra => ( + $key{extra} + ? $self->pw->decrypt( $key{extra} ) + : undef + ), + }; +} + sub cmd_dump { my ( $self, $name ) = @_; @@ -168,19 +204,17 @@ sub cmd_dump { confess('Password file does not exist'); } - my %key = $self->file_to_hash($pwfile); - $self->get_master_password(); - $self->pw->salt( $key{salt} ); + my $key = $self->pw_get( file => $pwfile ); $self->ui()->output( - [ 'URL', $key{url} ], - [ 'Login', $key{login} ], - [ 'Password', $self->pw->decrypt( $key{hash} ) ], + [ 'URL', $key->{url} ], + [ 'Login', $key->{login} ], + [ 'Password', $key->{password} ], ); - if ( $key{extra} ) { - print $self->pw->decrypt( $key{extra} ); + if ( $key->{extra} ) { + print $key->{extra}; } return; |