libfilezilla
Loading...
Searching...
No Matches
util.hpp File Reference

Various utility functions. More...

#include "libfilezilla.hpp"
#include "time.hpp"
#include <cstdint>
Include dependency graph for util.hpp:

Go to the source code of this file.

Classes

struct  scoped_wiper< T >

Namespaces

namespace  fz
 The namespace used by libfilezilla.

Functions

void sleep (duration const &d)
 Sleep current thread for the specified duration.
void yield ()
 Relinquish control for a brief amount of time.
int64_t random_number (int64_t min, int64_t max)
 Get a secure random integer uniformly distributed in the closed interval [min, max].
std::vector< uint8_t > random_bytes (size_t size)
 Get random uniformly distributed bytes.
void random_bytes (size_t size, uint8_t *destination)
void random_bytes (size_t size, buffer &destination)
uint64_t bitscan (uint64_t v)
 Returns index of the least-significant set bit.
uint64_t bitscan_reverse (uint64_t v)
 Returns index of the most-significant set bit.
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.
template<typename First, typename Second, std::enable_if_t< sizeof(typename First::value_type)==sizeof(uint8_t) &&sizeof(typename Second::value_type)==sizeof(uint8_t)> * = nullptr>
bool equal_consttime (First const &lhs, Second const &rhs)
template<typename T, typename std::enable_if_t< std::is_final_v< T > > * = nullptr>
T & move_assign_through_move_constructor (T *p, T &&op) noexcept
 Helper to move-assign guaranteeing same member destruction order as the destructor.
void wipe (void *p, size_t n)
 Securely wipes the memory.
void wipe (std::string &s)
 Securely wipes the entire storage of the container.
void wipe (std::wstring &s)
void wipe (std::vector< uint8_t > &v)
void wipe_unused (std::string &s)
 Securely wipes the unused space in these containers.
void wipe_unused (std::wstring &s)
void wipe_unused (std::vector< uint8_t > &v)
template<class A, class B>
constexpr bool cmp_less (A a, B b) noexcept
 Compares two integers which can be of different sizes and signeness.
template<typename Out, typename In>
constexpr Out clamped_cast (In in) noexcept
 Casts to a different integer type, clamping the new value to the min/max of the new type if the original value cannot be represented.

Detailed Description

Various utility functions.