HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
security.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9
10
11
12namespace hi::inline v1 {
13
21void secure_clear(void *ptr, size_t size) noexcept;
22
29inline void secure_clear(trivially_copyable auto &object) noexcept
30{
31 secure_clear(&object, sizeof(object));
32}
33
41template<typename It>
42void secure_clear(It first, It last) noexcept
43{
44 using value_type = decltype(*first);
45
46 if constexpr (requires { std::distance(first, last); }) {
47 secure_clear(std::addressof(*first), std::distance(first, last) * sizeof(value_type));
48
49 } else {
50 for (auto it = first; it != last; ++it) {
52 }
53 }
54}
55
56void secure_destroy_at(auto *p)
57{
58 std::destroy_at(p);
59 secure_clear(*p);
60}
61
70template<typename It>
71void secure_destroy(It first, It last)
72{
73 std::destroy(first, last);
74 secure_clear(first, last);
75}
76
86template<typename It, typename OutIt>
88{
89 std::uninitialized_move(first, last, d_first);
90 secure_erase(first, last);
91}
92
93}
94
DOXYGEN BUG.
Definition algorithm.hpp:16
void secure_destroy(It first, It last)
Securely destroy objects.
Definition security.hpp:71
void secure_uninitialized_move(It first, It last, OutIt d_first)
Securely move objects.
Definition security.hpp:87
void secure_clear(void *ptr, size_t size) noexcept
Securely clear memory.
Definition security_win32.hpp:13
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
T addressof(T... args)
T distance(T... args)