libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
variantdictionary.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
25#pragma once
26#include <cstdint>
27#include <istream>
28#include <map>
29#include <ostream>
30#include <string>
31#include <vector>
32
33#include "libkeepass/export.hh"
34
35namespace keepass {
36
43public:
45 enum class Type : uint8_t {
46 kEnd = 0x00,
47 kUInt32 = 0x04,
48 kUInt64 = 0x05,
49 kBool = 0x08,
50 kInt32 = 0x0c,
51 kInt64 = 0x0d,
52 kString = 0x18,
53 kByteArray = 0x42
54 };
55
59 struct Entry {
60 Type type = Type::kUInt32;
61 std::vector<uint8_t> value;
62 };
63
68 void Parse(std::istream& src);
69
74 void Write(std::ostream& dst) const;
75
81 bool Has(const std::string& key) const;
82
88 const Entry& Get(const std::string& key) const;
89
96 void Set(const std::string& key, Type type, std::vector<uint8_t>&& value);
97
103 std::vector<uint8_t> GetBytes(const std::string& key) const;
104
110 uint32_t GetUInt32(const std::string& key) const;
111
117 uint64_t GetUInt64(const std::string& key) const;
118
123 std::map<std::string, Entry> entries() const { return entries_; }
124
125private:
126 std::map<std::string, Entry> entries_;
127};
128
129} // namespace keepass
A typed key-value store used in KDBX 4 header fields.
Definition variantdictionary.hh:42
const Entry & Get(const std::string &key) const
Returns the entry associated with key.
std::map< std::string, Entry > entries() const
Returns a copy of all entries in the dictionary.
Definition variantdictionary.hh:123
bool Has(const std::string &key) const
Checks whether an entry with the given key exists.
std::vector< uint8_t > GetBytes(const std::string &key) const
Returns the raw value bytes of an entry.
void Set(const std::string &key, Type type, std::vector< uint8_t > &&value)
Inserts or replaces an entry in the dictionary.
void Parse(std::istream &src)
Deserializes the dictionary from a binary stream.
uint32_t GetUInt32(const std::string &key) const
Returns the value of an entry interpreted as a uint32.
Type
Type tags identifying the value kind stored in an entry.
Definition variantdictionary.hh:45
void Write(std::ostream &dst) const
Serializes the dictionary to a binary stream.
uint64_t GetUInt64(const std::string &key) const
Returns the value of an entry interpreted as a uint64.
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
A single entry in the dictionary, holding a typed value.
Definition variantdictionary.hh:59
std::vector< uint8_t > value
Raw serialized value bytes.
Definition variantdictionary.hh:61