diff --git a/include/libtorrent/hex.hpp b/include/libtorrent/hex.hpp index 69299178a..f97dfbbc3 100644 --- a/include/libtorrent/hex.hpp +++ b/include/libtorrent/hex.hpp @@ -35,22 +35,17 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/error_code.hpp" - -#include "libtorrent/aux_/disable_warnings_push.hpp" +#include "libtorrent/span.hpp" #include -#include #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { namespace aux { TORRENT_EXTRA_EXPORT int hex_to_int(char in); - // TODO: 3 take an span here instead - TORRENT_EXTRA_EXPORT bool is_hex(char const *in, int len); + TORRENT_EXTRA_EXPORT bool is_hex(span in); // The overload taking a ``std::string`` converts (binary) the string ``s`` // to hexadecimal representation and returns it. @@ -58,23 +53,29 @@ namespace libtorrent // buffer [``in``, ``in`` + len) to hexadecimal and prints it to the buffer // ``out``. The caller is responsible for making sure the buffer pointed to // by ``out`` is large enough, i.e. has at least len * 2 bytes of space. - TORRENT_DEPRECATED_EXPORT std::string to_hex(std::string const& s); - // TODO: 3 take an span here instead - TORRENT_DEPRECATED_EXPORT void to_hex(char const *in, int len, char* out); + TORRENT_DEPRECATED_EXPORT std::string to_hex(span s); + TORRENT_DEPRECATED_EXPORT void to_hex(span in, char* out); // converts the buffer [``in``, ``in`` + len) from hexadecimal to // binary. The binary output is written to the buffer pointed to // by ``out``. The caller is responsible for making sure the buffer // at ``out`` has enough space for the result to be written to, i.e. // (len + 1) / 2 bytes. - // TODO: 3 take an span here instead - TORRENT_DEPRECATED_EXPORT bool from_hex(char const *in, int len, char* out); + TORRENT_DEPRECATED_EXPORT bool from_hex(span in, char* out); } #ifndef TORRENT_NO_DEPRECATE - using aux::to_hex; - using aux::from_hex; + // deprecated in 1.2 + TORRENT_DEPRECATED + inline void to_hex(char const* in, int len, char* out) + { aux::to_hex({in, static_cast(len)}, out); } + TORRENT_DEPRECATED + inline std::string to_hex(std::string const& s) + { return aux::to_hex(s); } + TORRENT_DEPRECATED + inline bool from_hex(char const *in, int len, char* out) + { return aux::from_hex({in, static_cast(len)}, out); } #endif } diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 799717268..5ded405df 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -131,7 +131,7 @@ namespace libtorrent // shift left ``n`` bits. sha1_hash& operator<<=(int n); - // shift r ``n`` bits. + // shift right ``n`` bits. sha1_hash& operator>>=(int n); // standard comparison operators diff --git a/src/alert.cpp b/src/alert.cpp index bc964d4f0..6ef9f35a3 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -76,7 +76,7 @@ namespace libtorrent { else { char msg[41]; - aux::to_hex(t->info_hash().data(), 20, msg); + aux::to_hex(t->info_hash(), msg); m_name_idx = alloc.copy_string(msg); } } @@ -1138,7 +1138,7 @@ namespace libtorrent { { error_code ec; char ih_hex[41]; - aux::to_hex(info_hash.data(), 20, ih_hex); + aux::to_hex(info_hash, ih_hex); char msg[200]; std::snprintf(msg, sizeof(msg), "incoming dht announce: %s:%u (%s)" , ip.to_string(ec).c_str(), port, ih_hex); @@ -1153,7 +1153,7 @@ namespace libtorrent { std::string dht_get_peers_alert::message() const { char ih_hex[41]; - aux::to_hex(info_hash.data(), 20, ih_hex); + aux::to_hex(info_hash, ih_hex); char msg[200]; std::snprintf(msg, sizeof(msg), "incoming dht get_peers: %s", ih_hex); return msg; @@ -1379,7 +1379,7 @@ namespace libtorrent { if (params.ti) torrent_name = params.ti->name().c_str(); else if (!params.name.empty()) torrent_name = params.name.c_str(); else if (!params.url.empty()) torrent_name = params.url.c_str(); - else aux::to_hex(params.info_hash.data(), 20, info_hash); + else aux::to_hex(params.info_hash, info_hash); if (error) { @@ -1481,8 +1481,8 @@ namespace libtorrent { { char msg[200]; std::snprintf(msg, sizeof(msg), " torrent changed info-hash from: %s to %s" - , aux::to_hex(old_ih.to_string()).c_str() - , aux::to_hex(new_ih.to_string()).c_str()); + , aux::to_hex(old_ih).c_str() + , aux::to_hex(new_ih).c_str()); return torrent_alert::message() + msg; } #endif @@ -1548,7 +1548,7 @@ namespace libtorrent { { char msg[1050]; std::snprintf(msg, sizeof(msg), "DHT immutable item %s [ %s ]" - , aux::to_hex(target.to_string()).c_str() + , aux::to_hex(target).c_str() , item.to_string().c_str()); return msg; } @@ -1569,7 +1569,7 @@ namespace libtorrent { { char msg[1050]; std::snprintf(msg, sizeof(msg), "DHT mutable item (key=%s salt=%s seq=%" PRId64 " %s) [ %s ]" - , aux::to_hex(std::string(&key[0], 32)).c_str() + , aux::to_hex(key).c_str() , salt.c_str() , seq , authoritative ? "auth" : "non-auth" @@ -1604,8 +1604,8 @@ namespace libtorrent { { std::snprintf(msg, sizeof(msg), "DHT put complete (success=%d key=%s sig=%s salt=%s seq=%" PRId64 ")" , num_success - , aux::to_hex(std::string(&public_key[0], 32)).c_str() - , aux::to_hex(std::string(&signature[0], 64)).c_str() + , aux::to_hex(public_key).c_str() + , aux::to_hex(signature).c_str() , salt.c_str() , seq); return msg; @@ -1613,7 +1613,7 @@ namespace libtorrent { std::snprintf(msg, sizeof(msg), "DHT put commplete (success=%d hash=%s)" , num_success - , aux::to_hex(target.to_string()).c_str()); + , aux::to_hex(target).c_str()); return msg; } @@ -1645,10 +1645,10 @@ namespace libtorrent { if (obfuscated_info_hash != info_hash) { std::snprintf(obf, sizeof(obf), " [obfuscated: %s]" - , aux::to_hex(obfuscated_info_hash.to_string()).c_str()); + , aux::to_hex(obfuscated_info_hash).c_str()); } std::snprintf(msg, sizeof(msg), "outgoing dht get_peers : %s%s -> %s" - , aux::to_hex(info_hash.to_string()).c_str() + , aux::to_hex(info_hash).c_str() , obf , print_endpoint(ip).c_str()); return msg; @@ -1953,7 +1953,7 @@ namespace libtorrent { std::string dht_get_peers_reply_alert::message() const { char ih_hex[41]; - aux::to_hex(info_hash.data(), 20, ih_hex); + aux::to_hex(info_hash, ih_hex); char msg[200]; std::snprintf(msg, sizeof(msg), "incoming dht get_peers reply: %s, peers %d", ih_hex, m_num_peers); return msg; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index c0765432a..8687edcc1 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -818,14 +818,14 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING { char hex_pid[41]; - aux::to_hex(m_our_peer_id.data(), 20, hex_pid); + aux::to_hex(m_our_peer_id, hex_pid); hex_pid[40] = 0; peer_log(peer_log_alert::outgoing, "HANDSHAKE" , "sent peer_id: %s client: %s" , hex_pid, identify_client(m_our_peer_id).c_str()); } peer_log(peer_log_alert::outgoing_message, "HANDSHAKE" - , "ih: %s", aux::to_hex(ih.to_string()).c_str()); + , "ih: %s", aux::to_hex(ih).c_str()); #endif send_buffer(handshake, sizeof(handshake)); } @@ -3262,7 +3262,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING { char hex_pid[41]; - aux::to_hex(recv_buffer.begin(), 20, hex_pid); + aux::to_hex({recv_buffer.data(), 20}, hex_pid); hex_pid[40] = 0; char ascii_pid[21]; ascii_pid[20] = 0; diff --git a/src/hex.cpp b/src/hex.cpp index 200ac2ac8..bc0ef7b29 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -45,27 +45,27 @@ namespace libtorrent return -1; } - bool is_hex(char const *in, int len) + bool is_hex(span in) { - for (char const* end = in + len; in < end; ++in) + for (char const c : in) { - int t = hex_to_int(*in); + int const t = hex_to_int(c); if (t == -1) return false; } return true; } - bool from_hex(char const *in, int len, char* out) + bool from_hex(span in, char* out) { - for (char const* end = in + len; in < end; ++in, ++out) + for (auto i = in.begin(), end = in.end(); i != end; ++i, ++out) { - int t = aux::hex_to_int(*in); - if (t == -1) return false; - *out = t << 4; - ++in; - t = aux::hex_to_int(*in); - if (t == -1) return false; - *out |= t & 15; + int const t1 = aux::hex_to_int(*i); + if (t1 == -1) return false; + *out = t1 << 4; + ++i; + int const t2 = aux::hex_to_int(*i); + if (t2 == -1) return false; + *out |= t2 & 15; } return true; } @@ -74,23 +74,25 @@ namespace libtorrent char const hex_chars[] = "0123456789abcdef"; - std::string to_hex(std::string const& s) + std::string to_hex(span s) { std::string ret; - for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) + ret.resize(s.size() * 2); + int idx = 0; + for (char const i : s) { - ret += hex_chars[std::uint8_t(*i) >> 4]; - ret += hex_chars[std::uint8_t(*i) & 0xf]; + ret[idx++] = hex_chars[std::uint8_t(i) >> 4]; + ret[idx++] = hex_chars[std::uint8_t(i) & 0xf]; } return ret; } - void to_hex(char const *in, int len, char* out) + void to_hex(span in, char* out) { - for (char const* end = in + len; in < end; ++in) + for (char const i : in) { - *out++ = hex_chars[std::uint8_t(*in) >> 4]; - *out++ = hex_chars[std::uint8_t(*in) & 0xf]; + *out++ = hex_chars[std::uint8_t(i) >> 4]; + *out++ = hex_chars[std::uint8_t(i) & 0xf]; } *out = '\0'; } diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 3ed0fbc62..56e49975d 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -365,7 +365,7 @@ namespace libtorrent std::int64_t chunk_size = 0; span chunk_start(recv_buffer.begin() + m_chunk_pos, int(recv_buffer.size()) - m_chunk_pos); TORRENT_ASSERT(chunk_start[0] == '\r' - || aux::is_hex(chunk_start.data(), 1)); + || aux::is_hex(chunk_start[0])); bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size); if (!ret) { diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index a15785fe7..1d490fcd7 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -133,7 +133,7 @@ namespace libtorrent char tmp[20]; std::generate(tmp, tmp + sizeof(tmp), &std::rand); m_session_id.resize(sizeof(tmp)*2); - aux::to_hex(tmp, 20, &m_session_id[0]); + aux::to_hex(tmp, &m_session_id[0]); m_sam_socket.reset(new i2p_stream(m_io_service)); m_sam_socket->set_proxy(m_hostname, m_port); diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 3669802c7..730232d02 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -145,10 +145,10 @@ namespace libtorrent { namespace dht #ifndef TORRENT_DISABLE_LOGGING m_log->log(dht_logger::tracker, "starting IPv4 DHT tracker with node id: %s" - , aux::to_hex(m_dht.nid().to_string()).c_str()); + , aux::to_hex(m_dht.nid()).c_str()); #if TORRENT_USE_IPV6 m_log->log(dht_logger::tracker, "starting IPv6 DHT tracker with node id: %s" - , aux::to_hex(m_dht6.nid().to_string()).c_str()); + , aux::to_hex(m_dht6.nid()).c_str()); #endif #endif } diff --git a/src/kademlia/find_data.cpp b/src/kademlia/find_data.cpp index 94d7cbfad..1718db604 100644 --- a/src/kademlia/find_data.cpp +++ b/src/kademlia/find_data.cpp @@ -115,7 +115,7 @@ void find_data::got_write_token(node_id const& n, std::string const& write_token get_node().observer()->log(dht_logger::traversal , "[%p] adding write token '%s' under id '%s'" , static_cast(this), aux::to_hex(write_token).c_str() - , aux::to_hex(n.to_string()).c_str()); + , aux::to_hex(n).c_str()); #endif m_write_tokens[n] = write_token; } diff --git a/src/kademlia/get_peers.cpp b/src/kademlia/get_peers.cpp index c34871f8b..cbd58b224 100644 --- a/src/kademlia/get_peers.cpp +++ b/src/kademlia/get_peers.cpp @@ -72,7 +72,7 @@ void get_peers_observer::reply(msg const& m) char const* end = peers + n.list_at(0).string_length(); #ifndef TORRENT_DISABLE_LOGGING - bdecode_node id = r.dict_find_string("id"); + bdecode_node const id = r.dict_find_string("id"); if (id && id.string_length() == 20) { get_observer()->log(dht_logger::traversal, "[%p] PEERS " @@ -81,7 +81,7 @@ void get_peers_observer::reply(msg const& m) , algorithm()->invoke_count() , algorithm()->branch_factor() , print_endpoint(m.addr).c_str() - , aux::to_hex(id.string_value()).c_str() + , aux::to_hex({id.string_ptr(), size_t(id.string_length())}).c_str() , distance_exp(algorithm()->target(), node_id(id.string_ptr())) , int((end - peers) / 6)); } @@ -94,7 +94,7 @@ void get_peers_observer::reply(msg const& m) // assume it's uTorrent/libtorrent format read_endpoint_list(n, peer_list); #ifndef TORRENT_DISABLE_LOGGING - bdecode_node id = r.dict_find_string("id"); + bdecode_node const id = r.dict_find_string("id"); if (id && id.string_length() == 20) { get_observer()->log(dht_logger::traversal, "[%p] PEERS " @@ -103,7 +103,7 @@ void get_peers_observer::reply(msg const& m) , algorithm()->invoke_count() , algorithm()->branch_factor() , print_endpoint(m.addr).c_str() - , aux::to_hex(id.string_value()).c_str() + , aux::to_hex({id.string_ptr(), size_t(id.string_length())}).c_str() , distance_exp(algorithm()->target(), node_id(id.string_ptr())) , int(n.list_size())); } diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index b2c0eb471..fdf47d47d 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -361,7 +361,7 @@ namespace if (node.observer()) { char hex_ih[41]; - aux::to_hex(ih.data(), 20, hex_ih); + aux::to_hex(ih, hex_ih); node.observer()->log(dht_logger::node, "sending announce_peer [ ih: %s " " p: %d nodes: %d ]", hex_ih, listen_port, int(v.size())); } @@ -451,7 +451,7 @@ void node::announce(sha1_hash const& info_hash, int listen_port, int flags if (m_observer) { char hex_ih[41]; - aux::to_hex(info_hash.data(), 20, hex_ih); + aux::to_hex(info_hash, hex_ih); m_observer->log(dht_logger::node, "announcing [ ih: %s p: %d ]" , hex_ih, listen_port); } @@ -485,7 +485,7 @@ void node::get_item(sha1_hash const& target if (m_observer) { char hex_target[41]; - aux::to_hex(target.data(), 20, hex_target); + aux::to_hex(target, hex_target); m_observer->log(dht_logger::node, "starting get for [ hash: %s ]" , hex_target); } @@ -503,7 +503,7 @@ void node::get_item(public_key const& pk, std::string const& salt if (m_observer) { char hex_key[65]; - aux::to_hex(pk.bytes.data(), 32, hex_key); + aux::to_hex(pk.bytes, hex_key); m_observer->log(dht_logger::node, "starting get for [ key: %s ]", hex_key); } #endif @@ -542,7 +542,7 @@ void node::put_item(sha1_hash const& target, entry const& data, boost::function< if (m_observer) { char hex_target[41]; - aux::to_hex(target.data(), 20, hex_target); + aux::to_hex(target, hex_target); m_observer->log(dht_logger::node, "starting get for [ hash: %s ]" , hex_target); } @@ -568,7 +568,7 @@ void node::put_item(public_key const& pk, std::string const& salt if (m_observer) { char hex_key[65]; - aux::to_hex(pk.bytes.data(), 32, hex_key); + aux::to_hex(pk.bytes, hex_key); m_observer->log(dht_logger::node, "starting get for [ key: %s ]", hex_key); } #endif @@ -1028,9 +1028,9 @@ void node::incoming_request(msg const& m, entry& e) // std::fprintf(stderr, "%s PUT target: %s salt: %s key: %s\n" // , mutable_put ? "mutable":"immutable" -// , aux::to_hex(target.to_string()).c_str() +// , aux::to_hex(target).c_str() // , salt.second > 0 ? std::string(salt.first, salt.second).c_str() : "" -// , pk ? aux::to_hex(std::string(pk, 32)).c_str() : ""); +// , pk ? aux::to_hex(pk).c_str() : ""); // verify the write-token. tokens are only valid to write to // specific target hashes. it must match the one we got a "get" for @@ -1128,7 +1128,7 @@ void node::incoming_request(msg const& m, entry& e) // std::fprintf(stderr, "%s GET target: %s\n" // , msg_keys[1] ? "mutable":"immutable" -// , aux::to_hex(target.to_string()).c_str()); +// , aux::to_hex(target).c_str()); reply["token"] = generate_token(m.addr, sha1_hash(msg_keys[1].string_ptr())); diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index dc7a3febf..1c7e2c480 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -256,7 +256,7 @@ void routing_table::print_state(std::ostream& os) const "number of nodes per bucket:\n" , m_bucket_size , num_global_nodes() - , aux::to_hex(m_id.to_string()).c_str()); + , aux::to_hex(m_id).c_str()); if (cursor > buf.size() - 500) buf.resize(buf.size() * 3 / 2); int idx = 0; @@ -318,7 +318,7 @@ void routing_table::print_state(std::ostream& os) const cursor += std::snprintf(&buf[cursor], buf.size() - cursor , " prefix: %2x id: %s" , ((id[0] & top_mask) >> mask_shift) - , aux::to_hex(j->id.to_string()).c_str()); + , aux::to_hex(j->id).c_str()); if (j->rtt == 0xffff) { @@ -1000,7 +1000,7 @@ ip_ok: if (m_log) { char hex_id[41]; - aux::to_hex(e.id.data(), int(e.id.size()), hex_id); + aux::to_hex(e.id, hex_id); m_log->log(dht_logger::routing_table, "replacing node with higher RTT: %s %s" , hex_id, print_address(e.addr()).c_str()); } diff --git a/src/kademlia/traversal_algorithm.cpp b/src/kademlia/traversal_algorithm.cpp index eead62700..c5269ea2a 100644 --- a/src/kademlia/traversal_algorithm.cpp +++ b/src/kademlia/traversal_algorithm.cpp @@ -100,7 +100,7 @@ traversal_algorithm::traversal_algorithm( if (get_node().observer()) { char hex_target[41]; - aux::to_hex(reinterpret_cast(&target[0]), 20, hex_target); + aux::to_hex(target, hex_target); get_node().observer()->log(dht_logger::traversal, "[%p] NEW target: %s k: %d" , static_cast(this), hex_target, int(m_node.m_table.bucket_size())); } @@ -181,7 +181,7 @@ void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsig if (get_node().observer()) { char hex_id[41]; - aux::to_hex(reinterpret_cast(&o->id()[0]), 20, hex_id); + aux::to_hex(o->id(), hex_id); get_node().observer()->log(dht_logger::traversal , "[%p] traversal DUPLICATE node. id: %s addr: %s type: %s" , static_cast(this), hex_id, print_address(o->target_addr()).c_str(), name()); @@ -200,7 +200,7 @@ void traversal_algorithm::add_entry(node_id const& id, udp::endpoint addr, unsig if (get_node().observer()) { char hex_id[41]; - aux::to_hex(reinterpret_cast(&id[0]), 20, hex_id); + aux::to_hex(id, hex_id); get_node().observer()->log(dht_logger::traversal , "[%p] ADD id: %s addr: %s distance: %d invoke-count: %d type: %s" , static_cast(this), hex_id, print_endpoint(addr).c_str() @@ -331,7 +331,7 @@ void traversal_algorithm::failed(observer_ptr o, int flags) if (get_node().observer()) { char hex_id[41]; - aux::to_hex(reinterpret_cast(&o->id()[0]), 20, hex_id); + aux::to_hex(o->id(), hex_id); get_node().observer()->log(dht_logger::traversal , "[%p] 1ST_TIMEOUT id: %s distance: %d addr: %s branch-factor: %d " "invoke-count: %d type: %s" @@ -353,7 +353,7 @@ void traversal_algorithm::failed(observer_ptr o, int flags) if (get_node().observer()) { char hex_id[41]; - aux::to_hex(reinterpret_cast(&o->id()[0]), 20, hex_id); + aux::to_hex(o->id(), hex_id); get_node().observer()->log(dht_logger::traversal , "[%p] TIMEOUT id: %s distance: %d addr: %s branch-factor: %d " "invoke-count: %d type: %s" @@ -401,7 +401,7 @@ void traversal_algorithm::done() { TORRENT_ASSERT(o->flags & observer::flag_queried); char hex_id[41]; - aux::to_hex(reinterpret_cast(&o->id()[0]), 20, hex_id); + aux::to_hex(o->id(), hex_id); get_node().observer()->log(dht_logger::traversal , "[%p] id: %s distance: %d addr: %s" , static_cast(this), hex_id, closest_target @@ -481,7 +481,7 @@ bool traversal_algorithm::add_requests() if (get_node().observer()) { char hex_id[41]; - aux::to_hex(reinterpret_cast(&o->id()[0]), 20, hex_id); + aux::to_hex(o->id(), hex_id); get_node().observer()->log(dht_logger::traversal , "[%p] INVOKE nodes-left: %d top-invoke-count: %d " "invoke-count: %d branch-factor: %d " @@ -589,7 +589,7 @@ void traversal_observer::reply(msg const& m) { bdecode_node nid = r.dict_find_string("id"); char hex_id[41]; - aux::to_hex(nid.string_ptr(), 20, hex_id); + aux::to_hex({nid.string_ptr(), 20}, hex_id); get_observer()->log(dht_logger::traversal , "[%p] RESPONSE id: %s invoke-count: %d addr: %s type: %s" , static_cast(algorithm()), hex_id, algorithm()->invoke_count() diff --git a/src/lsd.cpp b/src/lsd.cpp index 976067afc..29d479831 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -142,7 +142,7 @@ void lsd::announce_impl(sha1_hash const& ih, int const listen_port #endif char ih_hex[41]; - aux::to_hex(ih.data(), 20, ih_hex); + aux::to_hex(ih, ih_hex); char msg[200]; #ifndef TORRENT_DISABLE_LOGGING @@ -278,7 +278,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buf } sha1_hash ih(nullptr); - aux::from_hex(ih_str.c_str(), 40, ih.data()); + aux::from_hex(ih_str, ih.data()); if (!ih.is_all_zeros() && port != 0) { diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 671e5c716..e0e5c186f 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -50,7 +50,7 @@ namespace libtorrent std::string ret; sha1_hash const& ih = handle.info_hash(); ret += "magnet:?xt=urn:btih:"; - ret += aux::to_hex(ih.to_string()); + ret += aux::to_hex(ih); torrent_status st = handle.status(torrent_handle::query_name); if (!st.name.empty()) @@ -82,7 +82,7 @@ namespace libtorrent std::string ret; sha1_hash const& ih = info.info_hash(); ret += "magnet:?xt=urn:btih:"; - ret += aux::to_hex(ih.to_string()); + ret += aux::to_hex(ih); std::string const& name = info.name(); @@ -158,7 +158,7 @@ namespace libtorrent if (btih.compare(0, 9, "urn:btih:") != 0) return torrent_handle(); - if (btih.size() == 40 + 9) aux::from_hex(&btih[9], 40, params.info_hash.data()); + if (btih.size() == 40 + 9) aux::from_hex({&btih[9], 40}, params.info_hash.data()); else params.info_hash.assign(base32decode(btih.substr(9))); return ses.add_torrent(params); @@ -265,7 +265,7 @@ namespace libtorrent #endif sha1_hash info_hash; - if (btih.size() == 40 + 9) aux::from_hex(&btih[9], 40, info_hash.data()); + if (btih.size() == 40 + 9) aux::from_hex({&btih[9], 40}, info_hash.data()); else if (btih.size() == 32 + 9) { std::string ih = base32decode(btih.substr(9)); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 21bea3f1a..34ad7253b 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1193,7 +1193,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING if (t) peer_log(peer_log_alert::info, "ATTACH" - , "Delay loaded torrent: %s:", aux::to_hex(ih.to_string()).c_str()); + , "Delay loaded torrent: %s:", aux::to_hex(ih).c_str()); #endif } @@ -1203,7 +1203,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "ATTACH" , "couldn't find a torrent with the given info_hash: %s torrents:" - , aux::to_hex(ih.to_string()).c_str()); + , aux::to_hex(ih).c_str()); #endif #ifndef TORRENT_DISABLE_DHT diff --git a/src/session_impl.cpp b/src/session_impl.cpp index e2ca98b94..90bee7188 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6926,7 +6926,7 @@ namespace aux { i != resp.peers.end(); ++i) { debug_log(" %16s %5d %s %s", i->hostname.c_str(), i->port - , i->pid.is_all_zeros()?"":to_hex(i->pid.to_string()).c_str() + , i->pid.is_all_zeros()?"":to_hex(i->pid).c_str() , identify_client(i->pid).c_str()); } for (std::vector::const_iterator i = resp.peers4.begin(); diff --git a/src/sha1_hash.cpp b/src/sha1_hash.cpp index 786c49581..5b7e7c927 100644 --- a/src/sha1_hash.cpp +++ b/src/sha1_hash.cpp @@ -47,7 +47,7 @@ namespace libtorrent std::ostream& operator<<(std::ostream& os, sha1_hash const& peer) { char out[sha1_hash::size() * 2 + 1]; - aux::to_hex(peer.data(), int(sha1_hash::size()), out); + aux::to_hex(peer, out); return os << out; } @@ -56,7 +56,7 @@ namespace libtorrent { char hex[sha1_hash::size() * 2]; is.read(hex, sha1_hash::size() * 2); - if (!aux::from_hex(hex, int(sha1_hash::size()) * 2, peer.data())) + if (!aux::from_hex(hex, peer.data())) is.setstate(std::ios_base::failbit); return is; } diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index a8784d770..be9dcbc77 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -227,8 +227,8 @@ namespace m_torrent.debug_log(" BANNING PEER [ p: %d | b: %d | c: %s" " | hash1: %s | hash2: %s | ip: %s ]" , b.piece_index, b.block_index, client - , aux::to_hex(i->second.digest.to_string()).c_str() - , aux::to_hex(e.digest.to_string()).c_str() + , aux::to_hex(i->second.digest).c_str() + , aux::to_hex(e.digest).c_str() , print_endpoint(p->ip()).c_str()); #endif m_torrent.ban_peer(p); @@ -253,7 +253,7 @@ namespace m_torrent.debug_log(" STORE BLOCK CRC [ p: %d | b: %d | c: %s" " | digest: %s | ip: %s ]" , b.piece_index, b.block_index, client - , aux::to_hex(e.digest.to_string()).c_str() + , aux::to_hex(e.digest).c_str() , print_address(p->ip().address()).c_str()); #endif } @@ -297,8 +297,8 @@ namespace m_torrent.debug_log(" BANNING PEER [ p: %d | b: %d | c: %s" " | ok_digest: %s | bad_digest: %s | ip: %s ]" , b.first.piece_index, b.first.block_index, client - , aux::to_hex(ok_digest.to_string()).c_str() - , aux::to_hex(b.second.digest.to_string()).c_str() + , aux::to_hex(ok_digest).c_str() + , aux::to_hex(b.second.digest).c_str() , print_address(p->ip().address()).c_str()); #endif m_torrent.ban_peer(p); diff --git a/src/storage.cpp b/src/storage.cpp index e1e0d7b95..9a7b4e1ac 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -409,7 +409,7 @@ namespace libtorrent TORRENT_ASSERT(m_files.num_files() > 0); m_save_path = complete(params.path); m_part_file_name = "." + (params.info - ? aux::to_hex(params.info->info_hash().to_string()) + ? aux::to_hex(params.info->info_hash()) : params.files->name()) + ".parts"; } diff --git a/src/torrent.cpp b/src/torrent.cpp index d30573b1d..b9e03dffe 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3309,7 +3309,7 @@ namespace libtorrent i != resp.peers.end(); ++i) { debug_log(" %16s %5d %s %s", i->hostname.c_str(), i->port - , i->pid.is_all_zeros()?"":aux::to_hex(i->pid.to_string()).c_str() + , i->pid.is_all_zeros()?"":aux::to_hex(i->pid).c_str() , identify_client(i->pid).c_str()); } for (std::vector::const_iterator i = resp.peers4.begin(); @@ -6918,7 +6918,7 @@ namespace libtorrent if (is_ssl_torrent()) { // for ssl sockets, set the hostname - std::string host_name = aux::to_hex(m_torrent_file->info_hash().to_string()); + std::string host_name = aux::to_hex(m_torrent_file->info_hash()); #define CASE(t) case socket_type_int_impl >::value: \ s->get >()->set_host_name(host_name); break; diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index b9c9a87e2..2505c0a48 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1092,7 +1092,7 @@ namespace libtorrent std::string name; sanitize_append_path_element(name, name_ent.string_ptr() , name_ent.string_length()); - if (name.empty()) name = aux::to_hex(m_info_hash.to_string()); + if (name.empty()) name = aux::to_hex(m_info_hash); // extract file list bdecode_node files_node = info.dict_find_list("files"); diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index b4991a93c..ec2dbca07 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -531,7 +531,7 @@ namespace libtorrent if (cb) { char hex_ih[41]; - aux::to_hex(tracker_req().info_hash.data(), 20, hex_ih); + aux::to_hex(tracker_req().info_hash, hex_ih); cb->debug_log("==> UDP_TRACKER_CONNECT [ to: %s ih: %s]" , m_hostname.empty() ? print_endpoint(m_target).c_str() @@ -763,7 +763,7 @@ namespace libtorrent if (cb) { char hex_ih[41]; - aux::to_hex(req.info_hash.data(), 20, hex_ih); + aux::to_hex(req.info_hash, hex_ih); cb->debug_log("==> UDP_TRACKER_ANNOUNCE [%s]", hex_ih); } #endif diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 8547e4da0..e35c700d4 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -829,7 +829,7 @@ void web_peer_connection::on_receive(error_code const& error std::int64_t chunk_size = 0; span chunk_start = recv_buffer.subspan(m_chunk_pos); TORRENT_ASSERT(chunk_start[0] == '\r' - || aux::is_hex(chunk_start.data(), 1)); + || aux::is_hex({chunk_start.data(), 1})); bool const ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size); if (!ret) { diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index edb078076..fd3c02ce5 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -836,7 +836,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 remove_all(combine_path("tmp3" + suffix, "temporary"), ec); } char ih_hex[41]; - aux::to_hex((char const*)&t->info_hash()[0], 20, ih_hex); + aux::to_hex(t->info_hash(), ih_hex); std::fprintf(stderr, "generated torrent: %s tmp1%s/temporary\n", ih_hex, suffix.c_str()); } else diff --git a/test/test_checking.cpp b/test/test_checking.cpp index c2fe9b20d..67eadfb49 100644 --- a/test/test_checking.cpp +++ b/test/test_checking.cpp @@ -117,7 +117,7 @@ void test_checking(int flags = read_only_files) boost::shared_ptr ti(new torrent_info(&buf[0], int(buf.size()), ec)); std::fprintf(stderr, "generated torrent: %s tmp1_checking/test_torrent_dir\n" - , aux::to_hex(ti->info_hash().to_string()).c_str()); + , aux::to_hex(ti->info_hash()).c_str()); // truncate every file in half if (flags & incomplete_files) diff --git a/test/test_dht.cpp b/test/test_dht.cpp index eed875fe0..6bd5ed0cc 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -66,15 +66,15 @@ namespace { sha1_hash to_hash(char const* s) { sha1_hash ret; - aux::from_hex(s, 40, (char*)&ret[0]); + aux::from_hex({s, 40}, (char*)&ret[0]); return ret; } void get_test_keypair(public_key& pk, secret_key& sk) { - aux::from_hex("77ff84905a91936367c01360803104f92432fcd904a43511876df5cdf3e7e548", 64, pk.bytes.data()); - aux::from_hex("e06d3183d14159228433ed599221b80bd0a5ce8352e4bdf0262f76786ef1c74d" - "b7e7a9fea2c0eb269d61e3b38e450a22e754941ac78479d6c54e1faf6037881d", 128, sk.bytes.data()); + aux::from_hex({"77ff84905a91936367c01360803104f92432fcd904a43511876df5cdf3e7e548", 64}, pk.bytes.data()); + aux::from_hex({"e06d3183d14159228433ed599221b80bd0a5ce8352e4bdf0262f76786ef1c74d" + "b7e7a9fea2c0eb269d61e3b38e450a22e754941ac78479d6c54e1faf6037881d", 128}, sk.bytes.data()); } sequence_number prev_seq(sequence_number s) @@ -942,16 +942,17 @@ TORRENT_TEST(bloom_filter) // these are test vectors from BEP 33 // http://www.bittorrent.org/beps/bep_0033.html std::fprintf(stderr, "test.size: %f\n", test.size()); - std::fprintf(stderr, "%s\n", aux::to_hex(test.to_string()).c_str()); + std::string const bf_str = test.to_string(); + std::fprintf(stderr, "%s\n", aux::to_hex(bf_str).c_str()); if (supports_ipv6()) { TEST_CHECK(fabs(test.size() - 1224.93f) < 0.001); - TEST_CHECK(aux::to_hex(test.to_string()) == "f6c3f5eaa07ffd91bde89f777f26fb2bff37bdb8fb2bbaa2fd3ddde7bacfff75ee7ccbaefe5eedb1fbfaff67f6abff5e43ddbca3fd9b9ffdf4ffd3e9dff12d1bdf59db53dbe9fa5b7ff3b8fdfcde1afb8bedd7be2f3ee71ebbbfe93bcdeefe148246c2bc5dbff7e7efdcf24fd8dc7adffd8fffdfddfff7a4bbeedf5cb95ce81fc7fcff1ff4ffffdfe5f7fdcbb7fd79b3fa1fc77bfe07fff905b7b7ffc7fefeffe0b8370bb0cd3f5b7f2bd93feb4386cfdd6f7fd5bfaf2e9ebffffeecd67adbf7c67f17efd5d75eba6ffeba7fff47a91eb1bfbb53e8abfb5762abe8ff237279bfefbfeef5ffc5febfdfe5adffadfee1fb737ffffbfd9f6aeffeee76b6fd8f72ef"); + TEST_CHECK(aux::to_hex(bf_str) == "f6c3f5eaa07ffd91bde89f777f26fb2bff37bdb8fb2bbaa2fd3ddde7bacfff75ee7ccbaefe5eedb1fbfaff67f6abff5e43ddbca3fd9b9ffdf4ffd3e9dff12d1bdf59db53dbe9fa5b7ff3b8fdfcde1afb8bedd7be2f3ee71ebbbfe93bcdeefe148246c2bc5dbff7e7efdcf24fd8dc7adffd8fffdfddfff7a4bbeedf5cb95ce81fc7fcff1ff4ffffdfe5f7fdcbb7fd79b3fa1fc77bfe07fff905b7b7ffc7fefeffe0b8370bb0cd3f5b7f2bd93feb4386cfdd6f7fd5bfaf2e9ebffffeecd67adbf7c67f17efd5d75eba6ffeba7fff47a91eb1bfbb53e8abfb5762abe8ff237279bfefbfeef5ffc5febfdfe5adffadfee1fb737ffffbfd9f6aeffeee76b6fd8f72ef"); } else { TEST_CHECK(fabs(test.size() - 257.854f) < 0.001); - TEST_CHECK(aux::to_hex(test.to_string()) == "24c0004020043000102012743e00480037110820422110008000c0e302854835a05401a4045021302a306c060001881002d8a0a3a8001901b40a800900310008d2108110c2496a0028700010d804188b01415200082004088026411104a804048002002000080680828c400080cc40020c042c0494447280928041402104080d4240040414a41f0205654800b0811830d2020042b002c5800004a71d0204804a0028120a004c10017801490b834004044106005421000c86900a0020500203510060144e900100924a1018141a028012913f0041802250042280481200002004430804210101c08111c10801001080002038008211004266848606b035001048"); + TEST_CHECK(aux::to_hex(bf_str) == "24c0004020043000102012743e00480037110820422110008000c0e302854835a05401a4045021302a306c060001881002d8a0a3a8001901b40a800900310008d2108110c2496a0028700010d804188b01415200082004088026411104a804048002002000080680828c400080cc40020c042c0494447280928041402104080d4240040414a41f0205654800b0811830d2020042b002c5800004a71d0204804a0028120a004c10017801490b834004044106005421000c86900a0020500203510060144e900100924a1018141a028012913f0041802250042280481200002004430804210101c08111c10801001080002038008211004266848606b035001048"); } } @@ -1057,8 +1058,8 @@ void test_put(address(&rand_addr)()) ed25519_create_keypair((unsigned char*)pk.bytes.data() , (unsigned char*)sk.bytes.data(), seed); std::fprintf(stderr, "pub: %s priv: %s\n" - , aux::to_hex(std::string(pk.bytes.data(), public_key::len)).c_str() - , aux::to_hex(std::string(sk.bytes.data(), secret_key::len)).c_str()); + , aux::to_hex(pk.bytes).c_str() + , aux::to_hex(sk.bytes).c_str()); std::string salt; if (with_salt) salt = "foobar"; @@ -1068,7 +1069,7 @@ void test_put(address(&rand_addr)()) sha1_hash target_id = h.final(); std::fprintf(stderr, "target_id: %s\n" - , aux::to_hex(target_id.to_string()).c_str()); + , aux::to_hex(target_id).c_str()); send_dht_request(t.dht_node, "get", t.source, &response , msg_args().target(target_id)); @@ -1135,7 +1136,7 @@ void test_put(address(&rand_addr)()) , msg_args().target(target_id)); std::fprintf(stderr, "target_id: %s\n" - , aux::to_hex(target_id.to_string()).c_str()); + , aux::to_hex(target_id).c_str()); key_desc_t const desc3[] = { @@ -1516,15 +1517,15 @@ void test_routing_table(address(&rand_addr)()) for (int i = 0; i < 5; ++i) { - address a = addr4(ips[i]); - node_id id = generate_id_impl(a, rs[i]); + address const a = addr4(ips[i]); + node_id const id = generate_id_impl(a, rs[i]); TEST_CHECK(id[0] == prefixes[i][0]); TEST_CHECK(id[1] == prefixes[i][1]); TEST_CHECK((id[2] & 0xf8) == (prefixes[i][2] & 0xf8)); TEST_CHECK(id[19] == rs[i]); std::fprintf(stderr, "IP address: %s r: %d node ID: %s\n", ips[i] - , rs[i], aux::to_hex(id.to_string()).c_str()); + , rs[i], aux::to_hex(id).c_str()); } } @@ -2392,12 +2393,12 @@ TORRENT_TEST(signing_test1) signature sig; sign_mutable_item(test_content, empty_salt, sequence_number(1), pk, sk, sig); - TEST_EQUAL(aux::to_hex(std::string(sig.bytes.data(), signature::len)) + TEST_EQUAL(aux::to_hex(sig.bytes) , "305ac8aeb6c9c151fa120f120ea2cfb923564e11552d06a5d856091e5e853cff" "1260d3f39e4999684aa92eb73ffd136e6f4f3ecbfda0ce53a1608ecd7ae21f01"); - sha1_hash target_id = item_target_id(empty_salt, pk); - TEST_EQUAL(aux::to_hex(target_id.to_string()), "4a533d47ec9c7d95b1ad75f576cffc641853b750"); + sha1_hash const target_id = item_target_id(empty_salt, pk); + TEST_EQUAL(aux::to_hex(target_id), "4a533d47ec9c7d95b1ad75f576cffc641853b750"); } TORRENT_TEST(signing_test2) @@ -2416,12 +2417,12 @@ TORRENT_TEST(signing_test2) // test vector 2 (the keypair is the same as test 1) sign_mutable_item(test_content, test_salt, sequence_number(1), pk, sk, sig); - TEST_EQUAL(aux::to_hex(std::string(sig.bytes.data(), signature::len)) + TEST_EQUAL(aux::to_hex(sig.bytes) , "6834284b6b24c3204eb2fea824d82f88883a3d95e8b4a21b8c0ded553d17d17d" "df9a8a7104b1258f30bed3787e6cb896fca78c58f8e03b5f18f14951a87d9a08"); sha1_hash target_id = item_target_id(test_salt, pk); - TEST_EQUAL(aux::to_hex(target_id.to_string()), "411eba73b6f087ca51a3795d9c8c938d365e32c1"); + TEST_EQUAL(aux::to_hex(target_id), "411eba73b6f087ca51a3795d9c8c938d365e32c1"); } TORRENT_TEST(signing_test3) @@ -2432,7 +2433,7 @@ TORRENT_TEST(signing_test3) span test_content("12:Hello World!", 15); sha1_hash target_id = item_target_id(test_content); - TEST_EQUAL(aux::to_hex(target_id.to_string()), "e5f96f6f38320f0f33959cb4d3d656452117aadb"); + TEST_EQUAL(aux::to_hex(target_id), "e5f96f6f38320f0f33959cb4d3d656452117aadb"); } // TODO: 2 split this up into smaller test cases diff --git a/test/test_hasher.cpp b/test/test_hasher.cpp index 9f1f4028d..beca7d3a1 100644 --- a/test/test_hasher.cpp +++ b/test/test_hasher.cpp @@ -70,7 +70,7 @@ TORRENT_TEST(hasher) h.update(test_array[test], int(std::strlen(test_array[test]))); sha1_hash result; - aux::from_hex(result_array[test], 40, (char*)&result[0]); + aux::from_hex({result_array[test], 40}, (char*)&result[0]); TEST_CHECK(result == h.final()); } } diff --git a/test/test_magnet.cpp b/test/test_magnet.cpp index 8f827c9ce..37c552129 100644 --- a/test/test_magnet.cpp +++ b/test/test_magnet.cpp @@ -177,7 +177,8 @@ TORRENT_TEST(magnet) std::fprintf(stderr, "3: %s\n", trackers[2].url.c_str()); } - TEST_EQUAL(aux::to_hex(t.info_hash().to_string()), "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"); + sha1_hash const ih = t.info_hash(); + TEST_EQUAL(aux::to_hex(ih), "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"); p1 = s->abort(); s.reset(new lt::session()); diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index 27ac90d35..2294ce07a 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -44,7 +44,7 @@ using namespace libtorrent; sha1_hash to_hash(char const* s) { sha1_hash ret; - aux::from_hex(s, 40, (char*)&ret[0]); + aux::from_hex({s, 40}, (char*)&ret[0]); return ret; } diff --git a/test/test_read_piece.cpp b/test/test_read_piece.cpp index f314ba0d9..983165d79 100644 --- a/test/test_read_piece.cpp +++ b/test/test_read_piece.cpp @@ -87,7 +87,7 @@ void test_read_piece(int flags) boost::shared_ptr ti(new torrent_info(&buf[0], int(buf.size()), ec)); std::fprintf(stderr, "generated torrent: %s tmp1_read_piece/test_torrent\n" - , aux::to_hex(ti->info_hash().to_string()).c_str()); + , aux::to_hex(ti->info_hash()).c_str()); const int mask = alert::all_categories & ~(alert::progress_notification diff --git a/test/test_resolve_links.cpp b/test/test_resolve_links.cpp index d5d14345a..3f17c97c8 100644 --- a/test/test_resolve_links.cpp +++ b/test/test_resolve_links.cpp @@ -121,8 +121,8 @@ TORRENT_TEST(resolve_links) { TORRENT_ASSERT(i < fs.num_files()); std::fprintf(stderr, "%s --> %s : %d\n", fs.file_name(i).c_str() - , links[i].ti ? aux::to_hex(links[i].ti->info_hash() - .to_string()).c_str() : "", links[i].file_idx); + , links[i].ti ? aux::to_hex(links[i].ti->info_hash()).c_str() + : "", links[i].file_idx); } } diff --git a/test/test_sha1_hash.cpp b/test/test_sha1_hash.cpp index 8d9932bd4..774cf5285 100644 --- a/test/test_sha1_hash.cpp +++ b/test/test_sha1_hash.cpp @@ -39,7 +39,7 @@ using namespace libtorrent; static sha1_hash to_hash(char const* s) { sha1_hash ret; - aux::from_hex(s, 40, (char*)&ret[0]); + aux::from_hex({s, 40}, ret.data()); return ret; } diff --git a/test/test_string.cpp b/test/test_string.cpp index 21bc264e7..6cb5a22db 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -54,21 +54,21 @@ TORRENT_TEST(hex) { static char const str[] = "0123456789012345678901234567890123456789"; char bin[20]; - TEST_CHECK(aux::from_hex(str, 40, bin)); + TEST_CHECK(aux::from_hex({str, 40}, bin)); char hex[41]; - aux::to_hex(bin, 20, hex); + aux::to_hex(bin, hex); TEST_CHECK(strcmp(hex, str) == 0); - TEST_CHECK(aux::to_hex("\x55\x73") == "5573"); - TEST_CHECK(aux::to_hex("\xaB\xd0") == "abd0"); + TEST_CHECK(aux::to_hex({"\x55\x73",2}) == "5573"); + TEST_CHECK(aux::to_hex({"\xaB\xd0",2}) == "abd0"); static char const hex_chars[] = "0123456789abcdefABCDEF"; for (int i = 1; i < 255; ++i) { - bool hex = strchr(hex_chars, i) != nullptr; - char c = i; - TEST_EQUAL(aux::is_hex(&c, 1), hex); + bool const hex = strchr(hex_chars, i) != nullptr; + char const c = i; + TEST_EQUAL(aux::is_hex(c), hex); } TEST_EQUAL(aux::hex_to_int('0'), 0); diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 3778df647..6d1f2d973 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -717,9 +717,10 @@ TORRENT_TEST(parse_torrents) file_storage const& fs = ti->files(); for (int i = 0; i < fs.num_files(); ++i) { - int first = ti->map_file(i, 0, 0).piece; - int last = ti->map_file(i, (std::max)(fs.file_size(i)-1, std::int64_t(0)), 0).piece; - int flags = fs.file_flags(i); + int const first = ti->map_file(i, 0, 0).piece; + int const last = ti->map_file(i, (std::max)(fs.file_size(i)-1, std::int64_t(0)), 0).piece; + int const flags = fs.file_flags(i); + sha1_hash const ih = fs.hash(i); std::fprintf(stderr, " %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" , fs.file_size(i) , (flags & file_storage::flag_pad_file)?'p':'-' @@ -728,7 +729,7 @@ TORRENT_TEST(parse_torrents) , (flags & file_storage::flag_symlink)?'l':'-' , first, last , std::uint32_t(fs.mtime(i)) - , fs.hash(i) != sha1_hash(nullptr) ? aux::to_hex(fs.hash(i).to_string()).c_str() : "" + , ih != sha1_hash(nullptr) ? aux::to_hex(ih).c_str() : "" , fs.file_path(i).c_str() , flags & file_storage::flag_symlink ? "-> ": "" , flags & file_storage::flag_symlink ? fs.symlink(i).c_str() : "");