HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
security.hpp
1
2#include "concepts.hpp"
3
4#pragma once
5
6namespace tt::inline v1 {
7
15void secure_clear(void *ptr, size_t size) noexcept;
16
23void secure_clear(trivially_copyable auto &object) noexcept
24{
25 secure_clear(&object, sizeof(object));
26}
27
35template<typename It>
36void secure_clear(It first, It last) noexcept
37{
38 using value_type = decltype(*first);
39
40 if constexpr (requires { std::distance(first, last); }) {
41 secure_clear(std::addressof(*first), std::distance(first, last) * sizeof(value_type));
42
43 } else {
44 for (auto it = first; it != last; ++it) {
45 secure_clear(*it);
46 }
47 }
48}
49
50void secure_destroy_at(auto *p)
51{
52 std::destroy_at(p);
53 secure_clear(*p);
54}
55
64template<typename It>
65void secure_destroy(It first, It last)
66{
67 std::destroy(first, last);
68 secure_clear(first, last);
69}
70
80template<typename It, typename OutIt>
81void secure_uninitialized_move(It first, It last, OutIt d_first)
82{
83 std::uninitialized_move(first, last, d_first);
84 secure_erase(first, last);
85}
86
87}
88
T addressof(T... args)
T distance(T... args)