HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
security_intf.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#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
9#endif
10
11#include "../utility/utility.hpp"
12#include "../macros.hpp"
13#include <iterator>
14#include <memory>
15
16hi_export_module(hikogui.security : intf);
17
18
19hi_export namespace hi::inline v1 {
20
28void secure_clear(void *ptr, size_t size) noexcept;
29
36inline void secure_clear(trivially_copyable auto &object) noexcept
37{
38 secure_clear(&object, sizeof(object));
39}
40
48template<typename It>
49void secure_clear(It first, It last) noexcept
50{
51 using value_type = decltype(*first);
52
53 if constexpr (requires { std::distance(first, last); }) {
54 secure_clear(std::addressof(*first), std::distance(first, last) * sizeof(value_type));
55
56 } else {
57 for (auto it = first; it != last; ++it) {
58 secure_clear(*it);
59 }
60 }
61}
62
63void secure_destroy_at(auto *p)
64{
65 std::destroy_at(p);
66 secure_clear(*p);
67}
68
77template<typename It>
78void secure_destroy(It first, It last)
79{
80 std::destroy(first, last);
81 secure_clear(first, last);
82}
83
93template<typename It, typename OutIt>
94void secure_uninitialized_move(It first, It last, OutIt d_first)
95{
96 std::uninitialized_move(first, last, d_first);
97 secure_erase(first, last);
98}
99
100}
101
Rules for working with win32 headers.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
void secure_destroy(It first, It last)
Securely destroy objects.
Definition security_intf.hpp:78
void secure_uninitialized_move(It first, It last, OutIt d_first)
Securely move objects.
Definition security_intf.hpp:94
void secure_clear(void *ptr, size_t size) noexcept
Securely clear memory.
Definition security_win32_impl.hpp:16
T addressof(T... args)
T distance(T... args)