diff --git a/CMakeLists.txt b/CMakeLists.txt index 735f2b8..1153693 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,9 @@ add_library(solanaceae_toxcore ./solanaceae/toxcore/utils.hpp ./solanaceae/toxcore/utils.cpp + ./solanaceae/toxcore/tox_key.hpp + ./solanaceae/toxcore/tox_key.cpp + ./solanaceae/toxcore/tox_interface.hpp ./solanaceae/toxcore/tox_interface.cpp ./solanaceae/toxcore/tox_event_interface.hpp diff --git a/solanaceae/toxcore/tox_key.cpp b/solanaceae/toxcore/tox_key.cpp new file mode 100644 index 0000000..f2159ad --- /dev/null +++ b/solanaceae/toxcore/tox_key.cpp @@ -0,0 +1,43 @@ +#include "./tox_key.hpp" + +#include + +ToxKey::ToxKey(const std::vector& v) { + assert(v.size() == data.size()); + for (size_t i = 0; i < data.size(); i++) { + data[i] = v[i]; + } +} + +ToxKey::ToxKey(const std::uint8_t* d, std::size_t s) { + assert(s == data.size()); + for (size_t i = 0; i < data.size(); i++) { + data[i] = d[i]; + } +} + + +bool ToxKey::operator<(const ToxKey& other) const { + for (size_t i = 0; i < size(); i++) { + if (data[i] < other.data[i]) { + return true; + } else if (data[i] > other.data[i]) { + return false; + } + } + + return false; // equal +} + +//std::ostream& operator<<(std::ostream& out, const SHA1Digest& v) { + //std::string str{}; + //str.resize(v.size()*2, '?'); + + //// HECK, std is 1 larger than size returns ('\0') + //sodium_bin2hex(str.data(), str.size()+1, v.data.data(), v.data.size()); + + //out << str; + + //return out; +//} + diff --git a/solanaceae/toxcore/tox_key.hpp b/solanaceae/toxcore/tox_key.hpp new file mode 100644 index 0000000..f1d959a --- /dev/null +++ b/solanaceae/toxcore/tox_key.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +// public key or secret key, or conf uid +struct ToxKey { + std::array data; + + ToxKey(void) = default; + ToxKey(const std::vector& v); + ToxKey(const std::uint8_t* d, std::size_t s); + + constexpr bool operator==(const ToxKey& other) const { return data == other.data; } + constexpr bool operator!=(const ToxKey& other) const { return data != other.data; } + + bool operator<(const ToxKey& other) const; + + constexpr std::size_t size(void) const { return data.size(); } +}; + +//std::ostream& operator<<(std::ostream& out, const SHA1Digest& v); +