libfilezilla
Classes | Typedefs | Enumerations | Functions
fz Namespace Reference

The namespace used by libfilezilla. More...

Classes

class  ascii_layer
 
class  buffer
 The buffer class is a simple buffer where data can be appended at the end and consumed at the front. Think of it as a deque with contiguous storage. More...
 
class  public_key
 Represents a X25519 public key with associated salt. More...
 
class  private_key
 Represents a X25519 private key with associated salt. More...
 
class  symmetric_key
 Symmetric encryption key with associated salt. More...
 
class  event_base
 Common base class for all events. More...
 
class  simple_event
 This is the recommended event class. More...
 
class  event_handler
 Simple handler for asynchronous event processing. More...
 
class  event_loop
 A threaded event loop that supports sending events and timers. More...
 
class  file
 Lean class for file access. More...
 
class  result
 Small class to return filesystem errors. More...
 
class  rwresult
 Holds the result of read/write operations. More...
 
class  hash_accumulator
 Accumulator for hashing large amounts of data. More...
 
class  hostname_lookup
 
class  impersonation_token
 Impersonation tokens for a given user can be used to spawn processes running as that user. More...
 
struct  network_interface
 
class  json
 json parser/builder More...
 
struct  json_array_iterator
 
class  local_filesys
 This class can be used to enumerate the contents of local directories and to query the metadata of files. More...
 
class  logger_interface
 Abstract interface for logging strings. More...
 
class  null_logger
 A logger that does not log anything. More...
 
class  stdout_logger
 A simple logger that writes to stdout. More...
 
class  mutex
 Lean replacement for std::(recursive_)mutex. More...
 
class  scoped_lock
 A simple scoped lock. More...
 
class  condition
 Waitable condition variable. More...
 
class  nonowning_buffer
 Similar to fz::buffer, but does not own memory. More...
 
class  sparse_optional
 Similar to C++17's std::optional, but stores the data in dynamic memory. More...
 
class  process
 The process class manages an asynchronous process with redirected IO. More...
 
class  rate_limited_layer
 A rate-limited socket layer. More...
 
class  compound_rate_limited_layer
 A compound rate-limited socket layer. More...
 
class  rate_limit_manager
 Context for rate_limiters. More...
 
class  bucket_base
 Base class for buckets. More...
 
class  rate_limiter
 A limiter for the attached buckets. More...
 
class  bucket
 A rate-limited token bucket. More...
 
class  recursive_remove
 Recursively deletes directories. More...
 
class  rwmutex
 Lean rw mutex. More...
 
class  scoped_read_lock
 A simple scoped read lock. More...
 
class  scoped_write_lock
 A simple scoped read lock. More...
 
class  shared_optional
 shared_optional is like std::shared_ptr but with relational operators acting like C++17's std::optional More...
 
class  public_verification_key
 Represents a public key to verify messages signed using Ed25519. More...
 
class  private_signing_key
 Represents a private key to sign message with using Ed25519. More...
 
class  socket_event_source
 All classes sending socket events should derive from this. More...
 
class  socket_base
 Common base clase for fz::socket and fz::listen_socket. More...
 
class  socket_descriptor
 Lightweight holder for socket descriptors. More...
 
class  listen_socket
 Simple Listen socket. More...
 
class  socket_interface
 Interface for sockets. More...
 
class  socket
 IPv6 capable, non-blocking socket class. More...
 
class  socket_layer
 A base class for socket layers. More...
 
struct  less_insensitive_ascii
 Comparator to be used for std::map for case-insensitive keys. More...
 
class  strtokenizer
 Container-like class that can be used to iterate over tokens in a string. More...
 
class  thread
 Spawns and represents a new thread of execution. More...
 
class  async_task
 Handle for asynchronous tasks. More...
 
class  thread_pool
 A dumb thread-pool for asynchronous tasks. More...
 
class  datetime
 Represents a point of time in wallclock, tracking the timestamps accuracy/precision. More...
 
class  duration
 The duration class represents a time interval in milliseconds. More...
 
class  monotonic_clock
 A monotonic clock (aka steady clock) is independent from walltime. More...
 
class  x509_certificate
 Represents all relevant information of a X.509 certificate as used by TLS. More...
 
class  tls_session_info
 Information about a TLS session. More...
 
class  tls_layer
 A Transport Layer Security (TLS) layer. More...
 
class  tls_system_trust_store
 Opaque class to load the system trust store asynchronously. More...
 
class  uri
 The uri class is used to decompose URIs into their individual components. More...
 
class  query_string
 Class for parsing a URI's query string. More...
 
class  buffer_lease
 
class  aio_waiter
 
class  aio_waitable
 
class  aio_buffer_pool
 A buffer pool for use with async readers/writers. More...
 
class  aio_base
 
class  reader_base
 Base class for all readers. More...
 
class  reader_factory
 A reader factory. More...
 
class  reader_factory_holder
 Holder for reader factories. More...
 
class  threaded_reader
 Base class for threaded readers. More...
 
class  file_reader
 File reader. More...
 
class  file_reader_factory
 Factory for. More...
 
class  view_reader
 
class  view_reader_factory
 
class  string_reader
 String reader, keeps a copy of the string. More...
 
class  string_reader_factory
 Factory for. More...
 
class  writer_base
 Base class for all writers. More...
 
class  writer_factory
 A writer factory. More...
 
class  writer_factory_holder
 
class  threaded_writer
 Base class for threaded writer. More...
 
class  file_writer
 File writer. More...
 
class  file_writer_factory
 Factory for. More...
 
class  buffer_writer
 
class  buffer_writer_factory
 
class  xml_parser_writer
 Forwards received data directly into an XML parser. More...
 
class  xml_namespace_parser_writer
 Similar to. More...
 
class  dll
 Encapsulates a DLL. More...
 
class  shdlls
 A collection of commonly used dlls. More...
 
class  regkey
 Prepresents a key in the Windows registry. More...
 

Typedefs

typedef unsigned long long timer_id
 
typedef simple_event< timer_event_type, timer_id > timer_event
 All timer events have this type. More...
 
typedef simple_event< hostname_lookup_event_type, hostname_lookup *, int, std::vector< std::string > > hostname_lookup_event
 Results of hostname_lookup. On success, second argument is zero, otherwise an error code.
 
typedef std::function< void(std::function< void()>)> invoker_factory
 
typedef simple_event< process_event_type, process *, process_event_flagprocess_event
 
template<typename T >
using shared_value = shared_optional< T, true >
 like shared_optional but can never be empty More...
 
typedef simple_event< socket_event_type, socket_event_source *, socket_event_flag, int > socket_event
 
typedef simple_event< hostaddress_event_type, socket_event_source *, std::string > hostaddress_event
 
typedef std::wstring native_string
 A string in the system's native character type and encoding.
Note: This typedef changes depending on platform! More...
 
typedef std::wstring_view native_string_view
 
typedef simple_event< certificate_verification_event_type, tls_layer *, tls_session_infocertificate_verification_event
 This event gets sent during the handshake with details about the session and the used certificate. More...
 
typedef simple_event< aio_buffer_event_type, aio_waitable const * > aio_buffer_event
 

Enumerations

enum class  base64_type { standard , url }
 Alphabet variations for base64. More...
 
enum class  base32_type { standard , base32hex , locale_safe }
 Alphabet variations for base32. More...
 
enum class  hash_algorithm { md5 , sha1 , sha256 , sha512 }
 List of supported hashing algorithms.
 
enum class  address_type { unknown , ipv4 , ipv6 , unix }
 
enum class  json_type {
  none , null , object , array ,
  string , number , boolean
}
 Types of JSON values. More...
 
enum class  mkdir_permissions { normal , cur_user , cur_user_and_admins }
 
enum class  process_event_flag { read = 0x1 , write = 0x2 }
 The type of a process event. More...
 
enum  { signature_size = 64 }
 
enum class  socket_event_flag { connection_next = 0x1 , connection = 0x2 , read = 0x4 , write = 0x8 }
 The type of a socket event. More...
 
enum class  listen_socket_state { none , listening }
 
enum class  socket_state : unsigned char {
  none , connecting , connected , shutting_down ,
  shut_down , closed , failed
}
 State transitions are monotonically increasing. More...
 
enum class  tls_ver { v1_0 , v1_1 , v1_2 , v1_3 }
 
enum class  tls_server_flags : unsigned int { none = 0 , no_auto_ticket = 0x1 }
 
enum class  aio_result { ok , wait , error }
 Result of aio operations. More...
 
enum class  file_writer_flags : unsigned { fsync = 0x01 , permissions_current_user_only = 0x02 , permissions_current_user_and_admins_only = 0x04 }
 

Functions

template<typename Obj , typename F , typename Tuple , typename Seq = typename std::make_index_sequence<std::tuple_size_v<typename std::remove_reference_t<Tuple>>>>
auto apply (Obj &&obj, F &&f, Tuple &&args) -> decltype(apply_(std::forward< Obj >(obj), std::forward< F >(f), std::forward< Tuple >(args), Seq()))
 Apply tuple to pointer to member. More...
 
template<typename Char >
int hex_char_to_int (Char c)
 Converts a hex digit to decimal int. More...
 
template<typename OutString = std::vector<uint8_t>>
OutString hex_decode (std::string_view const &in)
 
template<typename OutString = std::vector<uint8_t>>
OutString hex_decode (std::wstring_view const &in)
 
template<typename Char = char, bool Lowercase = true>
Char int_to_hex_char (int d)
 Converts an integer to the corresponding lowercase hex digit. More...
 
template<typename String , typename InString , bool Lowercase = true>
String hex_encode (InString const &data)
 
std::string base64_encode (std::string_view const &in, base64_type type=base64_type::standard, bool pad=true)
 Encodes raw input string to base64.
 
std::string base64_encode (std::vector< uint8_t > const &in, base64_type type=base64_type::standard, bool pad=true)
 
std::string base64_encode (fz::buffer const &in, base64_type type=base64_type::standard, bool pad=true)
 
void base64_encode_append (std::string &result, std::string_view const &in, base64_type type=base64_type::standard, bool pad=true)
 base64-encodes input and appends it to result. More...
 
std::vector< uint8_t > base64_decode (std::string_view const &in)
 Decodes base64, ignores whitespace. Returns empty string on invalid input. More...
 
std::vector< uint8_t > base64_decode (std::wstring_view const &in)
 
std::vector< uint8_t > base64_decode (fz::buffer const &in)
 
std::string base64_decode_s (std::string_view const &in)
 
std::string base64_decode_s (std::wstring_view const &in)
 
std::string base64_decode_s (fz::buffer const &in)
 
std::string base32_encode (std::string_view const &in, base32_type type=base32_type::standard, bool pad=true)
 Encodes raw input string to base32.
 
std::string base32_encode (std::vector< uint8_t > const &in, base32_type type=base32_type::standard, bool pad=true)
 
std::string base32_encode (fz::buffer const &in, base32_type type=base32_type::standard, bool pad=true)
 
std::vector< uint8_t > base32_decode (std::string_view const &in, base32_type type=base32_type::standard)
 Decodes base32, ignores whitespace. Returns empty string on invalid input. More...
 
std::vector< uint8_t > base32_decode (std::wstring_view const &in, base32_type type=base32_type::standard)
 
std::vector< uint8_t > base32_decode (fz::buffer const &in, base32_type type=base32_type::standard)
 
std::string base32_decode_s (std::string_view const &in, base32_type type=base32_type::standard)
 
std::string base32_decode_s (std::wstring_view const &in, base32_type type=base32_type::standard)
 
std::string base32_decode_s (fz::buffer const &in, base32_type type=base32_type::standard)
 
std::string percent_encode (std::string_view const &s, bool keep_slashes=false)
 Percent-encodes string. More...
 
std::string percent_encode (std::wstring_view const &s, bool keep_slashes=false)
 
std::wstring percent_encode_w (std::wstring_view const &s, bool keep_slashes=false)
 Percent-encodes wide-character. Non-ASCII characters are converted to UTF-8 before they are encoded. More...
 
std::vector< uint8_t > percent_decode (std::string_view const &s, bool allow_embedded_null=false)
 Percent-decodes string. More...
 
std::vector< uint8_t > percent_decode (std::wstring_view const &s, bool allow_embedded_null=false)
 
std::string percent_decode_s (std::string_view const &s, bool allow_embedded_null=false)
 
std::string percent_decode_s (std::wstring_view const &s, bool allow_embedded_null=false)
 
std::vector< uint8_t > encrypt (std::vector< uint8_t > const &plain, public_key const &pub, bool authenticated=true)
 Encrypt the plaintext to the given public key. More...
 
std::vector< uint8_t > encrypt (std::string_view const &plain, public_key const &pub, bool authenticated=true)
 
std::vector< uint8_t > encrypt (uint8_t const *plain, size_t size, public_key const &pub, bool authenticated=true)
 
std::vector< uint8_t > encrypt (std::vector< uint8_t > const &plain, public_key const &pub, std::vector< uint8_t > const &authenticated_data)
 
std::vector< uint8_t > encrypt (std::string_view const &plain, public_key const &pub, std::string_view const &authenticated_data)
 
std::vector< uint8_t > encrypt (uint8_t const *plain, size_t size, public_key const &pub, uint8_t const *authenticated_data, size_t authenticated_data_size)
 
std::vector< uint8_t > decrypt (std::vector< uint8_t > const &chiper, private_key const &priv, bool authenticated=true)
 Decrypt the ciphertext using the given private key. More...
 
std::vector< uint8_t > decrypt (std::string_view const &chiper, private_key const &priv, bool authenticated=true)
 
std::vector< uint8_t > decrypt (uint8_t const *cipher, size_t size, private_key const &priv, bool authenticated=true)
 
std::vector< uint8_t > decrypt (std::vector< uint8_t > const &cipher, private_key const &priv, std::vector< uint8_t > const &authenticated_data)
 
std::vector< uint8_t > decrypt (std::string_view const &cipher, private_key const &priv, std::string_view const &authenticated_data)
 
std::vector< uint8_t > decrypt (uint8_t const *cipher, size_t size, private_key const &priv, uint8_t const *authenticated_data, size_t authenticated_data_size)
 
bool operator== (symmetric_key const &lhs, symmetric_key const &rhs)
 Side-channel safe comparison.
 
bool operator!= (symmetric_key const &lhs, symmetric_key const &rhs)
 
std::vector< uint8_t > encrypt (std::vector< uint8_t > const &plain, symmetric_key const &key)
 Encrypt the plaintext using the given symmetric key. More...
 
std::vector< uint8_t > encrypt (std::string_view const &plain, symmetric_key const &key)
 
std::vector< uint8_t > encrypt (uint8_t const *plain, size_t size, symmetric_key const &key)
 
std::vector< uint8_t > encrypt (std::vector< uint8_t > const &plain, symmetric_key const &key, std::vector< uint8_t > const &authenticated_data)
 
std::vector< uint8_t > encrypt (std::string_view const &plain, symmetric_key const &key, std::string_view const &authenticated_data)
 
std::vector< uint8_t > encrypt (uint8_t const *plain, size_t size, symmetric_key const &key, uint8_t const *authenticated_data, size_t authenticated_data_size)
 
std::vector< uint8_t > decrypt (std::vector< uint8_t > const &chiper, symmetric_key const &key)
 Decrypt the ciphertext using the given symmetric key. More...
 
std::vector< uint8_t > decrypt (std::string_view const &chiper, symmetric_key const &key)
 
std::vector< uint8_t > decrypt (uint8_t const *cipher, size_t size, symmetric_key const &key)
 
std::vector< uint8_t > decrypt (std::vector< uint8_t > const &cipher, symmetric_key const &key, std::vector< uint8_t > const &authenticated_data)
 
std::vector< uint8_t > decrypt (std::string_view const &cipher, symmetric_key const &key, std::string_view const &authenticated_data)
 
std::vector< uint8_t > decrypt (uint8_t const *cipher, size_t size, symmetric_key const &key, uint8_t const *authenticated_data, size_t authenticated_data_size)
 
size_t get_unique_type_id (std::type_info const &id)
 
template<typename T >
bool same_type (event_base const &ev)
 
template<typename T , typename F >
bool dispatch (event_base const &ev, F &&f)
 Dispatch for simple_event<> based events to simple functors. More...
 
template<typename T , typename H , typename F >
bool dispatch (event_base const &ev, H *h, F &&f)
 Dispatch for simple_event<> based events to pointer to member. More...
 
template<typename T , typename ... Ts, typename H , typename F , typename ... Fs>
bool dispatch (event_base const &ev, H *h, F &&f, Fs &&... fs)
 Compound dispatch for simple_event<> based events. More...
 
bool remove_file (native_string const &name)
 remove the specified file. More...
 
file::creation_flags operator| (file::creation_flags lhs, file::creation_flags rhs)
 
file::creation_flagsoperator|= (file::creation_flags &lhs, file::creation_flags rhs)
 
template<typename... Args>
std::string sprintf (std::string_view const &fmt, Args &&... args)
 A simple type-safe sprintf replacement. More...
 
template<typename... Args>
std::wstring sprintf (std::wstring_view const &fmt, Args &&... args)
 
std::vector< uint8_t > md5 (std::string_view const &data)
 Standard MD5. More...
 
std::vector< uint8_t > md5 (std::vector< uint8_t > const &data)
 
std::vector< uint8_t > sha256 (std::string_view const &data)
 Standard SHA256.
 
std::vector< uint8_t > sha256 (std::vector< uint8_t > const &data)
 
std::vector< uint8_t > hmac_sha1 (std::string_view const &key, std::string_view const &data)
 Standard HMAC using SHA1. More...
 
std::vector< uint8_t > hmac_sha1 (std::vector< uint8_t > const &key, std::vector< uint8_t > const &data)
 
std::vector< uint8_t > hmac_sha1 (std::vector< uint8_t > const &key, std::string_view const &data)
 
std::vector< uint8_t > hmac_sha1 (std::string_view const &key, std::vector< uint8_t > const &data)
 
std::vector< uint8_t > hmac_sha256 (std::string_view const &key, std::string_view const &data)
 Standard HMAC using SHA256.
 
std::vector< uint8_t > hmac_sha256 (std::vector< uint8_t > const &key, std::vector< uint8_t > const &data)
 
std::vector< uint8_t > hmac_sha256 (std::vector< uint8_t > const &key, std::string_view const &data)
 
std::vector< uint8_t > hmac_sha256 (std::string_view const &key, std::vector< uint8_t > const &data)
 
std::vector< uint8_t > pbkdf2_hmac_sha256 (std::basic_string_view< uint8_t > const &password, std::basic_string_view< uint8_t > const &salt, size_t length, unsigned int iterations)
 
template<typename PasswordContainer , typename SaltContainer , std::enable_if_t< sizeof(typename PasswordContainer::value_type)==sizeof(uint8_t) &&sizeof(typename SaltContainer::value_type)==sizeof(uint8_t)> * = nullptr>
std::vector< uint8_t > pbkdf2_hmac_sha256 (PasswordContainer const &password, SaltContainer const &salt, size_t length, unsigned int iterations)
 
native_string current_username ()
 Returns the username the calling thread is running under.
 
template<typename F >
auto make_invoker (event_loop &loop, F &&f)
 Wraps the passed function, so that it is always invoked in the context of the loop. More...
 
template<typename F >
auto make_invoker (event_handler &h, F &&f)
 
invoker_factory get_invoker_factory (event_loop &loop)
 Creates an invoker factory. More...
 
template<typename F >
auto make_invoker (invoker_factory const &inv, F &&f)
 Creates an invoker using the given factory. More...
 
std::string get_ipv6_long_form (std::string_view const &short_address)
 Given a shortened IPv6 address, returns the full, unshortened address. More...
 
std::wstring get_ipv6_long_form (std::wstring_view const &short_address)
 
bool is_routable_address (std::string_view const &address)
 Tests whether the passed IP address is routable on the public Internet. More...
 
bool is_routable_address (std::wstring_view const &address)
 
address_type get_address_type (std::string_view const &address)
 Gets the type of the passed IP address.
 
address_type get_address_type (std::wstring_view const &address)
 
std::optional< std::vector< network_interface > > get_network_interfaces ()
 
json_array_iterator< false > begin (json &j)
 
json_array_iterator< false >::sentinel end (json &)
 
json_array_iterator< true > begin (json const &j)
 
json_array_iterator< true >::sentinel end (json const &)
 
std::pair< json, jsoncreate_jwk ()
 Creates a JWK pair. More...
 
json jws_sign_flattened (json const &priv, json const &payload, json const &extra_protected={})
 Create a JWS, with optional protected data. More...
 
result mkdir (native_string const &absolute_path, bool recurse, mkdir_permissions permissions=mkdir_permissions::normal, native_string *last_created=nullptr)
 Creates directory if it doesn't yet exist. More...
 
result remove_dir (native_string const &absolute_path)
 Removes sempty directory. More...
 
result rename_file (native_string const &source, native_string const &dest, bool allow_copy=true)
 Rename/move the passed file or directory. More...
 
null_loggerget_null_logger ()
 
bool spawn_detached_process (std::vector< native_string > const &cmd_with_args)
 Starts a detached process. More...
 
std::vector< uint8_t > sign (std::vector< uint8_t > const &message, private_signing_key const &priv, bool include_message=true)
 Returns the message with the signature appended, created using the passed private key.
 
std::vector< uint8_t > sign (std::string_view const &message, private_signing_key const &priv, bool include_message=true)
 
std::vector< uint8_t > sign (uint8_t const *message, size_t const size, private_signing_key const &priv, bool include_message=true)
 
bool verify (std::vector< uint8_t > const &message, public_verification_key const &pub)
 Verify a message with attached signature. Returns true iff it has been signed by the private key corresponding to the passed public key.
 
bool verify (std::string_view const &message, public_verification_key const &pub)
 
bool verify (uint8_t const *message, size_t const size, public_verification_key const &pub)
 
bool verify (std::vector< uint8_t > const &message, std::vector< uint8_t > const &signature, public_verification_key const &pub)
 Verify a message with detached signature. Returns true iff it has been signed by the private key corresponding to the passed public key.
 
bool verify (std::string_view const &message, std::string_view const &signature, public_verification_key const &pub)
 
bool verify (uint8_t const *message, size_t const message_size, uint8_t const *signature, size_t const sig_size, public_verification_key const &pub)
 
bool operator& (socket_event_flag lhs, socket_event_flag rhs)
 
socket_event_flag operator| (socket_event_flag lhs, socket_event_flag rhs)
 
socket_event_flagoperator|= (socket_event_flag &lhs, socket_event_flag rhs)
 
void remove_socket_events (event_handler *handler, socket_event_source const *const source)
 Remove all pending socket events from source sent to handler. More...
 
fz::socket_event_flag change_socket_event_handler (event_handler *old_handler, event_handler *new_handler, socket_event_source const *const source, fz::socket_event_flag remove)
 Changes all pending socket events from source. More...
 
std::string socket_error_string (int error)
 Gets a symbolic name for socket errors. More...
 
native_string socket_error_description (int error)
 Gets a human-readable, translated description of the error.
 
native_string to_native (std::string_view const &in)
 Converts std::string to native_string. More...
 
native_string to_native (std::wstring_view const &in)
 Convert std::wstring to native_string. More...
 
template<typename T , typename std::enable_if_t< std::is_same_v< native_string, typename std::decay_t< T >>, int > = 0>
native_string to_native (T const &in)
 Avoid converting native_string to native_string_view and back to native_string.
 
int stricmp (std::string_view const &a, std::string_view const &b)
 Locale-sensitive stricmp. More...
 
int stricmp (std::wstring_view const &a, std::wstring_view const &b)
 
template<typename Char >
Char tolower_ascii (Char c)
 Converts ASCII uppercase characters to lowercase as if C-locale is used. More...
 
template<>
std::wstring::value_type tolower_ascii (std::wstring::value_type c)
 
template<typename Char >
Char toupper_ascii (Char c)
 Converts ASCII lowercase characters to uppercase as if C-locale is used.
 
template<>
std::wstring::value_type toupper_ascii (std::wstring::value_type c)
 
std::string str_tolower_ascii (std::string_view const &s)
 tr_tolower_ascii does for strings what tolower_ascii does for individual characters
 
std::wstring str_tolower_ascii (std::wstring_view const &s)
 
std::string str_toupper_ascii (std::string_view const &s)
 
std::wstring str_toupper_ascii (std::wstring_view const &s)
 
bool equal_insensitive_ascii (std::string_view a, std::string_view b)
 Locale-insensitive stricmp. More...
 
bool equal_insensitive_ascii (std::wstring_view a, std::wstring_view b)
 
std::wstring to_wstring (std::string_view const &in)
 Converts from std::string in system encoding into std::wstring. More...
 
template<typename T >
auto to_wstring (T &&in) -> decltype(std::wstring(std::forward< T >(in)))
 Returns identity, that way to_wstring can be called with native_string. More...
 
template<typename Arg >
std::enable_if< std::is_arithmetic_v< std::decay_t< Arg > >, std::wstring >::type to_wstring (Arg &&arg)
 Converts from arithmetic type to std::wstring.
 
std::wstring to_wstring_from_utf8 (std::string_view const &in)
 Converts from std::string in UTF-8 into std::wstring. More...
 
std::wstring to_wstring_from_utf8 (char const *s, size_t len)
 
std::wstring to_wstring_from_utf8 (fz::buffer const &in)
 
std::string to_string (std::wstring_view const &in)
 Converts from std::wstring into std::string in system encoding. More...
 
template<typename T >
auto to_string (T &&in) -> decltype(std::string(std::forward< T >(in)))
 Returns identity, that way to_wstring can be called with native_string. More...
 
template<typename Arg >
std::enable_if< std::is_arithmetic_v< std::decay_t< Arg > >, std::string >::type to_string (Arg &&arg)
 Converts from arithmetic type to std::string.
 
template<typename Char >
size_t strlen (Char const *str)
 Returns length of 0-terminated character sequence. Works with both narrow and wide-characters.
 
std::string to_utf8 (std::string_view const &in)
 Converts from std::string in native encoding into std::string in UTF-8. More...
 
std::string to_utf8 (std::wstring_view const &in)
 Converts from std::wstring in native encoding into std::string in UTF-8. More...
 
template<typename String , typename Arg >
auto toString (Arg &&arg) -> typename std::enable_if< std::is_same_v< String, std::string >, decltype(to_string(std::forward< Arg >(arg)))>::type
 Calls either fz::to_string or fz::to_wstring depending on the passed template argument.
 
template<typename Char >
Char const * choose_string (char const *c, wchar_t const *w)
 Returns the function argument of the type matching the template argument. More...
 
template<>
char const * choose_string (char const *c, wchar_t const *)
 Returns the function argument of the type matching the template argument. More...
 
std::string replaced_substrings (std::string_view const &in, std::string_view const &find, std::string_view const &replacement)
 Returns in with all occurrences of find in the input string replaced with replacement. More...
 
std::wstring replaced_substrings (std::wstring_view const &in, std::wstring_view const &find, std::wstring_view const &replacement)
 
std::string replaced_substrings (std::string_view const &in, char find, char replacement)
 Returns in with all occurrences of find in the input string replaced with replacement.
 
std::wstring replaced_substrings (std::wstring_view const &in, wchar_t find, wchar_t replacement)
 
bool replace_substrings (std::string &in, std::string_view const &find, std::string_view const &replacement)
 Modifies in, replacing all occurrences of find with replacement. More...
 
bool replace_substrings (std::wstring &in, std::wstring_view const &find, std::wstring_view const &replacement)
 
bool replace_substrings (std::string &in, char find, char replacement)
 Modifies in, replacing all occurrences of find with replacement.
 
bool replace_substrings (std::wstring &in, wchar_t find, wchar_t replacement)
 
template<typename String , typename Delims >
 strtokenizer (String &&string, Delims &&delims, bool ignore_empty) -> strtokenizer< String, Delims >
 strtokenizer class construction-guide. More...
 
std::vector< std::string > strtok (std::string_view const &tokens, std::string_view const &delims, bool const ignore_empty=true)
 Tokenizes string. More...
 
std::vector< std::wstring > strtok (std::wstring_view const &tokens, std::wstring_view const &delims, bool const ignore_empty=true)
 
auto strtok (std::string_view const &tokens, char const delim, bool const ignore_empty=true)
 
auto strtok (std::wstring_view const &tokens, wchar_t const delim, bool const ignore_empty=true)
 
std::vector< std::string_view > strtok_view (std::string_view const &tokens, std::string_view const &delims, bool const ignore_empty=true)
 Tokenizes string. More...
 
std::vector< std::wstring_view > strtok_view (std::wstring_view const &tokens, std::wstring_view const &delims, bool const ignore_empty=true)
 
auto strtok_view (std::string_view const &tokens, char const delim, bool const ignore_empty=true)
 
auto strtok_view (std::wstring_view const &tokens, wchar_t const delim, bool const ignore_empty=true)
 
template<typename T >
to_integral (std::string_view const &s, T const errorval=T())
 Converts string to integral type T. If string is not convertible, errorval is returned.
 
template<typename T >
to_integral (std::wstring_view const &s, T const errorval=T())
 
template<typename T , typename StringType >
to_integral (std::basic_string_view< StringType > const &s, T const errorval=T())
 
template<typename String >
bool str_is_ascii (String const &s)
 Returns true iff the string only has characters in the 7-bit ASCII range.
 
std::string trimmed (std::string_view s, std::string_view const &chars=" \r\n\t", bool fromLeft=true, bool fromRight=true)
 Return passed string with all leading and trailing whitespace removed.
 
std::wstring trimmed (std::wstring_view s, std::wstring_view const &chars=L" \r\n\t", bool fromLeft=true, bool fromRight=true)
 
std::string ltrimmed (std::string_view s, std::string_view const &chars=" \r\n\t")
 
std::wstring ltrimmed (std::wstring_view s, std::wstring_view const &chars=L" \r\n\t")
 
std::string rtrimmed (std::string_view s, std::string_view const &chars=" \r\n\t")
 
std::wstring rtrimmed (std::wstring_view s, std::wstring_view const &chars=L" \r\n\t")
 
template<typename String , typename std::enable_if_t< std::is_same_v< typename String::value_type, char >, int > = 0>
void trim (String &s, std::string_view const &chars=" \r\n\t", bool fromLeft=true, bool fromRight=true)
 Remove all leading and trailing whitespace from string.
 
template<typename String , typename std::enable_if_t< std::is_same_v< typename String::value_type, wchar_t >, int > = 0>
void trim (String &s, std::wstring_view const &chars=L" \r\n\t", bool fromLeft=true, bool fromRight=true)
 
template<typename String , typename std::enable_if_t< std::is_same_v< typename String::value_type, char >, int > = 0>
void ltrim (String &s, std::string_view const &chars=" \r\n\t")
 
template<typename String , typename std::enable_if_t< std::is_same_v< typename String::value_type, wchar_t >, int > = 0>
void ltrim (String &s, std::wstring_view const &chars=L" \r\n\t")
 
template<typename String , typename std::enable_if_t< std::is_same_v< typename String::value_type, char >, int > = 0>
void rtrim (String &s, std::string_view const &chars=" \r\n\t")
 
template<typename String , typename std::enable_if_t< std::is_same_v< typename String::value_type, wchar_t >, int > = 0>
void rtrim (String &s, std::wstring_view const &chars=L" \r\n\t")
 
template<bool insensitive_ascii = false, typename String >
bool starts_with (String const &s, String const &beginning)
 Tests whether the first string starts with the second string. More...
 
template<bool insensitive_ascii = false, typename String >
bool ends_with (String const &s, String const &ending)
 Tests whether the first string ends with the second string. More...
 
std::string normalize_hyphens (std::string_view const &in)
 
std::wstring normalize_hyphens (std::wstring_view const &in)
 
bool is_valid_utf8 (std::string_view s)
 Verifies that the input data is valid UTF-8.
 
bool is_valid_utf8 (std::string_view s, size_t &state)
 Verifies that the input data is valid UTF-8. More...
 
void unicode_codepoint_to_utf8_append (std::string &result, uint32_t codepoint)
 Encodes a valid Unicode codepoint as UTF-8 and appends it to the passed string. More...
 
bool utf16be_to_utf8_append (std::string &result, std::string_view data, uint32_t &state)
 Converts from UTF-16-BE and appends it to the passed string. More...
 
bool utf16le_to_utf8_append (std::string &result, std::string_view data, uint32_t &state)
 Just as utf16be_to_utf8_append but for little-endian UTF-16.
 
native_string to_native_from_utf8 (std::string_view s)
 
duration operator- (duration const &a, duration const &b)
 
duration operator+ (duration const &a, duration const &b)
 
duration operator/ (duration const &a, int64_t b)
 
duration operator- (datetime const &a, datetime const &b)
 Gets the difference between two timestamps as duration. More...
 
duration operator- (monotonic_clock const &a, monotonic_clock const &b)
 
std::vector< x509_certificateload_certificates_file (native_string const &certsfile, bool pem, bool sort, logger_interface *logger=nullptr)
 Gets the certificate information for the certificates in the file. More...
 
std::vector< x509_certificateload_certificates (std::string_view const &certdata, bool pem, bool sort, logger_interface *logger=nullptr)
 
native_string check_certificate_status (std::string_view const &key, std::string_view const &certs, native_string const &password, bool pem=true)
 Checks that the key and certificates chain are valid and matching. More...
 
bool operator& (tls_server_flags lhs, tls_server_flags rhs)
 
tls_server_flags operator| (tls_server_flags lhs, tls_server_flags rhs)
 
void set_translators (std::wstring(*s)(char const *const t), std::wstring(*pf)(char const *const singular, char const *const plural, int64_t n))
 Sets translators for strings. More...
 
std::wstring translate (char const *const source)
 Translates the input string with the configured translator. More...
 
std::wstring translate (char const *const singular, char const *const plural, int64_t n)
 
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)
 
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
 
std::string get_version_string ()
 Get version string of libfilezilla.
 
std::tuple< int, int, int, int, std::string > get_version ()
 Get version of libfilezilla broken down into components major, minor, micro, nano and suffix.
 
bool operator& (file_writer_flags lhs, file_writer_flags rhs)
 
file_writer_flags operator| (file_writer_flags lhs, file_writer_flags rhs)
 
template<typename T , typename std::enable_if_t< std::is_same_v< wxString, typename std::decay_t< T >>, int > = 0>
std::wstring to_wstring (T const &s)
 
template<typename T , typename std::enable_if_t< std::is_same_v< wxString, typename std::decay_t< T >>, int > = 0>
std::string to_utf8 (T const &s)
 
template<typename T , typename std::enable_if_t< std::is_same_v< wxString, typename std::decay_t< T >>, int > = 0, typename... Args>
std::wstring sprintf (T const &fmt, Args &&... args)
 
template<typename F >
auto make_invoker (wxEvtHandler &handler, F &&f)
 Alternative version of fz::invoke that accepts wxEvtHandler.
 
invoker_factory get_invoker_factory (wxEvtHandler &handler)
 Returns an invoker factory utilizing the event system of of wx.
 

Detailed Description

The namespace used by libfilezilla.

All declarations in any libfilezilla header are in this namespace.

Typedef Documentation

◆ certificate_verification_event

typedef simple_event<certificate_verification_event_type, tls_layer*, tls_session_info> certificate_verification_event

This event gets sent during the handshake with details about the session and the used certificate.

After receiving this event, tls_layer::set_verification_result needs to be called eventually.

◆ hostaddress_event

typedef simple_event<hostaddress_event_type, socket_event_source*, std::string> hostaddress_event

Whenever a hostname has been resolved to an IP address, this event is sent with the resolved IP address literal.

◆ native_string

typedef std::string native_string

A string in the system's native character type and encoding.
Note: This typedef changes depending on platform!

On Windows, the system's native encoding is UTF-16, so native_string is typedef'ed to std::wstring.

On all other platform, native_string is a typedef for std::string.

Always using native_string has the benefit that no conversion needs to be performed which is especially useful if dealing with filenames.

◆ process_event

typedef simple_event<process_event_type, process*, process_event_flag> process_event

All processevents are sent through this.

See also
fz::process_event_flag

Read and write events are edge-triggered:

  • After receiving a read event for a process, it will not be sent again unless a subsequent call to process::read has returned EAGAIN.
  • The same holds for the write event and process::write

It is a grave violation to call the read/write functions again after they returned EAGAIN without first waiting for the event.

◆ shared_value

using shared_value = shared_optional<T, true>

like shared_optional but can never be empty

All operations that would result in an empty shared_optional instead result in a default-constructed value.

As such, operator* and operator-> are always well-defined.

◆ socket_event

typedef simple_event<socket_event_type, socket_event_source*, socket_event_flag, int> socket_event

All socket events are sent through this.

See also
fz::socket_event_flag

If the error value is non-zero for the connection, read and write events, the socket has failed and needs to be closed. Doing anything else with failed sockets is undefined behavior. Failure events can be received at any time.

Read and write events are edge-triggered:

  • After receiving a read event for a socket, it will not be sent again unless a subsequent call to socket_interface::read or socket_interface::shutdown_read has returned EAGAIN.
  • The same holds for the write event and socket_interface::write and socket_interface::shutdown
  • A successful connection events doubles as write event, it does not act as read event

It is a grave violation to call the read/write/shutdown functions again after they returned EAGAIN without first waiting for the event.

◆ timer_event

typedef simple_event<timer_event_type, timer_id> timer_event

All timer events have this type.

All timer events have one arguments of type timer_id which is the id of the timer that triggered.

Enumeration Type Documentation

◆ aio_result

enum aio_result
strong

Result of aio operations.

Enumerator
ok 

Success, proceed.

wait 

Must wait on being signalled before either retrying or continuing, exact semantics depend on the function returning this value.

error 

Operationf failed.

◆ base32_type

enum base32_type
strong

Alphabet variations for base32.

  • standard: A-Z2-7 as per RFC4648
  • base32hex: Tricontakaidecimal, natural extension of hex with letters G through V
  • locale_safe: Does not contain the letter i

◆ base64_type

enum base64_type
strong

Alphabet variations for base64.

  • standard: Alphabet with / and + as chars 62 and 63
  • url: - and _

◆ json_type

enum json_type
strong

Types of JSON values.

Enumerator
null 

Not a JSON value.

object 

The explicit null value.

◆ listen_socket_state

enum listen_socket_state
strong
Enumerator
none 

How the socket is initially.

listening 

Only in listening state you can get a connection event.

◆ mkdir_permissions

enum mkdir_permissions
strong
Enumerator
normal 

Normal permissions, on MSW this means inheriting the parent's permissions, on *nix the current umask is applied.

cur_user 

Only current user.

cur_user_and_admins 

Only current user and administrators.

◆ process_event_flag

enum process_event_flag
strong

The type of a process event.

In received events, exactly a single bit is always set.

Enumerator
read 

Data has become available.

write 

data can be written.

◆ socket_event_flag

enum socket_event_flag
strong

The type of a socket event.

In received events, exactly a single bit is always set.

Flag combinations are used when changing event handlers,

See also
f::socket::set_event_handler
Enumerator
connection_next 

Sent if connection attempt has failed, but there are still additional addresses to try. Errors can be ignored for this type.

connection 

If no error is set, the connection has been established. If an error is set, the connection could not be established.

read 

If no error is set, data has become available. If an error is set, the connection has failed.

write 

If no error is set, data can be written. If an error is set, the connection has failed.

◆ socket_state

enum socket_state : unsigned char
strong

State transitions are monotonically increasing.

Enumerator
none 

How the socket is initially.

connecting 

Only in connecting state you can get a connection event. After sending the event, socket is in connected or failed state depending whether error value is set in the event.

connected 

Socket is in its normal working state. You can get send and receive events.

shutting_down 

Shutting down of the write side. Transitions to shutdown with a single write event.

shut_down 

Write side has finished shutting down. Receive still working normally.

closed 

Socket has been closed. Further events disabled.

failed 

Socket has failed. Further events disabled.

◆ tls_server_flags

enum tls_server_flags : unsigned int
strong
Enumerator
no_auto_ticket 

In TLS 1.3, do not automatically send PSKs after finishing handshake. Ignored if not TLS 1.3.

Function Documentation

◆ apply()

auto fz::apply ( Obj &&  obj,
F &&  f,
Tuple &&  args 
) -> decltype(apply_(std::forward<Obj>(obj), std::forward<F>(f), std::forward<Tuple>(args), Seq()))

Apply tuple to pointer to member.

Example:

struct object {
int f(int value, std::string const& str) const { return value + str.size(); }
};
object o;
auto t = std::make_tuple(5, std::string("Hello!"));
int v = fz::apply(&o, &object::f, t);
// v is now 11
auto apply(Obj &&obj, F &&f, Tuple &&args) -> decltype(apply_(std::forward< Obj >(obj), std::forward< F >(f), std::forward< Tuple >(args), Seq()))
Apply tuple to pointer to member.
Definition: apply.hpp:48
@ object
The explicit null value.

◆ base32_decode()

std::vector<uint8_t> fz::base32_decode ( std::string_view const &  in,
base32_type  type = base32_type::standard 
)

Decodes base32, ignores whitespace. Returns empty string on invalid input.

Padding is optional.

◆ base64_decode()

std::vector<uint8_t> fz::base64_decode ( std::string_view const &  in)

Decodes base64, ignores whitespace. Returns empty string on invalid input.

Padding is optional, alphabet is auto-detected.

◆ base64_encode_append()

void fz::base64_encode_append ( std::string &  result,
std::string_view const &  in,
base64_type  type = base64_type::standard,
bool  pad = true 
)

base64-encodes input and appends it to result.

Multiple inputs concatenated this way cannot be passed to a single base64_decode. The parts need to be individually decoded.

◆ bitscan()

uint64_t fz::bitscan ( uint64_t  v)

Returns index of the least-significant set bit.

For example bitscan(12) returns 2

Undefined if called with 0

◆ bitscan_reverse()

uint64_t fz::bitscan_reverse ( uint64_t  v)

Returns index of the most-significant set bit.

For example bitscan_reverse(12) returns 3

Undefined if called with 0

◆ change_socket_event_handler()

fz::socket_event_flag fz::change_socket_event_handler ( event_handler old_handler,
event_handler new_handler,
socket_event_source const *const  source,
fz::socket_event_flag  remove 
)

Changes all pending socket events from source.

If newHandler is null, remove_socket_events is called.

This function is called by socket::set_event_handler().

Example use-cases: Handoff after proxy handshakes, or handoff to TLS classes in case of STARTTLS mechanism

Returns which events are still pending.

◆ check_certificate_status()

native_string fz::check_certificate_status ( std::string_view const &  key,
std::string_view const &  certs,
native_string const &  password,
bool  pem = true 
)

Checks that the key and certificates chain are valid and matching.

If the password is non-empty, the private key is assumed to having been encrypted using it.

If the pem flag is set, the input is assumed to be in PEM, otherwise DER.

Returns an error string. If empty, then the check was successful.

◆ choose_string() [1/2]

wchar_t const * choose_string ( char const *  c,
wchar_t const *  w 
)
inline

Returns the function argument of the type matching the template argument.

See also
fzS

◆ choose_string() [2/2]

Char const* fz::choose_string ( char const *  c,
wchar_t const *  w 
)
inline

Returns the function argument of the type matching the template argument.

See also
fzS

◆ create_jwk()

std::pair<json, json> fz::create_jwk ( )

Creates a JWK pair.

Using EC key type with P-256 as algorithm.

Returns both the private key and the public key as JSON structurs.

◆ decrypt() [1/2]

std::vector<uint8_t> fz::decrypt ( std::vector< uint8_t > const &  chiper,
private_key const &  priv,
bool  authenticated = true 
)

Decrypt the ciphertext using the given private key.

Parameters
privThe private key matching the public key that was originally used to encrypt the data
authenticatedif true, authenticated encryption is used.
Returns
plaintext on success, empty container on failure
Decryption algorithm:

Let M_priv be the key portion and S_m be the salt portion of the priv parameter and C the ciphertext.

  • First C is split into E_pub, S_e, C' and T such that
    C: = E_pub || S_e || C' || T
  • M_pub is calculated from M_priv
  • Using ECDH on Curve25519 (X25519), the shared secret R is recovered:
    R := X25519(M_priv, E_pub)
  • From R, a symmetric AES256 key K and a nonce IV are derived:
    • K := SHA256(S_e || 0 || S || E_pub || M_pub || S_m)
    • IV := SHA256(S_e || 2 || S || E_pub || M_pub || S_m) if authenticated,
      IV := SHA256(S_e || 1 || S || E_pub || M_pub || S_m) otherwise
  • The ciphertext is decrypted into the plaintext P using
    P, T' := AES256-GCM(K, IV, C') if authenticated,
    P := AES256-CTR(K, IV, C'), T:='' otherwise
  • If the calculated T' matches T, then P is returned, otherwise decryption has failed and nothing is returned.

◆ decrypt() [2/2]

std::vector<uint8_t> fz::decrypt ( std::vector< uint8_t > const &  chiper,
symmetric_key const &  key 
)

Decrypt the ciphertext using the given symmetric key.

Parameters
privThe symmetric key that was originally used to encrypt the data
Returns
plaintext on success, empty container on failure
Decryption algorithm:

Let M be the key portion and S be the salt portion of the priv parameter and C the ciphertext.

  • First C is split into N, C' and T such that
    C: = N || C' || T
  • From N an AES key K and an IV are derived:
    • K := SHA256(S || 3 || M || N)
    • IV := SHA256(S || 4 || M || N)
  • The ciphertext is decrypted into the plaintext P using
    P, T' := AES256-GCM(K, IV, C')
  • If the calculated T' matches T, then P is returned, otherwise decryption has failed and nothing is returned.

◆ dispatch() [1/3]

bool fz::dispatch ( event_base const &  ev,
F &&  f 
)

Dispatch for simple_event<> based events to simple functors.

Template Parameters
Tthe event type, a simple_event<> instantiation
Parameters
evthe received event
ffunctor that should be called if the event matches the passed type.

If the passed event is of the type passed as template argument, the passed function is called with the contents of the event unpacked as arguments.

Returns
true iff event matches passed type.
See also
event_handler for complete usage example.

◆ dispatch() [2/3]

bool fz::dispatch ( event_base const &  ev,
H *  h,
F &&  f 
)

Dispatch for simple_event<> based events to pointer to member.

Template Parameters
Tthe event type, a simple_event<> instantiation
Parameters
evthe received event.
hobject whose member gets called if the event matches the passed type.
fpointer to member of h that should be called if the event matches the passed type.

If the passed event is of the type passed as template argument, the passed function is called with the contents of the event unpacked as arguments.

Returns
true iff event matches passed type.
See also
event_handler for complete usage example.

◆ dispatch() [3/3]

bool fz::dispatch ( event_base const &  ev,
H *  h,
F &&  f,
Fs &&...  fs 
)

Compound dispatch for simple_event<> based events.

Calls the simple dispatch for each passed type and tries the next one if it didn't match.

Order the passed types in decreasing usage frequency for maximum performance.

Template Parameters
Tthe event type, a simple_event<> instantiation
Tsadditional event types
Parameters
evthe received event.
hobject whose member gets called if the event matches the passed type.
fpointer to member of h that should be called if the event matches the passed type.
fsadditional pairs of objects and pointers to members.
Returns
true iff event matched a passed type.
See also
event_handler for complete usage example.

◆ encrypt() [1/2]

std::vector<uint8_t> fz::encrypt ( std::vector< uint8_t > const &  plain,
public_key const &  pub,
bool  authenticated = true 
)

Encrypt the plaintext to the given public key.

Parameters
authenticatedif true, authenticated encryption is used.
Encryption algorithm:

Let M_pub be the key portion, S_e be the salt portion of the pub parameter and P be the plaintext.

  • First an ephemeral private key E_priv with corresponding public key E_pub and S_e is randomly generated
  • Using ECDH on Curve25519 (X25519), a shared secret R is derived:
    R := X25519(E_priv, M_pub)
  • From R, a symmetric AES256 key K and a nonce IV are derived:
    • K := SHA256(S_e || 0 || S || E_pub || M_pub || S_m)
    • IV := SHA256(S_e || 2 || S || E_pub || M_pub || S_m) if authenticated,
      IV := SHA256(S_e || 1 || S || E_pub || M_pub || S_m) otherwise
  • The plaintext is encrypted into the ciphertext C' and authentication tag T using
    C', T := AES256-GCM(K, IV, P) if authenticated,
    C' := AES256-CTR(K, IV, P) T:='' otherwise
  • The ciphertext C is returned, containing E_pub, S_e and T:
    C := E_pub || S_e || C' || T

◆ encrypt() [2/2]

std::vector<uint8_t> fz::encrypt ( std::vector< uint8_t > const &  plain,
symmetric_key const &  key 
)

Encrypt the plaintext using the given symmetric key.

Encryption algorithm:

Let M be the key portion, S be the salt portion of the key parameter and P be the plaintext.

  • First a ranodm nonce N is created from which an AES key K and an IV are derived:
    • K := SHA256(S || 3 || M || N)
    • IV := SHA256(S || 4 || M || N)
  • The plaintext is encrypted into the ciphertext C' and authentication tag T using
    C', T := AES256-GCM(K, IV, P)
  • The ciphertext C is returned, containing N and T:
    C := N || C' || T

◆ ends_with()

bool fz::ends_with ( String const &  s,
String const &  ending 
)

Tests whether the first string ends with the second string.

Template Parameters
insensitive_asciiIf true, comparison is case-insensitive

◆ equal_consttime()

bool fz::equal_consttime ( std::basic_string_view< uint8_t > const &  lhs,
std::basic_string_view< uint8_t > const &  rhs 
)

Secure equality test in constant time.

As long as both inputs are of the same size, comparison is done in constant time to prevent timing attacks.

◆ equal_insensitive_ascii()

bool fz::equal_insensitive_ascii ( std::string_view  a,
std::string_view  b 
)
inline

Locale-insensitive stricmp.

Equivalent to str_tolower_ascii(a).compare(str_tolower_ascii(b));

◆ get_invoker_factory()

invoker_factory fz::get_invoker_factory ( event_loop loop)

Creates an invoker factory.

It is slower than building an invoker directly. Only use this if the abstraction is needed.

◆ get_ipv6_long_form()

std::string fz::get_ipv6_long_form ( std::string_view const &  short_address)

Given a shortened IPv6 address, returns the full, unshortened address.

If passed address is encloded in square brackets, they are stripped.

Returns an empty string if the passed string isn't a valid IPv6 address.

◆ get_unique_type_id()

size_t fz::get_unique_type_id ( std::type_info const &  id)

Maps a type info to a unique identifier even across DLL boundaries

◆ hex_char_to_int()

int fz::hex_char_to_int ( Char  c)

Converts a hex digit to decimal int.

Example: '9' becomes 9, 'b' becomes 11, 'D' becomes 13

Returns -1 if input is not a valid hex digit.

◆ hmac_sha1()

std::vector<uint8_t> fz::hmac_sha1 ( std::string_view const &  key,
std::string_view const &  data 
)

Standard HMAC using SHA1.

While HMAC-SHA1 (as opposed to plain SHA1) is still considered secure in 2021, avoid using this for new things

◆ int_to_hex_char()

Char fz::int_to_hex_char ( int  d)

Converts an integer to the corresponding lowercase hex digit.

Example: 9 becomes '9', 11 becomes 'b'

Undefined output if input is less than 0 or larger than 15

◆ is_routable_address()

bool fz::is_routable_address ( std::string_view const &  address)

Tests whether the passed IP address is routable on the public Internet.

Unroutable addresss are:

  • Invalid addresses
  • ::/128 (the unspecified address)
  • ::1/128 (localhost)
  • fe80::/10 (link-local)
  • fc00::/7 (unique local)
  • 127.0.0.0/8 (localhost)
  • 10.0.0.0/8 (private)
  • 172.16.0.0/12 (private)
  • 192.168.0.0/16 (private)
  • 169.254.0.0/16 (link-local)

All other addresses are assumed routable.

◆ is_valid_utf8()

bool fz::is_valid_utf8 ( std::string_view  s,
size_t &  state 
)

Verifies that the input data is valid UTF-8.

The verfication state is exposed, you can use this function to verify data to be in UTF-8 in a piecewise fashion. When starting verification, initialize state with 0 and call the function for as many blocks of data as needed, each time passing the previously updated state along.

If the input data on any particular call ends in the midlde of a UTF-8 sequence, state is updated, so that the the check can continue with the next block of data.

Once you have no data left to verify, check that the state is zero. If it is non-zero, the input data was prematurely terminated in the middle of a UTF-8 sequence.

If the input data is invalid, the function returns false and state is updated with the offset of the offending input byte.

◆ jws_sign_flattened()

json fz::jws_sign_flattened ( json const &  priv,
json const &  payload,
json const &  extra_protected = {} 
)

Create a JWS, with optional protected data.

Only supports EC keys using P-256. Signature algorithm is ES256.

Returns the signature in the flattened JSON JWS representation.

Any values passed through an object in the extra_protected are included in the JWS protected headers.

Does not use the JWS Unprotected Header.

◆ load_certificates_file()

std::vector<x509_certificate> fz::load_certificates_file ( native_string const &  certsfile,
bool  pem,
bool  sort,
logger_interface logger = nullptr 
)

Gets the certificate information for the certificates in the file.

If the sort flag is not set, certificates are returned in input order. If the sort flag is set, a chain is built, with certificate i signed by i+1. If building the chain fails, nothing is returned.

◆ make_invoker() [1/2]

auto fz::make_invoker ( event_loop loop,
F &&  f 
)

Wraps the passed function, so that it is always invoked in the context of the loop.

Returns a std::function with the same arguments as the passed function. The returned function can be called in any thread, as result the passed function is called asynchronously with the same arguments in the loop's thread.

◆ make_invoker() [2/2]

auto fz::make_invoker ( invoker_factory const &  inv,
F &&  f 
)

Creates an invoker using the given factory.

Allows creating invokers independent of fz::event_loop, useful when interfacing with third-party event loops such as GUI frameworks, see also glue/wxinvoker.hpp

◆ md5()

std::vector<uint8_t> fz::md5 ( std::string_view const &  data)

Standard MD5.

Insecure, avoid using this

◆ mkdir()

result fz::mkdir ( native_string const &  absolute_path,
bool  recurse,
mkdir_permissions  permissions = mkdir_permissions::normal,
native_string last_created = nullptr 
)

Creates directory if it doesn't yet exist.

If current_user_only is set, the directory is created with permissions so that only the current user has access, otherwise the default permissions are used.

This function only works with absolute paths.

Parameters
absolute_pathThe directory to create
recurseIf true, creation is recursive. If false, only the last segment gets created, all other components already need to exist.
permissionsWhen creating the last component, these permissions are applied. Does not change existing permissions or permissings of newly created parent directories during recursive mkdir.
last_createdIf non-null, receives the longest sub-path that was created

◆ move_assign_through_move_constructor()

T& fz::move_assign_through_move_constructor ( T *  p,
T &&  op 
)
noexcept

/brief Helper to move-assign guaranteeing same member destruction order as the destructor.

The implicity-defined move operator performs a member-wise move (class.copy.assign 15.8.2.12 in the C++17 standard), which can lead to members being destroyed in construction order, e.g. if moving a std::unique_ptr

If the members depend on being destroyed in destruction order, by default the reverse default construction order, the implicitly-defined move operator cannot be used.

By first explicitly destructing the moved-to instance and then placement move-constructing it from the moved-from instance, correct destruction order is guaranteed.

◆ normalize_hyphens()

std::string fz::normalize_hyphens ( std::string_view const &  in)

Normalizes various hyphens, dashes and minuses to just hyphen-minus.

The narrow version assumes UTF-8 as encoding.

◆ operator-() [1/2]

duration operator- ( datetime const &  a,
datetime const &  b 
)

Gets the difference between two timestamps as duration.

This function ignores accuracy, it treats both timestamps as if they had millisecond-accuracy.

◆ operator-() [2/2]

duration operator- ( monotonic_clock const &  a,
monotonic_clock const &  b 
)
inline

Gets the difference between two clocks as duration

◆ percent_decode()

std::vector<uint8_t> fz::percent_decode ( std::string_view const &  s,
bool  allow_embedded_null = false 
)

Percent-decodes string.

If the string cannot be decoded, an empty string is returned.

◆ percent_encode()

std::string fz::percent_encode ( std::string_view const &  s,
bool  keep_slashes = false 
)

Percent-encodes string.

The characters A-Z, a-z, 0-9, hyphen, underscore, period, tilde are not percent-encoded, optionally slashes aren't encoded either. Every other character is encoded.

Parameters
keep_slashesIf set, slashes are not encoded.

◆ percent_encode_w()

std::wstring fz::percent_encode_w ( std::wstring_view const &  s,
bool  keep_slashes = false 
)

Percent-encodes wide-character. Non-ASCII characters are converted to UTF-8 before they are encoded.

See also
fz::percent_encode

◆ random_bytes()

std::vector<uint8_t> fz::random_bytes ( size_t  size)

Get random uniformly distributed bytes.

If generation of random bytes fails, the program is aborted.

◆ random_number()

int64_t fz::random_number ( int64_t  min,
int64_t  max 
)

Get a secure random integer uniformly distributed in the closed interval [min, max].

If generation of random number fails, the program is aborted.

◆ remove_dir()

result fz::remove_dir ( native_string const &  absolute_path)

Removes sempty directory.

For recursive remove, see fz::recursive_remove

◆ remove_file()

bool fz::remove_file ( native_string const &  name)

remove the specified file.

Returns
true iff the file has been removed or did not exist to begin with.

◆ remove_socket_events()

void fz::remove_socket_events ( event_handler handler,
socket_event_source const *const  source 
)

Remove all pending socket events from source sent to handler.

Useful e.g. if you want to destroy the handler but keep the source. This function is called, through change_socket_event_handler, by socket::set_event_handler(0)

◆ rename_file()

result fz::rename_file ( native_string const &  source,
native_string const &  dest,
bool  allow_copy = true 
)

Rename/move the passed file or directory.

Can rename both files and directories within same filesystem. Can optionally rename files across filesystems

If renaming a file, the target file is overwritten.

Directories cannot be renamed/moved across differnet filesystems/mount points

param allow_copy If true, files, but not directories, can be moved across file system boundaries. It first copies the file before deleting the old one.

◆ replace_substrings()

bool fz::replace_substrings ( std::string &  in,
std::string_view const &  find,
std::string_view const &  replacement 
)

Modifies in, replacing all occurrences of find with replacement.

  • find If empty, no replacement takes place.

◆ replaced_substrings()

std::string fz::replaced_substrings ( std::string_view const &  in,
std::string_view const &  find,
std::string_view const &  replacement 
)

Returns in with all occurrences of find in the input string replaced with replacement.

  • find If empty, no replacement takes place.

◆ same_type()

bool fz::same_type ( event_base const &  ev)

Used as lightweight RTTI alternative during dispatch

Returns
true iff T& t = ...; t.derived_type() == ev.derived_type()

◆ set_translators()

void fz::set_translators ( std::wstring(*)(char const *const t)  s,
std::wstring(*)(char const *const singular, char const *const plural, int64_t n)  pf 
)

Sets translators for strings.

You could pass functions that in turn call gettext/ngettext

◆ sleep()

void fz::sleep ( duration const &  d)

Sleep current thread for the specified duration.

Alternative to std::this_thread::sleep_for which unfortunately isn't implemented on MinGW.

Note
May wake up early, e.g. due to a signal. You can use monotonic_clock to check elapsed time and sleep again if needed.

◆ socket_error_string()

std::string fz::socket_error_string ( int  error)

Gets a symbolic name for socket errors.

For example, error_string(EAGAIN) == "EAGAIN"

Returns
name if the error code is known
number as string if the error code is not known

◆ spawn_detached_process()

bool fz::spawn_detached_process ( std::vector< native_string > const &  cmd_with_args)

Starts a detached process.

This function takes care of properly quoting and escaping the the program's path and its arguments.

Parameters
cmd_with_argsThe full path of the program to execute and any additional arguments
Note
May return true even if the process cannot be started.

◆ sprintf()

std::string fz::sprintf ( std::string_view const &  fmt,
Args &&...  args 
)

A simple type-safe sprintf replacement.

Only partially implements the format specifiers for the printf family of C functions:

  • Positional arguments
  • Supported flags: 0, ' ', -, +
  • Field widths are supported as decimal integers not exceeding 10k, longer widths are truncated
  • precision is ignored
  • Supported types: d, i, u, s, x, X, p

For string arguments, mixing char*, wchar_t*, std::string and std::wstring is allowed. Converstion to/from narrow strings is using the locale's encoding.

Asserts if unsupported types are passed or if the types don't match the arguments. Fails gracefully with NDEBUG.

Example:

std::string s = fz::printf("%2$s %1$s", "foo", std::wstring("bar");
assert(s == "bar foo"); // This is true

◆ starts_with()

bool fz::starts_with ( String const &  s,
String const &  beginning 
)

Tests whether the first string starts with the second string.

Template Parameters
insensitive_asciiIf true, comparison is case-insensitive

◆ stricmp()

int fz::stricmp ( std::string_view const &  a,
std::string_view const &  b 
)

Locale-sensitive stricmp.

Like std::string::compare but case-insensitive, respecting locale.

Note
does not handle embedded null

◆ strtok()

std::vector<std::string> fz::strtok ( std::string_view const &  tokens,
std::string_view const &  delims,
bool const  ignore_empty = true 
)

Tokenizes string.

Parameters
delimsthe delimiters to look for
ignore_emptyIf true, empty tokens are omitted in the output

◆ strtok_view()

std::vector<std::string_view> fz::strtok_view ( std::string_view const &  tokens,
std::string_view const &  delims,
bool const  ignore_empty = true 
)

Tokenizes string.

Warning
This function returns string_views, mind the lifetime of the string passed in tokens.
Parameters
delimsthe delimiters to look for
ignore_emptyIf true, empty tokens are omitted in the output

◆ strtokenizer()

fz::strtokenizer ( String &&  string,
Delims &&  delims,
bool  ignore_empty 
) -> strtokenizer< String, Delims >

strtokenizer class construction-guide.

Parameters
delimsthe delimiters to look for
ignore_emptyIf true, empty tokens are omitted in the output

◆ to_native() [1/2]

native_string fz::to_native ( std::string_view const &  in)

Converts std::string to native_string.

Returns
the converted string on success. On failure an empty string is returned.
Examples
list.cpp, nonblocking_process.cpp, process.cpp, and raw_https.cpp.

◆ to_native() [2/2]

native_string fz::to_native ( std::wstring_view const &  in)

Convert std::wstring to native_string.

Returns
the converted string on success. On failure an empty string is returned.

◆ to_string() [1/2]

std::string fz::to_string ( std::wstring_view const &  in)

Converts from std::wstring into std::string in system encoding.

Returns
the converted string on success. On failure an empty string is returned.
Examples
list.cpp, and raw_https.cpp.

◆ to_string() [2/2]

auto fz::to_string ( T &&  in) -> decltype(std::string(std::forward<T>(in)))
inline

Returns identity, that way to_wstring can be called with native_string.

This template deals with string literals, std::string and std::string_view parameters.

◆ to_utf8() [1/2]

std::string fz::to_utf8 ( std::string_view const &  in)

Converts from std::string in native encoding into std::string in UTF-8.

Returns
the converted string on success. On failure an empty string is returned.
Note
Does not handle embedded nulls

◆ to_utf8() [2/2]

std::string fz::to_utf8 ( std::wstring_view const &  in)

Converts from std::wstring in native encoding into std::string in UTF-8.

Returns
the converted string on success. On failure an empty string is returned.
Note
Does not handle embedded nulls

◆ to_wstring() [1/2]

std::wstring fz::to_wstring ( std::string_view const &  in)

Converts from std::string in system encoding into std::wstring.

Returns
the converted string on success. On failure an empty string is returned.
Examples
aio.cpp.

◆ to_wstring() [2/2]

auto fz::to_wstring ( T &&  in) -> decltype(std::wstring(std::forward<T>(in)))
inline

Returns identity, that way to_wstring can be called with native_string.

This template deals with wide string literals, std::wstring and std::wstring_view parameters.

◆ to_wstring_from_utf8()

std::wstring fz::to_wstring_from_utf8 ( std::string_view const &  in)

Converts from std::string in UTF-8 into std::wstring.

Returns
the converted string on success. On failure an empty string is returned.

◆ tolower_ascii()

Char fz::tolower_ascii ( Char  c)

Converts ASCII uppercase characters to lowercase as if C-locale is used.

Under some locales there is a different case-relationship between the letters a-z and A-Z as one expects from ASCII under the C locale. In Turkish for example there are different variations of the letter i, namely dotted and dotless. What we see as 'i' is the lowercase dotted i and 'I' is the uppercase dotless i. Since std::tolower is locale-aware, I would become the dotless lowercase i.

This is not always what we want. FTP commands for example are case-insensitive ASCII strings, LIST and list are the same.

tolower_ascii instead converts all types of 'i's to the ASCII i as well.

Returns
A-Z becomes a-z.
In addition dotless lowercase i and dotted uppercase i also become the standard i.

◆ translate()

std::wstring fz::translate ( char const *const  source)

Translates the input string with the configured translator.

Returns the untranslated string is if no translator has previously been configured

◆ unicode_codepoint_to_utf8_append()

void fz::unicode_codepoint_to_utf8_append ( std::string &  result,
uint32_t  codepoint 
)

Encodes a valid Unicode codepoint as UTF-8 and appends it to the passed string.

Undefined if not passed a valid codepoint.

◆ utf16be_to_utf8_append()

bool fz::utf16be_to_utf8_append ( std::string &  result,
std::string_view  data,
uint32_t &  state 
)

Converts from UTF-16-BE and appends it to the passed string.

The conversion state is exposed, you can use this function to convert data to UTF-8 in a piecewise fashion. When starting conversion, initialize state with 0 and call the function for as many blocks of data as needed, each time passing the previously updated state along.

If the input data on any particular call ends in the midlde of a UTF-16 sequence, state is updated, so that the conversion can continue at the next iteration.

Once you have no data left to convert, check that the state is zero. If it is non-zero, the input data was prematurely terminated in the middle of a UTF-16 sequence.

If the input data is invalid, the function returns false and state is updated with the offset of the offending input byte.

◆ yield()

void fz::yield ( )

Relinquish control for a brief amount of time.

The exact duration is unspecified.