1 #ifndef LIBFILEZILLA_UTIL_HEADER
2 #define LIBFILEZILLA_UTIL_HEADER
23 void FZ_PUBLIC_SYMBOL
sleep(duration
const& d);
29 void FZ_PUBLIC_SYMBOL
yield();
35 int64_t FZ_PUBLIC_SYMBOL
random_number(int64_t min, int64_t max);
41 std::vector<uint8_t> FZ_PUBLIC_SYMBOL
random_bytes(
size_t size);
43 void FZ_PUBLIC_SYMBOL
random_bytes(
size_t size, uint8_t* destination);
46 void FZ_PUBLIC_SYMBOL
random_bytes(
size_t size, buffer& destination);
54 uint64_t FZ_PUBLIC_SYMBOL
bitscan(uint64_t v);
69 bool FZ_PUBLIC_SYMBOL
equal_consttime(std::basic_string_view<uint8_t>
const& lhs, std::basic_string_view<uint8_t>
const& rhs);
71 template <
typename First,
typename Second,
72 std::enable_if_t<
sizeof(
typename First::value_type) ==
sizeof(uint8_t) &&
73 sizeof(
typename Second::value_type) ==
sizeof(uint8_t)>* =
nullptr>
76 return equal_consttime(std::basic_string_view<uint8_t>(reinterpret_cast<uint8_t const*>(lhs.data()), lhs.size()),
77 std::basic_string_view<uint8_t>(reinterpret_cast<uint8_t const*>(rhs.data()), rhs.size()));
94 template<
typename T,
typename std::enable_if_t<std::is_final_v<T>>* =
nullptr>
98 new (p)T(std::move(op));
107 void FZ_PUBLIC_SYMBOL wipe(
void* p,
size_t n);
113 void FZ_PUBLIC_SYMBOL wipe(std::string & s);
114 void FZ_PUBLIC_SYMBOL wipe(std::vector<uint8_t> & v);
120 void FZ_PUBLIC_SYMBOL wipe_unused(std::string & s);
121 void FZ_PUBLIC_SYMBOL wipe_unused(std::vector<uint8_t> & v);
T & move_assign_through_move_constructor(T *p, T &&op) noexcept
Helper to move-assign guaranteeing same member destruction order as the destructor.
Definition: util.hpp:95
void sleep(duration const &d)
Sleep current thread for the specified duration.
uint64_t bitscan_reverse(uint64_t v)
Returns index of the most-significant set bit.
std::vector< uint8_t > random_bytes(size_t size)
Get random uniformly distributed bytes.
Assorted classes dealing with time.
int64_t random_number(int64_t min, int64_t max)
Get a secure random integer uniformly distributed in the closed interval [min, max].
The namespace used by libfilezilla.
Definition: apply.hpp:17
uint64_t bitscan(uint64_t v)
Returns index of the least-significant set bit.
Sets some global macros and further includes string.hpp.
void yield()
Relinquish control for a brief amount of time.
bool equal_consttime(std::basic_string_view< uint8_t > const &lhs, std::basic_string_view< uint8_t > const &rhs)
Secure equality test in constant time.