Files
hrynco-kswitcher/src/lan_pairing.h
T

27 lines
890 B
C++

#pragma once
#include "platform.h"
#include "../vendor/json.hpp"
namespace ks::lan
{
using Json = nlohmann::json;
inline constexpr unsigned Port = 45883;
inline constexpr uint64_t PairLifetime = 120000, PeerLifetime = 12000;
std::string randomHex(size_t bytes);
std::string normalizeCode(const std::string &);
std::string mac(const std::string &key, const std::string &text);
bool equal(const std::string &, const std::string &);
bool identifier(const std::string &);
Json envelope(const std::string &type, const std::string &id);
struct Pairing
{
std::string local, peer, code, nonce, remoteNonce, derived;
uint64_t started{};
bool acknowledged{}, confirmed{};
Pairing(std::string local, std::string peer, const std::string &code, uint64_t now);
bool expired(uint64_t now) const;
Json offer() const;
std::vector<Json> receive(const Json &, uint64_t now);
};
}