本文整理汇总了C++中Blob::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Blob::end方法的具体用法?C++ Blob::end怎么用?C++ Blob::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blob
的用法示例。
在下文中一共展示了Blob::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例3: convertNonCanonical
void convertNonCanonical(std::string const& hex, std::string const& canonHex)
{
Blob b (loadSignature(hex));
// The signature ought to at least be valid before we begin.
expect (isValid (hex), "invalid signature");
size_t len = b.size ();
expect (!makeCanonicalECDSASig (&b[0], len),
"non-canonical signature was already canonical");
expect (b.size () >= len,
"canonicalized signature length longer than non-canonical");
b.resize (len);
expect (isCanonicalECDSASig (&b[0], len, ECDSA::strict),
"canonicalized signature is not strictly canonical");
Blob canonicalForm (loadSignature (canonHex));
expect (b.size () == canonicalForm.size (),
"canonicalized signature doesn't have the expected length");
expect (std::equal (b.begin (), b.end (), canonicalForm.begin ()),
"canonicalized signature isn't what we expected");
}
示例4: CryptoException
Blob
PrivateKey::decrypt(const Blob& cipher) const
{
if (!key)
throw CryptoException("Can't decrypt data without private key !");
unsigned key_len = 0;
int err = gnutls_privkey_get_pk_algorithm(key, &key_len);
if (err < 0)
throw CryptoException("Can't read public key length !");
if (err != GNUTLS_PK_RSA)
throw CryptoException("Must be an RSA key");
unsigned cypher_block_sz = key_len / 8;
if (cipher.size() % cypher_block_sz)
throw CryptoException("Unexpected cipher length");
Blob ret;
for (auto cb = cipher.cbegin(), ce = cipher.cend(); cb < ce; cb += cypher_block_sz) {
const gnutls_datum_t dat {(uint8_t*)(&(*cb)), cypher_block_sz};
gnutls_datum_t out;
int err = gnutls_privkey_decrypt_data(key, 0, &dat, &out);
if (err != GNUTLS_E_SUCCESS)
throw DhtException(std::string("Can't decrypt data: ") + gnutls_strerror(err));
ret.insert(ret.end(), out.data, out.data+out.size);
gnutls_free(out.data);
}
return ret;
}
示例5: gotNode
void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNode& id, uint256 const& nodeHash,
Blob& nodeData, SHAMapTreeNode::TNType type)
{
if (fromFilter)
return;
m_nodeCache.insert (nodeHash, nodeData);
if ((type == SHAMapTreeNode::tnTRANSACTION_NM) && (nodeData.size () > 16))
{
// this is a transaction, and we didn't have it
WriteLog (lsDEBUG, TransactionAcquire) << "Node on our acquiring TX set is TXN we may not have";
try
{
Serializer s (nodeData.begin () + 4, nodeData.end ()); // skip prefix
SerializerIterator sit (s);
SerializedTransaction::pointer stx = boost::make_shared<SerializedTransaction> (boost::ref (sit));
assert (stx->getTransactionID () == nodeHash);
getApp().getJobQueue ().addJob (jtTRANSACTION, "TXS->TXN",
BIND_TYPE (&NetworkOPs::submitTransaction, &getApp().getOPs (), P_1, stx));
}
catch (...)
{
WriteLog (lsWARNING, TransactionAcquire) << "Fetched invalid transaction in proposed set";
}
}
}
示例6: vch
std::string CBase58Data::ToString () const
{
Blob vch (1, nVersion);
vch.insert (vch.end (), vchData.begin (), vchData.end ());
return Base58::encodeWithCheck (vch);
}
示例7: human
std::string RippleAddress::human(Blob& blob, VersionEncoding type)
{
Blob vch(1, type);
vch.insert(vch.end(), blob.begin(), blob.end());
return Base58::encodeWithCheck(vch);
}
示例8:
std::string
toString (AnyPublicKey const& pk)
{
Blob buffer;
buffer.reserve (1 + pk.size ());
buffer.push_back (VER_NODE_PUBLIC);
auto const data = pk.data ();
buffer.insert (buffer.end (), data, data + pk.size ());
return Base58::encodeWithCheck (buffer);
}
示例9: strCopy
std::string strCopy (Blob const& vucSrc)
{
std::string strDst;
strDst.resize (vucSrc.size ());
std::copy (vucSrc.begin (), vucSrc.end (), strDst.begin ());
return strDst;
}
示例10:
bool Base58::decodeWithCheck (const char* psz, Blob& vchRet, Alphabet const& alphabet)
{
if (!decode (psz, vchRet, alphabet))
return false;
if (vchRet.size () < 4)
{
vchRet.clear ();
return false;
}
uint256 hash = SHA256Hash (vchRet.begin (), vchRet.end () - 4);
if (memcmp (&hash, &vchRet.end ()[-4], 4) != 0)
{
vchRet.clear ();
return false;
}
vchRet.resize (vchRet.size () - 4);
return true;
}
示例11: ConvertToBase58
String ConvertToBase58(const ConstBuf& cbuf) {
HashValue hash = HasherEng::GetCurrent()->HashForAddress(cbuf);
Blob v = cbuf + Blob(hash.data(), 4);
vector<char> r;
vector<byte> tmp(v.Size+1, 0);
std::reverse_copy(v.begin(), v.end(), tmp.begin());
for (BigInteger n(&tmp[0], tmp.size()); Sign(n);) {
pair<BigInteger, BigInteger> pp = div(n, 58);
n = pp.first;
r.insert(r.begin(), s_pszBase58[explicit_cast<int>(pp.second)]);
}
for (int i=0; i<v.Size && !v.constData()[i]; ++i)
r.insert(r.begin(), s_pszBase58[0]);
return String(&r[0], r.size());
}
示例12: ConvertToBase58ShaSquare
String ConvertToBase58ShaSquare(const ConstBuf& cbuf) {
SHA256 sha;
HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(cbuf)));
Blob v = cbuf + Blob(hash.data(), 4);
vector<char> r;
vector<byte> tmp(v.Size+1, 0);
std::reverse_copy(v.begin(), v.end(), tmp.begin());
for (BigInteger n(&tmp[0], tmp.size()); Sign(n);) {
pair<BigInteger, BigInteger> pp = div(n, 58);
n = pp.first;
r.insert(r.begin(), s_pszBase58[explicit_cast<int>(pp.second)]);
}
for (int i=0; i<v.Size && !v.constData()[i]; ++i)
r.insert(r.begin(), s_pszBase58[0]);
return String(&r[0], r.size());
}
示例13: while
void
Certificate::pack(Blob& b) const
{
const Certificate* crt = this;
while (crt) {
std::string str;
size_t buf_sz = 8192;
str.resize(buf_sz);
if (int err = gnutls_x509_crt_export(crt->cert, GNUTLS_X509_FMT_DER, &(*str.begin()), &buf_sz)) {
std::cerr << "Could not export certificate - " << gnutls_strerror(err) << std::endl;
return;
}
str.resize(buf_sz);
b.insert(b.end(), str.begin(), str.end());
crt = crt->issuer.get();
return;
}
}
示例14: addBlob
void ClusterImpl::addBlob(const Blob& blob)
{
log_debug1("addBlob(ptr, " << blob.size() << ')');
data.insert(data.end(), blob.data(), blob.end());
offsets.push_back(data.size());
}
示例15: load
friend bool load(Blob const& blob, SpecificMessage& msg) {
msg.contents.assign(blob.begin(), blob.end());
return true;
}