libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
cipher_registry.hh
Go to the documentation of this file.
1/*
2 * libkeepass - KeePass key database importer/exporter
3 * Copyright (C) 2014 Christian Kindahl
4 * Copyright (C) 2024 Dominik Krümpelmann
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22#pragma once
23
24#include <array>
25#include <functional>
26#include <map>
27#include <memory>
28#include <mutex>
29
30#include "database.hh"
31#include "libkeepass/cipher.hh"
32#include "libkeepass/export.hh"
33
34namespace keepass {
35
46public:
48 using Factory = std::function<std::unique_ptr<Cipher<16>>(
49 const uint8_t* key, const std::array<uint8_t, 16>& init_vector)>;
50
53
55 void Register(Database::Cipher cipher, Factory factory);
56
58 std::unique_ptr<Cipher<16>> Create(Database::Cipher cipher, const uint8_t* key,
59 const std::array<uint8_t, 16>& init_vector) const;
60
62 bool Contains(Database::Cipher cipher) const;
63
64private:
66
67 mutable std::mutex mutex_;
68 std::map<Database::Cipher, Factory> factories_;
69};
70
71} // namespace keepass
Block and stream cipher abstractions for KeePass encryption.
Process-wide registry for 16-byte block ciphers.
Definition cipher_registry.hh:45
bool Contains(Database::Cipher cipher) const
Returns whether a block-cipher factory is registered for cipher.
static CipherRegistry & Instance()
Returns the process-wide registry.
void Register(Database::Cipher cipher, Factory factory)
Registers/overwrites the factory for a payload cipher id.
std::unique_ptr< Cipher< 16 > > Create(Database::Cipher cipher, const uint8_t *key, const std::array< uint8_t, 16 > &init_vector) const
Creates a block cipher, or throws UnsupportedFeatureError.
std::function< std::unique_ptr< Cipher< 16 > >(const uint8_t *key, const std::array< uint8_t, 16 > &init_vector)> Factory
Creates a block cipher for the given 32-byte key and IV.
Definition cipher_registry.hh:49
Cipher
Cipher algorithms supported for encrypting the database payload.
Definition database.hh:77
In-memory representation of a KeePass database.
Visibility/export macro for the shared library.
#define LIBKEEPASS_API
Marks a class, function or variable as part of the public ABI.
Definition export.hh:43