StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
vault.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Crypto.
5 *
6 * StormByte-Crypto original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Crypto source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, in particular Crypto++, bundled libbzip2, the StormByte-Buffer
23 * tree and the StormByte suite it vendors), which remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Crypto is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Crypto. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
46#include <StormByte/expected.hxx>
47#include <StormByte/safe/map.hxx>
48#include <StormByte/safe/string.hxx>
49#include <StormByte/size.hxx>
50#include <StormByte/type_traits/safe.hxx>
51
52#include <string_view>
53#include <utility>
54
59namespace StormByte {
64 namespace Crypto {
69 namespace Secure {
74
89 public:
98
99 Vault(const Vault&) = delete;
100
105 Vault(Vault&& other) noexcept;
106
110 ~Vault() noexcept;
111
112 Vault& operator=(const Vault&) = delete;
113
119 Vault& operator=(Vault&& other) noexcept;
121
127 void Store(std::string_view name, Password password);
128
135 ExpectedPassword Get(std::string_view name) const;
136
142 bool Contains(std::string_view name) const;
143
148 void Remove(std::string_view name);
149
153 void Clear() noexcept;
154
159 StormByte::Size Size() const noexcept;
160
165 bool Empty() const noexcept;
166
167 private:
168 Safe::Map<Safe::String, Password> m_passwords;
169 };
170 }
171 }
172}
173
Shared, wiped container for passwords and raw key material.
Definition password.hxx:108
void Clear() noexcept
Drop every password.
void Store(std::string_view name, Password password)
Store or overwrite a named password.
Vault(Vault &&other) noexcept
Move constructor.
ExpectedPassword Get(std::string_view name) const
Look up a password.
Vault(const Vault &)=delete
StormByte::Size Size() const noexcept
Number of stored passwords.
~Vault() noexcept
Destructor.
void Remove(std::string_view name)
Drop one password.
bool Contains(std::string_view name) const
Whether a name exists.
bool Empty() const noexcept
Whether the vault is empty.
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Wiped secrets of the Crypto module (Password, Vault).
StormByte::Expected< Password, VaultException > ExpectedPassword
Password or a vault error.
Definition vault.hxx:73
Crypto module of the StormByte suite.
Definition aead.hxx:53
Root namespace of the StormByte suite.
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, Safe::Shared< E > >, std::expected< T, Safe::Shared< E > > > Expected
STL namespace.
#define STORMBYTE_CRYPTO_PUBLIC
Definition visibility.h:53