PRCYCoin  2.0.0.7rc1
P2P Digital Currency
utilstrencodings.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2015-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #include "utilstrencodings.h"
9 
10 #include "tinyformat.h"
11 
12 #include <cstdlib>
13 #include <cstring>
14 #include <errno.h>
15 #include <limits>
16 
17 #include <openssl/bio.h>
18 #include <openssl/buffer.h>
19 #include <openssl/evp.h>
20 
21 
22 
23 static const std::string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
24 
25 static const std::string SAFE_CHARS[] =
26 {
27  CHARS_ALPHA_NUM + " .,;-_/:?@()", // SAFE_CHARS_DEFAULT
28  CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
29  CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
30 };
31 
32 std::string SanitizeString(const std::string& str, int rule)
33 {
34  std::string strResult;
35  for (std::string::size_type i = 0; i < str.size(); i++)
36  {
37  if (SAFE_CHARS[rule].find(str[i]) != std::string::npos)
38  strResult.push_back(str[i]);
39  }
40  return strResult;
41 }
42 
43 const signed char p_util_hexdigit[256] =
44  {
45  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
47  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
48  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
49  -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
50  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
51  -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1,
52  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
53  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
54  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
55  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
56  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
57  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
58  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
59  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
60  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
61 };
62 
63 signed char HexDigit(char c)
64 {
65  return p_util_hexdigit[(unsigned char)c];
66 }
67 
68 bool IsHex(const std::string& str)
69 {
70  for (std::string::const_iterator it(str.begin()); it != str.end(); ++it) {
71  if (HexDigit(*it) < 0)
72  return false;
73  }
74  return (str.size() > 0) && (str.size() % 2 == 0);
75 }
76 
77 std::vector<unsigned char> ParseHex(const char* psz)
78 {
79  // convert hex dump to vector
80  std::vector<unsigned char> vch;
81  while (true) {
82  while (isspace(*psz))
83  psz++;
84  signed char c = HexDigit(*psz++);
85  if (c == (signed char)-1)
86  break;
87  unsigned char n = (c << 4);
88  c = HexDigit(*psz++);
89  if (c == (signed char)-1)
90  break;
91  n |= c;
92  vch.push_back(n);
93  }
94  return vch;
95 }
96 
97 std::vector<unsigned char> ParseHex(const std::string& str)
98 {
99  return ParseHex(str.c_str());
100 }
101 
102 std::string EncodeBase64(const unsigned char* pch, size_t len)
103 {
104  static const char* pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
105 
106  std::string strRet = "";
107  strRet.reserve((len + 2) / 3 * 4);
108 
109  int mode = 0, left = 0;
110  const unsigned char* pchEnd = pch + len;
111 
112  while (pch < pchEnd) {
113  int enc = *(pch++);
114  switch (mode) {
115  case 0: // we have no bits
116  strRet += pbase64[enc >> 2];
117  left = (enc & 3) << 4;
118  mode = 1;
119  break;
120 
121  case 1: // we have two bits
122  strRet += pbase64[left | (enc >> 4)];
123  left = (enc & 15) << 2;
124  mode = 2;
125  break;
126 
127  case 2: // we have four bits
128  strRet += pbase64[left | (enc >> 6)];
129  strRet += pbase64[enc & 63];
130  mode = 0;
131  break;
132  }
133  }
134 
135  if (mode) {
136  strRet += pbase64[left];
137  strRet += '=';
138  if (mode == 1)
139  strRet += '=';
140  }
141 
142  return strRet;
143 }
144 
145 std::string EncodeBase64(const std::string& str)
146 {
147  return EncodeBase64((const unsigned char*)str.c_str(), str.size());
148 }
149 
150 std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
151 {
152  static const int decode64_table[256] =
153  {
154  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
155  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156  -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
157  -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
158  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
159  29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
160  49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
162  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
163  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
164  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
165  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
166  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
167 
168  if (pfInvalid)
169  *pfInvalid = false;
170 
171  std::vector<unsigned char> vchRet;
172  vchRet.reserve(strlen(p) * 3 / 4);
173 
174  int mode = 0;
175  int left = 0;
176 
177  while (1) {
178  int dec = decode64_table[(unsigned char)*p];
179  if (dec == -1) break;
180  p++;
181  switch (mode) {
182  case 0: // we have no bits and get 6
183  left = dec;
184  mode = 1;
185  break;
186 
187  case 1: // we have 6 bits and keep 4
188  vchRet.push_back((left << 2) | (dec >> 4));
189  left = dec & 15;
190  mode = 2;
191  break;
192 
193  case 2: // we have 4 bits and get 6, we keep 2
194  vchRet.push_back((left << 4) | (dec >> 2));
195  left = dec & 3;
196  mode = 3;
197  break;
198 
199  case 3: // we have 2 bits and get 6
200  vchRet.push_back((left << 6) | dec);
201  mode = 0;
202  break;
203  }
204  }
205 
206  if (pfInvalid)
207  switch (mode) {
208  case 0: // 4n base64 characters processed: ok
209  break;
210 
211  case 1: // 4n+1 base64 character processed: impossible
212  *pfInvalid = true;
213  break;
214 
215  case 2: // 4n+2 base64 characters processed: require '=='
216  if (left || p[0] != '=' || p[1] != '=' || decode64_table[(unsigned char)p[2]] != -1)
217  *pfInvalid = true;
218  break;
219 
220  case 3: // 4n+3 base64 characters processed: require '='
221  if (left || p[0] != '=' || decode64_table[(unsigned char)p[1]] != -1)
222  *pfInvalid = true;
223  break;
224  }
225 
226  return vchRet;
227 }
228 
229 std::string DecodeBase64(const std::string& str)
230 {
231  std::vector<unsigned char> vchRet = DecodeBase64(str.c_str());
232  return (vchRet.size() == 0) ? std::string() : std::string((const char*)&vchRet[0], vchRet.size());
233 }
234 
235 // Base64 decoding with secure memory allocation
237 {
238  SecureString output;
239 
240  // Init openssl BIO with base64 filter and memory input
241  BIO *b64, *mem;
242  b64 = BIO_new(BIO_f_base64());
243  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer
244  mem = BIO_new_mem_buf((void*)&input[0], input.size());
245  BIO_push(b64, mem);
246 
247  // Prepare buffer to receive decoded data
248  if (input.size() % 4 != 0) {
249  throw std::runtime_error("Input length should be a multiple of 4");
250  }
251  size_t nMaxLen = input.size() / 4 * 3; // upper bound, guaranteed divisible by 4
252  output.resize(nMaxLen);
253 
254  // Decode the string
255  size_t nLen;
256  nLen = BIO_read(b64, (void*)&output[0], input.size());
257  output.resize(nLen);
258 
259  // Free memory
260  BIO_free_all(b64);
261  return output;
262 }
263 
264 // Base64 encoding with secure memory allocation
266 {
267  // Init openssl BIO with base64 filter and memory output
268  BIO *b64, *mem;
269  b64 = BIO_new(BIO_f_base64());
270  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); // No newlines in output
271  mem = BIO_new(BIO_s_mem());
272  BIO_push(b64, mem);
273 
274  // Decode the string
275  BIO_write(b64, &input[0], input.size());
276  (void)BIO_flush(b64);
277 
278  // Create output variable from buffer mem ptr
279  BUF_MEM* bptr;
280  BIO_get_mem_ptr(b64, &bptr);
281  SecureString output(bptr->data, bptr->length);
282 
283  // Cleanse secure data buffer from memory
284  memory_cleanse((void*)bptr->data, bptr->length);
285 
286  // Free memory
287  BIO_free_all(b64);
288  return output;
289 }
290 
291 std::string EncodeBase32(const unsigned char* pch, size_t len)
292 {
293  static const char* pbase32 = "abcdefghijklmnopqrstuvwxyz234567";
294 
295  std::string strRet = "";
296  strRet.reserve((len + 4) / 5 * 8);
297 
298  int mode = 0, left = 0;
299  const unsigned char* pchEnd = pch + len;
300 
301  while (pch < pchEnd) {
302  int enc = *(pch++);
303  switch (mode) {
304  case 0: // we have no bits
305  strRet += pbase32[enc >> 3];
306  left = (enc & 7) << 2;
307  mode = 1;
308  break;
309 
310  case 1: // we have three bits
311  strRet += pbase32[left | (enc >> 6)];
312  strRet += pbase32[(enc >> 1) & 31];
313  left = (enc & 1) << 4;
314  mode = 2;
315  break;
316 
317  case 2: // we have one bit
318  strRet += pbase32[left | (enc >> 4)];
319  left = (enc & 15) << 1;
320  mode = 3;
321  break;
322 
323  case 3: // we have four bits
324  strRet += pbase32[left | (enc >> 7)];
325  strRet += pbase32[(enc >> 2) & 31];
326  left = (enc & 3) << 3;
327  mode = 4;
328  break;
329 
330  case 4: // we have two bits
331  strRet += pbase32[left | (enc >> 5)];
332  strRet += pbase32[enc & 31];
333  mode = 0;
334  }
335  }
336 
337  static const int nPadding[5] = {0, 6, 4, 3, 1};
338  if (mode) {
339  strRet += pbase32[left];
340  for (int n = 0; n < nPadding[mode]; n++)
341  strRet += '=';
342  }
343 
344  return strRet;
345 }
346 
347 std::string EncodeBase32(const std::string& str)
348 {
349  return EncodeBase32((const unsigned char*)str.c_str(), str.size());
350 }
351 
352 std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
353 {
354  static const int decode32_table[256] =
355  {
356  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
357  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
358  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
359  -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
360  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
361  3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
362  23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
363  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
364  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
365  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
366  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
367  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
368  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
369 
370  if (pfInvalid)
371  *pfInvalid = false;
372 
373  std::vector<unsigned char> vchRet;
374  vchRet.reserve((strlen(p)) * 5 / 8);
375 
376  int mode = 0;
377  int left = 0;
378 
379  while (1) {
380  int dec = decode32_table[(unsigned char)*p];
381  if (dec == -1) break;
382  p++;
383  switch (mode) {
384  case 0: // we have no bits and get 5
385  left = dec;
386  mode = 1;
387  break;
388 
389  case 1: // we have 5 bits and keep 2
390  vchRet.push_back((left << 3) | (dec >> 2));
391  left = dec & 3;
392  mode = 2;
393  break;
394 
395  case 2: // we have 2 bits and keep 7
396  left = left << 5 | dec;
397  mode = 3;
398  break;
399 
400  case 3: // we have 7 bits and keep 4
401  vchRet.push_back((left << 1) | (dec >> 4));
402  left = dec & 15;
403  mode = 4;
404  break;
405 
406  case 4: // we have 4 bits, and keep 1
407  vchRet.push_back((left << 4) | (dec >> 1));
408  left = dec & 1;
409  mode = 5;
410  break;
411 
412  case 5: // we have 1 bit, and keep 6
413  left = left << 5 | dec;
414  mode = 6;
415  break;
416 
417  case 6: // we have 6 bits, and keep 3
418  vchRet.push_back((left << 2) | (dec >> 3));
419  left = dec & 7;
420  mode = 7;
421  break;
422 
423  case 7: // we have 3 bits, and keep 0
424  vchRet.push_back((left << 5) | dec);
425  mode = 0;
426  break;
427  }
428  }
429 
430  if (pfInvalid)
431  switch (mode) {
432  case 0: // 8n base32 characters processed: ok
433  break;
434 
435  case 1: // 8n+1 base32 characters processed: impossible
436  case 3: // +3
437  case 6: // +6
438  *pfInvalid = true;
439  break;
440 
441  case 2: // 8n+2 base32 characters processed: require '======'
442  if (left || p[0] != '=' || p[1] != '=' || p[2] != '=' || p[3] != '=' || p[4] != '=' || p[5] != '=' || decode32_table[(unsigned char)p[6]] != -1)
443  *pfInvalid = true;
444  break;
445 
446  case 4: // 8n+4 base32 characters processed: require '===='
447  if (left || p[0] != '=' || p[1] != '=' || p[2] != '=' || p[3] != '=' || decode32_table[(unsigned char)p[4]] != -1)
448  *pfInvalid = true;
449  break;
450 
451  case 5: // 8n+5 base32 characters processed: require '==='
452  if (left || p[0] != '=' || p[1] != '=' || p[2] != '=' || decode32_table[(unsigned char)p[3]] != -1)
453  *pfInvalid = true;
454  break;
455 
456  case 7: // 8n+7 base32 characters processed: require '='
457  if (left || p[0] != '=' || decode32_table[(unsigned char)p[1]] != -1)
458  *pfInvalid = true;
459  break;
460  }
461 
462  return vchRet;
463 }
464 
465 std::string DecodeBase32(const std::string& str)
466 {
467  std::vector<unsigned char> vchRet = DecodeBase32(str.c_str());
468  return (vchRet.size() == 0) ? std::string() : std::string((const char*)&vchRet[0], vchRet.size());
469 }
470 
471 static bool ParsePrechecks(const std::string& str)
472 {
473  if (str.empty()) // No empty string allowed
474  return false;
475  if (str.size() >= 1 && (isspace(str[0]) || isspace(str[str.size()-1]))) // No padding allowed
476  return false;
477  if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
478  return false;
479  return true;
480 }
481 
482 bool ParseInt32(const std::string& str, int32_t *out)
483 {
484  if (!ParsePrechecks(str))
485  return false;
486  char *endp = NULL;
487  errno = 0; // strtol will not set errno if valid
488  long int n = strtol(str.c_str(), &endp, 10);
489  if(out) *out = (int32_t)n;
490  // Note that strtol returns a *long int*, so even if strtol doesn't report a over/underflow
491  // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
492  // platforms the size of these types may be different.
493  return endp && *endp == 0 && !errno &&
494  n >= std::numeric_limits<int32_t>::min() &&
495  n <= std::numeric_limits<int32_t>::max();
496 }
497 
498 bool ParseInt64(const std::string& str, int64_t *out)
499 {
500  if (!ParsePrechecks(str))
501  return false;
502  char *endp = NULL;
503  errno = 0; // strtoll will not set errno if valid
504  long long int n = strtoll(str.c_str(), &endp, 10);
505  if(out) *out = (int64_t)n;
506  // Note that strtoll returns a *long long int*, so even if strtol doesn't report a over/underflow
507  // we still have to check that the returned value is within the range of an *int64_t*.
508  return endp && *endp == 0 && !errno &&
509  n >= std::numeric_limits<int64_t>::min() &&
510  n <= std::numeric_limits<int64_t>::max();
511 }
512 
513 bool ParseDouble(const std::string& str, double *out)
514 {
515  if (!ParsePrechecks(str))
516  return false;
517  if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
518  return false;
519  std::istringstream text(str);
520  text.imbue(std::locale::classic());
521  double result;
522  text >> result;
523  if(out) *out = result;
524  return text.eof() && !text.fail();
525 }
526 
527 std::string FormatParagraph(const std::string in, size_t width, size_t indent)
528 {
529  std::stringstream out;
530  size_t col = 0;
531  size_t ptr = 0;
532  while (ptr < in.size()) {
533  // Find beginning of next word
534  ptr = in.find_first_not_of(' ', ptr);
535  if (ptr == std::string::npos)
536  break;
537  // Find end of next word
538  size_t endword = in.find_first_of(' ', ptr);
539  if (endword == std::string::npos)
540  endword = in.size();
541  // Add newline and indentation if this wraps over the allowed width
542  if (col > 0) {
543  if ((col + endword - ptr) > width) {
544  out << '\n';
545  for (size_t i = 0; i < indent; ++i)
546  out << ' ';
547  col = 0;
548  } else
549  out << ' ';
550  }
551  // Append word
552  out << in.substr(ptr, endword - ptr);
553  col += endword - ptr + 1;
554  ptr = endword;
555  }
556  return out.str();
557 }
558 
559 std::string i64tostr(int64_t n)
560 {
561  return strprintf("%d", n);
562 }
563 
564 std::string itostr(int n)
565 {
566  return strprintf("%d", n);
567 }
568 
569 int64_t atoi64(const char* psz)
570 {
571 #ifdef _MSC_VER
572  return _atoi64(psz);
573 #else
574  return strtoll(psz, NULL, 10);
575 #endif
576 }
577 
578 int64_t atoi64(const std::string& str)
579 {
580 #ifdef _MSC_VER
581  return _atoi64(str.c_str());
582 #else
583  return strtoll(str.c_str(), NULL, 10);
584 #endif
585 }
586 
587 int atoi(const std::string& str)
588 {
589  return atoi(str.c_str());
590 }
p_util_hexdigit
const signed char p_util_hexdigit[256]
Definition: utilstrencodings.cpp:43
EncodeBase64Secure
SecureString EncodeBase64Secure(const SecureString &input)
Definition: utilstrencodings.cpp:265
ParseHex
std::vector< unsigned char > ParseHex(const char *psz)
Definition: utilstrencodings.cpp:77
DecodeBase32
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid)
Definition: utilstrencodings.cpp:352
ParseInt64
bool ParseInt64(const std::string &str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
Definition: utilstrencodings.cpp:498
SanitizeString
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
Definition: utilstrencodings.cpp:32
memory_cleanse
void memory_cleanse(void *ptr, size_t len)
Definition: cleanse.cpp:27
atoi
int atoi(const std::string &str)
Definition: utilstrencodings.cpp:587
tinyformat.h
DecodeBase64
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
Definition: utilstrencodings.cpp:150
DecodeBase64Secure
SecureString DecodeBase64Secure(const SecureString &input)
Definition: utilstrencodings.cpp:236
IsHex
bool IsHex(const std::string &str)
Definition: utilstrencodings.cpp:68
SecureString
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: allocators.h:262
EncodeBase64
std::string EncodeBase64(const unsigned char *pch, size_t len)
Definition: utilstrencodings.cpp:102
ParseDouble
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
Definition: utilstrencodings.cpp:513
FormatParagraph
std::string FormatParagraph(const std::string in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
Definition: utilstrencodings.cpp:527
strprintf
#define strprintf
Definition: tinyformat.h:1056
atoi64
int64_t atoi64(const char *psz)
Definition: utilstrencodings.cpp:569
itostr
std::string itostr(int n)
Definition: utilstrencodings.cpp:564
HexDigit
signed char HexDigit(char c)
Definition: utilstrencodings.cpp:63
EncodeBase32
std::string EncodeBase32(const unsigned char *pch, size_t len)
Definition: utilstrencodings.cpp:291
i64tostr
std::string i64tostr(int64_t n)
Definition: utilstrencodings.cpp:559
ParseInt32
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
Definition: utilstrencodings.cpp:482
utilstrencodings.h