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#include "concepts.hpp"
6
7#pragma once
8
9namespace tt::inline v1 {
10
18void secure_clear(void *ptr, size_t size) noexcept;
19
26void secure_clear(trivially_copyable auto &object) noexcept
27{
28 secure_clear(&object, sizeof(object));
29}
30
38template<typename It>
39void secure_clear(It first, It last) noexcept
40{
41 using value_type = decltype(*first);
42
43 if constexpr (requires { std::distance(first, last); }) {
44 secure_clear(std::addressof(*first), std::distance(first, last) * sizeof(value_type));
45
46 } else {
47 for (auto it = first; it != last; ++it) {
48 secure_clear(*it);
49 }
50 }
51}
52
53void secure_destroy_at(auto *p)
54{
55 std::destroy_at(p);
56 secure_clear(*p);
57}
58
67template<typename It>
68void secure_destroy(It first, It last)
69{
70 std::destroy(first, last);
71 secure_clear(first, last);
72}
73
83template<typename It, typename OutIt>
84void secure_uninitialized_move(It first, It last, OutIt d_first)
85{
86 std::uninitialized_move(first, last, d_first);
87 secure_erase(first, last);
88}
89
90}
91
DOXYGEN BUG.
Definition algorithm.hpp:15
void secure_destroy(It first, It last)
Securely destroy objects.
Definition security.hpp:68
void secure_uninitialized_move(It first, It last, OutIt d_first)
Securely move objects.
Definition security.hpp:84
void secure_clear(void *ptr, size_t size) noexcept
Securely clear memory.
Definition security_win32.hpp:12
Definition concepts.hpp:48
T addressof(T... args)
T distance(T... args)