added the password policy feature to the core (::Record) for easier access.

This commit is contained in:
git@daemon.de
2013-07-05 15:26:34 +02:00
parent ed5afed40f
commit f66b9e9aeb
4 changed files with 41 additions and 7 deletions

View File

@@ -1,3 +1,7 @@
1.13
added Crypt::PWSafe3::PasswordPolicy submodule, which allows
to access the password policy of a PasswordSafe record.
1.12 1.12
I somehow managed to mangle version numbers of sub modules, I somehow managed to mangle version numbers of sub modules,
now all properly incremented. now all properly incremented.

View File

@@ -22,12 +22,13 @@ use Data::Dumper;
use Exporter (); use Exporter ();
use vars qw(@ISA @EXPORT); use vars qw(@ISA @EXPORT);
$Crypt::PWSafe3::VERSION = '1.12'; $Crypt::PWSafe3::VERSION = '1.13';
use Crypt::PWSafe3::Field; use Crypt::PWSafe3::Field;
use Crypt::PWSafe3::HeaderField; use Crypt::PWSafe3::HeaderField;
use Crypt::PWSafe3::Record; use Crypt::PWSafe3::Record;
use Crypt::PWSafe3::SHA256; use Crypt::PWSafe3::SHA256;
use Crypt::PWSafe3::PasswordPolicy;
require 5.10.0; require 5.10.0;

View File

@@ -67,6 +67,8 @@ sub new {
sub decode { sub decode {
my($this, $raw) = @_; my($this, $raw) = @_;
return if $raw eq '';
# expected input: ffffnnnllluuudddsss # expected input: ffffnnnllluuudddsss
# create a 6-elemt array # create a 6-elemt array
@@ -136,7 +138,7 @@ Crypt::PWSafe3::PasswordPolicy - represent a passwordsafe v3 passwprd policy ent
use Crypt::PWSafe3; use Crypt::PWSafe3;
use Crypt::PWSafe3::PasswordPolicy; use Crypt::PWSafe3::PasswordPolicy;
my $record = $vault->getrecord($uuid); my $record = $vault->getrecord($uuid);
my $policy = Crypt::PWSafe3::PasswordPolicy->new(raw => $record->pwpol); my $policy = $record->policy;
# print current values # print current values
print Dumper($policy); print Dumper($policy);
@@ -149,7 +151,9 @@ Crypt::PWSafe3::PasswordPolicy - represent a passwordsafe v3 passwprd policy ent
$policy->MinSymbols(2); $policy->MinSymbols(2);
# put back into record # put back into record
$record->raw($policy->encode()); $record->policy($policy);
=head1 DESCRIPTION =head1 DESCRIPTION

View File

@@ -9,7 +9,7 @@ my %map2type = %Crypt::PWSafe3::Field::map2type;
my %map2name = %Crypt::PWSafe3::Field::map2name; my %map2name = %Crypt::PWSafe3::Field::map2name;
$Crypt::PWSafe3::Record::VERSION = '1.06'; $Crypt::PWSafe3::Record::VERSION = '1.07';
foreach my $field (keys %map2type ) { foreach my $field (keys %map2type ) {
eval qq( eval qq(
@@ -144,6 +144,22 @@ sub addfield {
$this->{field}->{ $name } = $field; $this->{field}->{ $name } = $field;
} }
sub policy {
#
# return or set a password policy
my ($this, $policy) = @_;
if($policy) {
$this->{policy} = $policy;
$this->pwpol($policy->encode());
}
else {
$this->{policy} = Crypt::PWSafe3::PasswordPolicy->new(raw => $this->pwpol);
}
return $this->{policy};
}
=head1 NAME =head1 NAME
Crypt::PWSafe3::Record - Represents a Passwordsafe v3 data record Crypt::PWSafe3::Record - Represents a Passwordsafe v3 data record
@@ -265,9 +281,18 @@ for more details.
Returns the password policy without argument. Sets the password policy Returns the password policy without argument. Sets the password policy
if an argument is given. if an argument is given.
B<Crypt::PWSafe3> doesn't update the pwpol field currently. So if This is the raw encoded policy string. If you want to access it, use the
you mind, do it yourself. Refer to L<Crypt::PWSafe3::Databaseformat> B<policy()> method, see below.
for more details.
=head2 B<policy([Crypt::PWSafe3::PasswordPolicy object])>
If called without arguments, returns a Crypt::PWSafe3::PasswordPolicy
object. See L<Crypt::PWSafe3::PasswordPolicy> for details, how to access
it.
To modify the password policy, create new Crypt::PWSafe3::PasswordPolicy
object or modify the existing one and pass it as argument to the
B<policy> method.
=head2 B<pwexp([string])> =head2 B<pwexp([string])>