diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-05-29 21:33:17 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-05-29 21:33:17 +0000 |
commit | a66281d8453edde56145e032e8d38db91580ba08 (patch) | |
tree | efdddb6f765cf020502eed9139dab6767adb5d0b /protocols/Tox/src/tox_address.h | |
parent | 6c5621e08b28ff3c3db26726aafd827d354d6934 (diff) |
Tox:
- reworked code related with address/public key
- added tox_add_tcp_relay to bootstrap
- updated tox core
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@13900 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_address.h')
-rw-r--r-- | protocols/Tox/src/tox_address.h | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/protocols/Tox/src/tox_address.h b/protocols/Tox/src/tox_address.h index 265ed2f94e..2688118fe2 100644 --- a/protocols/Tox/src/tox_address.h +++ b/protocols/Tox/src/tox_address.h @@ -8,23 +8,36 @@ class ToxHexAddress {
private:
std::string hexData;
+ void Init(const char *hex, size_t size)
+ {
+ hexData = std::string(hex, size);
+ }
+ void Init(const uint8_t *bin, size_t size)
+ {
+ char *hex = (char*)mir_alloc(size * 2 + 1);
+ hexData = bin2hex(bin, size, hex);
+ std::transform(hexData.begin(), hexData.end(), hexData.begin(), ::toupper);
+ mir_free(hex);
+ }
public:
ToxHexAddress(const ToxHexAddress &address) : hexData(address.hexData) { }
ToxHexAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2) : hexData(hex, hex + size) { }
ToxHexAddress(const std::string &hex)
{
- this->ToxHexAddress::ToxHexAddress(hex.c_str(), hex.size());
+ Init(hex.c_str(), hex.size());
}
ToxHexAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE)
{
- char *hex = (char*)mir_alloc(size * 2 + 1);
- hexData = bin2hex(bin, size, hex);
- std::transform(hexData.begin(), hexData.end(), hexData.begin(), ::toupper);
- mir_free(hex);
+ Init(bin, size);
}
ToxHexAddress(const std::vector<uint8_t> &bin)
{
- this->ToxHexAddress::ToxHexAddress(bin.data(), bin.size());
+ Init(bin.data(), bin.size());
+ }
+ ToxHexAddress& operator=(const char *hex)
+ {
+ Init(hex, mir_strlen(hex));
+ return *this;
}
const size_t GetLength() const
{
@@ -54,24 +67,34 @@ class ToxBinAddress {
private:
std::vector<uint8_t> binData;
-public:
- ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { }
- ToxBinAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE) : binData(bin, bin + size) { }
- ToxBinAddress(const std::vector<uint8_t> &bin, size_t size = TOX_ADDRESS_SIZE) : binData(bin.begin(), bin.begin() + size) { }
- ToxBinAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2)
+ void Init(const char *hex, size_t size)
{
char *endptr;
const char *pos = hex;
- for (size_t i = 0; i < size / 2; i++)
+ size /= 2; binData.resize(size);
+ for (size_t i = 0; i < size; i++)
{
char buf[5] = { '0', 'x', pos[0], pos[1], 0 };
- binData.push_back((uint8_t)strtol(buf, &endptr, 0));
+ binData[i] = (uint8_t)strtol(buf, &endptr, 0);
pos += 2;
}
}
+public:
+ ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { }
+ ToxBinAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE) : binData(bin, bin + size) { }
+ ToxBinAddress(const std::vector<uint8_t> &bin, size_t size = TOX_ADDRESS_SIZE) : binData(bin.begin(), bin.begin() + size) { }
+ ToxBinAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2)
+ {
+ Init(hex, size);
+ }
ToxBinAddress(const std::string &hex)
{
- this->ToxBinAddress::ToxBinAddress(hex.c_str(), hex.size());
+ Init(hex.c_str(), hex.size());
+ }
+ ToxBinAddress& operator=(const char *hex)
+ {
+ Init(hex, mir_strlen(hex));
+ return *this;
}
const ToxBinAddress GetPubKey() const
{
|