]>
Dogcows Code - chaz/p5-File-KDBX/blob - lib/File/KDBX/Key/Composite.pm
1 package File
::KDBX
::Key
::Composite
;
2 # ABSTRACT: A composite key made up of component keys
7 use Crypt
::Digest
qw(digest_data);
9 use File
::KDBX
::Util
qw(:class :erase);
10 use Ref
::Util
qw(is_arrayref);
11 use Scalar
::Util
qw(blessed);
14 extends
'File::KDBX::Key';
16 our $VERSION = '0.901'; # VERSION
20 my $primitive = shift // throw
'Missing key primitive';
22 my @primitive = grep { defined } is_arrayref
($primitive) ? @$primitive : $primitive;
23 @primitive or throw
'Composite key must have at least one component key', count
=> scalar @primitive;
25 my @keys = map { blessed
$_ && $_->can('raw_key') ? $_ : File
::KDBX
::Key-
>new($_,
26 keep_primitive
=> $self->{keep_primitive
}) } @primitive;
27 $self->{keys} = \
@keys;
35 my $challenge = shift;
37 my @keys = @{$self->keys} or throw
'Cannot generate a raw key from an empty composite key';
39 my @basic_keys = map { $_->raw_key } grep { !$_->can('challenge') } @keys;
41 $response = $self->challenge($challenge, @_) if defined $challenge;
42 my $cleanup = erase_scoped \
@basic_keys, $response;
44 return digest_data
('SHA256',
46 defined $response ? $response : (),
53 $self->{keys} = shift if @_;
54 return $self->{keys} ||= [];
61 my @chalresp_keys = grep { $_->can('challenge') } @{$self->keys} or return '';
63 my @responses = map { $_->challenge(@_) } @chalresp_keys;
64 my $cleanup = erase_scoped \
@responses;
66 return digest_data
('SHA256', @responses);
71 $_->hide for @{$self->keys};
77 $_->show for @{$self->keys};
91 File::KDBX::Key::Composite - A composite key made up of component keys
99 use File::KDBX::Key::Composite;
101 my $key = File::KDBX::Key::Composite->(\@component_keys);
105 A composite key is a collection of other keys. A master key capable of unlocking a KDBX database is always
106 a composite key, even if it only has a single component.
108 Inherets methods and attributes from L<File::KDBX::Key>.
116 Get one or more component L<File::KDBX::Key>.
122 $raw_key = $key->raw_key;
123 $raw_key = $key->raw_key($challenge);
125 Get the raw key from each component key and return a generated composite raw key.
129 $response = $key->challenge(...);
131 Issues a challenge to any L<File::KDBX::Key::ChallengeResponse> components keys. Arguments are passed through
132 to each component key. The responses are hashed together and the composite response is returned.
134 Returns empty string if there are no challenge-response components keys.
138 Please report any bugs or feature requests on the bugtracker website
139 L<https://github.com/chazmcgarvey/File-KDBX/issues>
141 When submitting a bug or request, please include a test-file or a
142 patch to an existing test-file that illustrates the bug or desired
147 Charles McGarvey <ccm@cpan.org>
149 =head1 COPYRIGHT AND LICENSE
151 This software is copyright (c) 2022 by Charles McGarvey.
153 This is free software; you can redistribute it and/or modify it under
154 the same terms as the Perl 5 programming language system itself.
This page took 0.047917 seconds and 4 git commands to generate.