summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_address.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/src/tox_address.h')
-rw-r--r--protocols/Tox/src/tox_address.h34
1 files changed, 22 insertions, 12 deletions
diff --git a/protocols/Tox/src/tox_address.h b/protocols/Tox/src/tox_address.h
index 6eada63300..4270e23ee2 100644
--- a/protocols/Tox/src/tox_address.h
+++ b/protocols/Tox/src/tox_address.h
@@ -9,12 +9,11 @@ class ToxHexAddress
private:
std::string hexData;
public:
- ToxHexAddress(const char *hex) : hexData(hex) { }
- ToxHexAddress(const std::string &hex) : hexData(hex) { }
ToxHexAddress(const ToxHexAddress &address) : hexData(address.hexData) { }
- ToxHexAddress(const std::vector<uint8_t> &bin)
+ ToxHexAddress(const char *hex, size_t size = TOX_FRIEND_ADDRESS_SIZE * 2) : hexData(hex, hex + size) { }
+ ToxHexAddress(const std::string &hex)
{
- this->ToxHexAddress::ToxHexAddress(bin.data(), bin.size());
+ this->ToxHexAddress::ToxHexAddress(hex.c_str(), hex.size());
}
ToxHexAddress(const uint8_t *bin, size_t size = TOX_FRIEND_ADDRESS_SIZE)
{
@@ -23,10 +22,18 @@ public:
std::transform(hexData.begin(), hexData.end(), hexData.begin(), ::toupper);
mir_free(hex);
}
+ ToxHexAddress(const std::vector<uint8_t> &bin)
+ {
+ this->ToxHexAddress::ToxHexAddress(bin.data(), bin.size());
+ }
const size_t GetLength() const
{
return hexData.length();
}
+ const bool IsEmpty() const
+ {
+ return hexData.length() == 0;
+ }
const ToxHexAddress GetPubKey() const
{
ToxHexAddress pubKey = hexData.substr(0, TOX_PUBLIC_KEY_SIZE * 2).c_str();
@@ -36,6 +43,10 @@ public:
{
return hexData.c_str();
}
+ static ToxHexAddress Empty()
+ {
+ return ToxHexAddress("");
+ }
ToxBinAddress ToBin() const;
};
@@ -45,24 +56,23 @@ private:
std::vector<uint8_t> binData;
public:
ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { }
- ToxBinAddress(const std::vector<uint8_t> &bin) : binData(bin) { }
ToxBinAddress(const uint8_t *bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) : binData(bin, bin + size) { }
- ToxBinAddress(const std::string &hex)
- {
- this->ToxBinAddress::ToxBinAddress(hex.c_str());
- }
- ToxBinAddress(const char *hex)
+ ToxBinAddress(const std::vector<uint8_t> &bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) : binData(bin.begin(), bin.begin() + size) { }
+ ToxBinAddress(const char *hex, size_t size = TOX_FRIEND_ADDRESS_SIZE * 2)
{
char *endptr;
const char *pos = hex;
- size_t size = mir_strlen(hex) / 2;
- for (size_t i = 0; i < size; i++)
+ for (size_t i = 0; i < size / 2; i++)
{
char buf[5] = { '0', 'x', pos[0], pos[1], 0 };
binData.push_back((uint8_t)strtol(buf, &endptr, 0));
pos += 2;
}
}
+ ToxBinAddress(const std::string &hex)
+ {
+ this->ToxBinAddress::ToxBinAddress(hex.c_str(), hex.size());
+ }
const ToxBinAddress GetPubKey() const
{
ToxBinAddress pubKey(binData.data(), TOX_PUBLIC_KEY_SIZE);