add toxkey

This commit is contained in:
Green Sky 2023-07-23 12:13:09 +02:00
parent 76fbeb9500
commit b3c5fe3a7c
No known key found for this signature in database
3 changed files with 70 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,43 @@
#include "./tox_key.hpp"
#include <cassert>
ToxKey::ToxKey(const std::vector<std::uint8_t>& 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;
//}

View File

@ -0,0 +1,24 @@
#pragma once
#include <array>
#include <vector>
#include <cstdint>
// public key or secret key, or conf uid
struct ToxKey {
std::array<std::uint8_t, 32> data;
ToxKey(void) = default;
ToxKey(const std::vector<std::uint8_t>& 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);