#ifndef UTILS_H #define UTILS_H #include #ifdef _WIN32 #include #include #include "win32shim.h" #else #include #include "sys/socket.h" #include #endif #include #include #include #include #include #include #include #include #define HMAC_SHA1_BLOCKSIZE 64 /** * @brief Returns current timestamp * * @return unsigned long long resulting timestamp in milliseconds from unix time zero */ unsigned long long getCurrentTimestamp(); /** * @brief portable 64bit equivalent of htons / htonl. aka endianess swap * * @param value input value to swap * @return uint64_t swapped result */ uint64_t hton64(uint64_t value); /** * @brief Performs big number multiplication on two numbers * * @param num big num in vector format * @param n secondary number * @return std::vector resulting number */ std::vector bigNumMultiply(std::vector num, int n); /** * @brief Performs big number addition on two numbers * * @param num big num in vector format * @param n secondary number * @return std::vector resulting number */ std::vector bigNumAdd(std::vector num, int n); unsigned char h2int(char c); std::string urlDecode(std::string str); /** * @brief Converts provided bytes into a human readable hex string * * @param bytes vector containing binary data * @return std::string string containing hex representation of inputted data */ std::string bytesToHexString(std::vector &bytes); /** * @brief Extracts given type from binary data * * @tparam T type to extract * @param v vector containing binary data to extract from * @param pos position offset * @return T extracted type */ template T extract(const std::vector &v, int pos) { T value; memcpy(&value, &v[pos], sizeof(T)); return value; } /** * @brief Packs given type into binary data * * @tparam T type of data to pack * @param data data to pack * @return std::vector resulting vector containing binary data */ template std::vector pack(T data) { std::vector rawData( (std::uint8_t*)&data, (std::uint8_t*)&(data) + sizeof(T)); return rawData; } #endif