+subtest 'Memory protection' => sub {
+ my $kdbx = File::KDBX->new;
+
+ is exception { $kdbx->lock }, undef, 'Can lock empty database';
+ $kdbx->unlock; # should be no-op since nothing was locked
+
+ my $entry = $kdbx->root->add_entry(
+ title => 'My Bank',
+ username => 'mreynolds',
+ password => 's3cr3t',
+ );
+ $entry->string(Custom => 'foo', protect => 1);
+ $entry->binary(Binary => 'bar', protect => 1);
+ $entry->binary(UnprotectedBinary => 'baz');
+
+ is exception { $kdbx->lock }, undef, 'Can lock new database';
+ is $entry->username, 'mreynolds', 'UserName does not get locked';
+ is $entry->password, undef, 'Password is lockable';
+ is $entry->string_value('Custom'), undef, 'Custom is lockable';
+ is $entry->binary_value('Binary'), undef, 'Binary is lockable';
+ is $entry->binary_value('UnprotectedBinary'), 'baz', 'Unprotected binary does not get locked';
+
+ $kdbx->unlock;
+ is $entry->password, 's3cr3t', 'Password is unlockable';
+ is $entry->string_value('Custom'), 'foo', 'Custom is unlockable';
+ is $entry->binary_value('Binary'), 'bar', 'Binary is unlockable';
+};
+