29 #include <boost/optional/optional.hpp> 36 static constexpr
const char hex[] =
u8"0123456789abcdef";
42 if (c >=
'A' && c <=
'Z')
77 memwipe(&other[0], other.size());
92 memcpy(buffer.data(), s, len);
103 memwipe(buffer.data(), buffer.size() *
sizeof(char));
106 void wipeable_string::grow(
size_t sz,
size_t reserved)
110 if (reserved <= buffer.capacity())
112 if (sz < buffer.size())
113 memwipe(buffer.data() + sz, buffer.size() - sz);
117 size_t old_sz = buffer.size();
118 std::unique_ptr<char[]> tmp{
new char[old_sz]};
121 memcpy(tmp.get(), buffer.data(), old_sz *
sizeof(char));
122 memwipe(buffer.data(), old_sz *
sizeof(char));
124 buffer.reserve(reserved);
128 memcpy(buffer.data(), tmp.get(), old_sz *
sizeof(char));
129 memwipe(tmp.get(), old_sz *
sizeof(char));
146 const size_t orgsz =
size();
165 append(s.c_str(), s.size());
171 while (prefix <
size() &&
data()[prefix] ==
' ')
174 memmove(buffer.data(), buffer.data() + prefix,
size() - prefix);
177 while (suffix <
size()-prefix &&
data()[
size() - 1 - prefix - suffix] ==
' ')
187 const char *ptr =
data();
191 const char c = *ptr++;
195 fields.push_back({});
196 fields.back().push_back(c);
207 const size_t len =
size();
208 const char *d =
data();
209 res->grow(0, len / 2);
210 for (
size_t i = 0; i < len; i += 2)
212 char c = atolower(d[i]);
213 const char *ptr0 = strchr(hex, c);
216 c = atolower(d[i+1]);
217 const char *ptr1 = strchr(hex, c);
220 res->push_back(((ptr0-hex)<<4) | (ptr1-hex));
227 const size_t sz =
size();
229 const char c = buffer.back();
259 buffer = other.buffer;
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
boost::optional< wipeable_string > parse_hexstr() const
size_t size() const noexcept
void append(const char *ptr, size_t len)
void split(std::vector< wipeable_string > &fields) const
wipeable_string & operator=(wipeable_string &&other)
const T & move(const T &t)
void * memcpy(void *a, const void *b, size_t c)
void * memwipe(void *src, size_t n)
const char * data() const noexcept
void * memmove(void *a, const void *b, size_t c)