This commit is contained in:
MoneroOcean
2020-07-15 11:18:28 -07:00
parent 662c61ee4b
commit 8f21d27d42
2 changed files with 63 additions and 25 deletions

View File

@@ -1,7 +1,32 @@
// Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2014-2019, The Monero Project
// Distributed under the MIT/X11 software license, see the accompanying //
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "base58.h" #include "base58.h"
@@ -11,7 +36,6 @@
#include "crypto/hash.h" #include "crypto/hash.h"
#include "int-util.h" #include "int-util.h"
#include "util.h"
#include "varint.h" #include "varint.h"
namespace tools namespace tools
@@ -84,20 +108,8 @@ namespace tools
assert(1 <= size && size <= sizeof(uint64_t)); assert(1 <= size && size <= sizeof(uint64_t));
uint64_t res = 0; uint64_t res = 0;
switch (9 - size) memcpy(reinterpret_cast<uint8_t*>(&res) + sizeof(uint64_t) - size, data, size);
{ return SWAP64BE(res);
case 1: res |= *data++;
case 2: res <<= 8; res |= *data++;
case 3: res <<= 8; res |= *data++;
case 4: res <<= 8; res |= *data++;
case 5: res <<= 8; res |= *data++;
case 6: res <<= 8; res |= *data++;
case 7: res <<= 8; res |= *data++;
case 8: res <<= 8; res |= *data; break;
default: assert(false);
}
return res;
} }
void uint_64_to_8be(uint64_t num, size_t size, uint8_t* data) void uint_64_to_8be(uint64_t num, size_t size, uint8_t* data)
@@ -110,7 +122,7 @@ namespace tools
void encode_block(const char* block, size_t size, char* res) void encode_block(const char* block, size_t size, char* res)
{ {
assert(1 <= size && size <= sizeof(full_block_size)); assert(1 <= size && size <= full_block_size);
uint64_t num = uint_8be_to_64(reinterpret_cast<const uint8_t*>(block), size); uint64_t num = uint_8be_to_64(reinterpret_cast<const uint8_t*>(block), size);
int i = static_cast<int>(encoded_block_sizes[size]) - 1; int i = static_cast<int>(encoded_block_sizes[size]) - 1;
@@ -222,7 +234,7 @@ namespace tools
return encode(buf); return encode(buf);
} }
bool decode_addr(std::string addr, uint64_t& tag, std::string& data) bool decode_addr(const std::string &addr, uint64_t& tag, std::string& data)
{ {
std::string addr_data; std::string addr_data;
bool r = decode(addr, addr_data); bool r = decode(addr, addr_data);

View File

@@ -1,6 +1,32 @@
// Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2014-2019, The Monero Project
// Distributed under the MIT/X11 software license, see the accompanying //
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#pragma once #pragma once
@@ -15,6 +41,6 @@ namespace tools
bool decode(const std::string& enc, std::string& data); bool decode(const std::string& enc, std::string& data);
std::string encode_addr(uint64_t tag, const std::string& data); std::string encode_addr(uint64_t tag, const std::string& data);
bool decode_addr(std::string addr, uint64_t& tag, std::string& data); bool decode_addr(const std::string &addr, uint64_t& tag, std::string& data);
} }
} }