29 #include <boost/optional/optional.hpp>
35 static constexpr
const char hex[] =
u8"0123456789abcdef";
41 if (c >=
'A' && c <=
'Z')
76 memwipe(&other[0], other.size());
91 memcpy(buffer.data(), s, len);
102 memwipe(buffer.data(), buffer.size() *
sizeof(
char));
105 void wipeable_string::grow(
size_t sz,
size_t reserved)
109 if (reserved <= buffer.capacity())
111 if (sz < buffer.size())
112 memwipe(buffer.data() + sz, buffer.size() - sz);
116 size_t old_sz = buffer.size();
117 std::unique_ptr<char[]> tmp{
new char[old_sz]};
120 memcpy(tmp.get(), buffer.data(), old_sz *
sizeof(
char));
121 memwipe(buffer.data(), old_sz *
sizeof(
char));
123 buffer.reserve(reserved);
127 memcpy(buffer.data(), tmp.get(), old_sz *
sizeof(
char));
128 memwipe(tmp.get(), old_sz *
sizeof(
char));
145 const size_t orgsz =
size();
164 append(s.c_str(), s.size());
170 while (prefix <
size() &&
data()[prefix] ==
' ')
173 memmove(buffer.data(), buffer.data() + prefix,
size() - prefix);
176 while (suffix <
size()-prefix &&
data()[
size() - 1 - prefix - suffix] ==
' ')
186 const char *ptr =
data();
190 const char c = *ptr++;
194 fields.push_back({});
195 fields.back().push_back(c);
206 const size_t len =
size();
207 const char *d =
data();
208 res->grow(0, len / 2);
209 for (
size_t i = 0; i < len; i += 2)
211 char c = atolower(d[i]);
212 const char *ptr0 = strchr(hex, c);
215 c = atolower(d[i+1]);
216 const char *ptr1 = strchr(hex, c);
219 res->push_back(((ptr0-hex)<<4) | (ptr1-hex));
226 const size_t sz =
size();
228 const char c = buffer.back();
258 buffer = other.buffer;
void split(std::vector< wipeable_string > &fields) const
void append(const char *ptr, size_t len)
const char * data() const noexcept
boost::optional< wipeable_string > parse_hexstr() const
wipeable_string & operator=(wipeable_string &&other)
size_t size() const noexcept
void * memcpy(void *a, const void *b, size_t c)
void * memmove(void *a, const void *b, size_t c)
void * memwipe(void *src, size_t n)
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
const T & move(const T &t)