aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee')
-rw-r--r--contrib/epee/include/byte_slice.h10
-rw-r--r--contrib/epee/include/net/http_base.h6
-rw-r--r--contrib/epee/include/net/http_client.h5
-rw-r--r--contrib/epee/src/byte_slice.cpp19
4 files changed, 35 insertions, 5 deletions
diff --git a/contrib/epee/include/byte_slice.h b/contrib/epee/include/byte_slice.h
index 1fbba101e..bd9452b11 100644
--- a/contrib/epee/include/byte_slice.h
+++ b/contrib/epee/include/byte_slice.h
@@ -42,7 +42,12 @@ namespace epee
struct release_byte_slice
{
- void operator()(byte_slice_data*) const noexcept;
+ //! For use with `zmq_message_init_data`, use second arg for buffer pointer.
+ static void call(void*, void* ptr) noexcept;
+ void operator()(byte_slice_data* ptr) const noexcept
+ {
+ call(nullptr, ptr);
+ }
};
/*! Inspired by slices in golang. Storage is thread-safe reference counted,
@@ -140,6 +145,9 @@ namespace epee
\throw std::out_of_range If `size() < end`.
\return Slice starting at `data() + begin` of size `end - begin`. */
byte_slice get_slice(std::size_t begin, std::size_t end) const;
+
+ //! \post `empty()` \return Ownership of ref-counted buffer.
+ std::unique_ptr<byte_slice_data, release_byte_slice> take_buffer() noexcept;
};
} // epee
diff --git a/contrib/epee/include/net/http_base.h b/contrib/epee/include/net/http_base.h
index a66fb7c23..bf6589c92 100644
--- a/contrib/epee/include/net/http_base.h
+++ b/contrib/epee/include/net/http_base.h
@@ -33,6 +33,7 @@
#include <string>
#include <utility>
+#include "memwipe.h"
#include "string_tools.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -200,6 +201,11 @@ namespace net_utils
this->~http_response_info();
new(this) http_response_info();
}
+
+ void wipe()
+ {
+ memwipe(&m_body[0], m_body.size());
+ }
};
}
}
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h
index d329b8cf2..86df48f65 100644
--- a/contrib/epee/include/net/http_client.h
+++ b/contrib/epee/include/net/http_client.h
@@ -330,6 +330,11 @@ namespace net_utils
return m_net_client.get_bytes_received();
}
//---------------------------------------------------------------------------
+ void wipe_response()
+ {
+ m_response_info.wipe();
+ }
+ //---------------------------------------------------------------------------
private:
//---------------------------------------------------------------------------
inline bool handle_reciev(std::chrono::milliseconds timeout)
diff --git a/contrib/epee/src/byte_slice.cpp b/contrib/epee/src/byte_slice.cpp
index 216049e5b..3ad3b3e7e 100644
--- a/contrib/epee/src/byte_slice.cpp
+++ b/contrib/epee/src/byte_slice.cpp
@@ -49,12 +49,16 @@ namespace epee
std::atomic<std::size_t> ref_count;
};
- void release_byte_slice::operator()(byte_slice_data* ptr) const noexcept
+ void release_byte_slice::call(void*, void* ptr) noexcept
{
- if (ptr && --(ptr->ref_count) == 0)
+ if (ptr)
{
- ptr->~byte_slice_data();
- free(ptr);
+ byte_slice_data* self = static_cast<byte_slice_data*>(ptr);
+ if (--(self->ref_count) == 0)
+ {
+ self->~byte_slice_data();
+ free(self);
+ }
}
}
@@ -206,4 +210,11 @@ namespace epee
return {};
return {storage_.get(), {portion_.begin() + begin, end - begin}};
}
+
+ std::unique_ptr<byte_slice_data, release_byte_slice> byte_slice::take_buffer() noexcept
+ {
+ std::unique_ptr<byte_slice_data, release_byte_slice> out{std::move(storage_)};
+ portion_ = nullptr;
+ return out;
+ }
} // epee