X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FEntry.pm;h=6a927c1b1a4608b99ae3dbe5a1af79aff8d00876;hb=a4c5d05556ecd450acce5e20fcab7af5f282af2f;hp=8596aa23f3bb84dba68cef1964fc6797c335d91f;hpb=fe0093f5f317cd136a2328abb7b0c31a69d4fe33;p=chaz%2Fp5-File-KDBX diff --git a/lib/File/KDBX/Entry.pm b/lib/File/KDBX/Entry.pm index 8596aa2..6a927c1 100644 --- a/lib/File/KDBX/Entry.pm +++ b/lib/File/KDBX/Entry.pm @@ -11,11 +11,11 @@ use File::KDBX::Constants qw(:history :icon); use File::KDBX::Error; use File::KDBX::Util qw(:assert :class :coercion :erase :function :uri generate_uuid load_optional); use Hash::Util::FieldHash; -use List::Util qw(first sum0); +use List::Util qw(any first sum0); use Ref::Util qw(is_coderef is_hashref is_plain_hashref); use Scalar::Util qw(blessed looks_like_number); use Storable qw(dclone); -use Time::Piece; +use Time::Piece 1.33; use boolean; use namespace::clean; @@ -60,7 +60,7 @@ An array of window title / keystroke sequence associations. keystroke_sequence => '{USERNAME}{TAB}{PASSWORD}{ENTER}', } -Keystroke sequences can have , most commonly C<{USERNAME}> and C<{PASSWORD}>. +Keystroke sequences can have L, most commonly C<{USERNAME}> and C<{PASSWORD}>. =attr quality_check @@ -253,14 +253,16 @@ sub string { return $self->{strings}{$key} = $args{value} if is_plain_hashref($args{value}); + # Auto-vivify the standard strings. + if (!exists $self->{strings}{$key} && $STANDARD_STRINGS{$key}) { + $args{value} //= ''; + $args{protect} //= true if $self->_protect($key); + } + while (my ($field, $value) = each %args) { $self->{strings}{$key}{$field} = $value; } - # Auto-vivify the standard strings. - if ($STANDARD_STRINGS{$key}) { - return $self->{strings}{$key} //= {value => '', $self->_protect($key) ? (protect => true) : ()}; - } return $self->{strings}{$key}; } @@ -298,7 +300,7 @@ sub string_value { =method expand_string_value - $string = $entry->expand_string_value; + $string = $entry->expand_string_value($string_key); Same as L but will substitute placeholders and resolve field references. Any placeholders that do not expand to values are left as-is. @@ -308,6 +310,26 @@ See L. Some placeholders (notably field references) require the entry be connected to a database and will throw an error if it is not. +=method expand_notes + +Shortcut equivalent to C<< ->expand_string_value('Notes') >>. + +=method expand_password + +Shortcut equivalent to C<< ->expand_string_value('Password') >>. + +=method expand_title + +Shortcut equivalent to C<< ->expand_string_value('Title') >>. + +=method expand_url + +Shortcut equivalent to C<< ->expand_string_value('URL') >>. + +=method expand_username + +Shortcut equivalent to C<< ->expand_string_value('UserName') >>. + =cut sub _expand_placeholder { @@ -360,26 +382,6 @@ sub expand_string_value { return $self->_expand_string($str); } -=attr expand_notes - -Shortcut equivalent to C<< ->expand_string_value('Notes') >>. - -=attr expand_password - -Shortcut equivalent to C<< ->expand_string_value('Password') >>. - -=attr expand_title - -Shortcut equivalent to C<< ->expand_string_value('Title') >>. - -=attr expand_url - -Shortcut equivalent to C<< ->expand_string_value('URL') >>. - -=attr expand_username - -Shortcut equivalent to C<< ->expand_string_value('UserName') >>. - =method other_strings $other = $entry->other_strings; @@ -553,7 +555,7 @@ sub hmac_otp { $params{secret} = encode_b32r($params{secret}) if !$params{base32}; $params{base32} = 1; - my $otp = eval {Pass::OTP::otp(%params, @_) }; + my $otp = eval { Pass::OTP::otp(%params, @_) }; if (my $err = $@) { throw 'Unable to generate HOTP', error => $err; } @@ -587,7 +589,7 @@ sub time_otp { $params{secret} = encode_b32r($params{secret}) if !$params{base32}; $params{base32} = 1; - my $otp = eval {Pass::OTP::otp(%params, @_) }; + my $otp = eval { Pass::OTP::otp(%params, @_) }; if (my $err = $@) { throw 'Unable to generate TOTP', error => $err; } @@ -654,8 +656,8 @@ sub _hotp_params { my %params = ( type => 'hotp', - issuer => $self->title || 'KDBX', - account => $self->username || 'none', + issuer => $self->expand_title || 'KDBX', + account => $self->expand_username || 'none', digits => 6, counter => $self->string_value('HmacOtp-Counter') // 0, $self->_otp_secret_params('Hmac'), @@ -680,8 +682,8 @@ sub _totp_params { ); my %params = ( type => 'totp', - issuer => $self->title || 'KDBX', - account => $self->username || 'none', + issuer => $self->expand_title || 'KDBX', + account => $self->expand_username || 'none', digits => $self->string_value('TimeOtp-Length') // 6, algorithm => $algorithms{$self->string_value('TimeOtp-Algorithm') || ''} || 'sha1', period => $self->string_value('TimeOtp-Period') // 30, @@ -1055,7 +1057,8 @@ There is also some metadata associated with an entry. Each entry in a database i a UUID. An entry can also have an icon associated with it, and there are various timestamps. Take a look at the attributes to see what's available. -A B is a subclass of L. +A B is a subclass of L. View its documentation to see other attributes +and methods available on entries. =head2 Placeholders