1 #ifndef LIBFILEZILLA_BUFFER_HEADER
2 #define LIBFILEZILLA_BUFFER_HEADER
29 buffer() noexcept =
default;
32 explicit buffer(
size_t capacity);
37 ~
buffer() {
delete[] data_; }
43 unsigned char const*
get()
const {
return pos_; }
44 unsigned char*
get() {
return pos_; }
64 unsigned char*
get(
size_t write_size);
67 void add(
size_t added);
75 template<
typename T, std::enable_if_t<std::is_
signed_v<T>,
int> = 0>
78 add(static_cast<size_t>(added));
86 void consume(
size_t consumed);
88 size_t size()
const {
return size_; }
99 void append(
unsigned char const* data,
size_t len);
100 void append(std::string_view
const& str);
101 void append(std::vector<uint8_t>
const& data);
103 void append(
unsigned char v);
104 void append(
size_t len,
unsigned char c);
106 buffer& operator+=(
unsigned char v) {
110 buffer& operator+=(std::string_view
const& str) {
114 buffer& operator+=(std::vector<uint8_t>
const& data) {
123 bool empty()
const {
return size_ == 0; }
124 explicit operator bool()
const {
128 size_t capacity()
const {
return capacity_; }
129 void reserve(
size_t capacity);
131 void resize(
size_t size);
135 unsigned char & operator[](
size_t i) {
return pos_[i]; }
139 bool operator!=(buffer
const& rhs)
const {
140 return !(*
this == rhs);
143 std::string_view to_view()
const;
151 unsigned char* data_{};
152 unsigned char* pos_{};
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.
void add(T added)
Overload of add for signed types, only adds if value is positive.
Definition: buffer.hpp:76
The namespace used by libfilezilla.
Definition: apply.hpp:17
Sets some global macros and further includes string.hpp.
The buffer class is a simple buffer where data can be appended at the end and consumed at the front...
Definition: buffer.hpp:26
unsigned char operator[](size_t i) const
Gets element at offset i. Does not do bounds checking.
Definition: buffer.hpp:134