]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Entry.pm
Fix memory protection of brand new databases
[chaz/p5-File-KDBX] / lib / File / KDBX / Entry.pm
index b6858358fd214092d49c1b882b7a167c408285c3..6a927c1b1a4608b99ae3dbe5a1af79aff8d00876 100644 (file)
@@ -11,7 +11,7 @@ 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);
@@ -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};
 }
 
@@ -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,
This page took 0.02515 seconds and 4 git commands to generate.