本文整理汇总了C++中Alphabet::from_char方法的典型用法代码示例。如果您正苦于以下问题:C++ Alphabet::from_char方法的具体用法?C++ Alphabet::from_char怎么用?C++ Alphabet::from_char使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alphabet
的用法示例。
在下文中一共展示了Alphabet::from_char方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i
bool Base58::raw_decode (char const* first, char const* last, void* dest,
std::size_t size, bool checked, Alphabet const& alphabet)
{
CAutoBN_CTX pctx;
CBigNum bn58 = 58;
CBigNum bn = 0;
CBigNum bnChar;
// Convert big endian string to bignum
for (char const* p = first; p != last; ++p)
{
int i (alphabet.from_char (*p));
if (i == -1)
return false;
bnChar.setuint ((unsigned int) i);
int const success (BN_mul (&bn, &bn, &bn58, pctx));
assert (success);
(void) success;
bn += bnChar;
}
// Get bignum as little endian data
Blob vchTmp = bn.getvch ();
// Trim off sign byte if present
if (vchTmp.size () >= 2 && vchTmp.end ()[-1] == 0 && vchTmp.end ()[-2] >= 0x80)
vchTmp.erase (vchTmp.end () - 1);
char* const out (static_cast <char*> (dest));
// Count leading zeros
int nLeadingZeros = 0;
for (char const* p = first; p!=last && *p==alphabet[0]; p++)
nLeadingZeros++;
// Verify that the size is correct
if (vchTmp.size() + nLeadingZeros != size)
return false;
// Fill the leading zeros
memset (out, 0, nLeadingZeros);
// Copy little endian data to big endian
std::reverse_copy (vchTmp.begin (), vchTmp.end (),
out + nLeadingZeros);
if (checked)
{
char hash4 [4];
fourbyte_hash256 (hash4, out, size - 4);
if (memcmp (hash4, out + size - 4, 4) != 0)
return false;
}
return true;
}