当前位置: 首页>>代码示例>>C++>>正文


C++ CBigNum::setuint方法代码示例

本文整理汇总了C++中CBigNum::setuint方法的典型用法代码示例。如果您正苦于以下问题:C++ CBigNum::setuint方法的具体用法?C++ CBigNum::setuint怎么用?C++ CBigNum::setuint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CBigNum的用法示例。


在下文中一共展示了CBigNum::setuint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:alexandrev,项目名称:rippled,代码行数:59,代码来源:Base58.cpp

示例2: bignum_error

bool Base58::decode (const char* psz, Blob& vchRet, Alphabet const& alphabet)
{
    CAutoBN_CTX pctx;
    vchRet.clear ();
    CBigNum bn58 = 58;
    CBigNum bn = 0;
    CBigNum bnChar;

    while (isspace (*psz))
        psz++;

    // Convert big endian string to bignum
    for (const char* p = psz; *p; p++)
    {
        // VFALCO TODO Make this use the inverse table!
        //             Or better yet ditch this and call raw_decode
        //
        const char* p1 = strchr (alphabet.chars(), *p);

        if (p1 == nullptr)
        {
            while (isspace (*p))
                p++;

            if (*p != '\0')
                return false;

            break;
        }

        bnChar.setuint (p1 - alphabet.chars());

        if (!BN_mul (&bn, &bn, &bn58, pctx))
            throw bignum_error ("DecodeBase58 : BN_mul failed");

        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);

    // Restore leading zeros
    int nLeadingZeros = 0;

    for (const char* p = psz; *p == alphabet.chars()[0]; p++)
        nLeadingZeros++;

    vchRet.assign (nLeadingZeros + vchTmp.size (), 0);

    // Convert little endian data to big endian
    std::reverse_copy (vchTmp.begin (), vchTmp.end (), vchRet.end () - vchTmp.size ());
    return true;
}
开发者ID:CCJY,项目名称:rippled,代码行数:57,代码来源:Base58.cpp


注:本文中的CBigNum::setuint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。