libfilezilla
Namespaces | Functions
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.

Namespaces

 fz
 The namespace used by libfilezilla.
 

Functions

void sleep (duration const &d)
 Sleep current thread for the specified duration. More...
 
void yield ()
 Relinquish control for a brief amount of time. More...
 
int64_t random_number (int64_t min, int64_t max)
 Get a secure random integer uniformly distributed in the closed interval [min, max]. More...
 
std::vector< uint8_t > random_bytes (size_t size)
 Get random uniformly distributed bytes. More...
 
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. More...
 
uint64_t bitscan_reverse (uint64_t v)
 Returns index of the most-significant set bit. More...
 
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. More...
 
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. More...
 
void wipe (void *p, size_t n)
 Securely wipes the memory. More...
 
void wipe (std::string &s)
 Securely wipes the entire storage of the container. More...
 
void wipe (std::vector< uint8_t > &v)
 
void wipe_unused (std::string &s)
 Securely wipes the unused space in these containers. More...
 
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.