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


C++ bytes::size方法代码示例

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


在下文中一共展示了bytes::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: l

void Secp256k1PP::encrypt(Public const& _k, bytes& io_cipher)
{
	auto& ctx = Secp256k1PPCtx::get();

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
	CryptoPP::ECIES<CryptoPP::ECP>::Encryptor e;
#pragma GCC diagnostic pop
#pragma clang diagnostic pop

	{
		Guard l(ctx.x_params);
		e.AccessKey().Initialize(ctx.m_params, publicToPoint(_k));
	}


	size_t plen = io_cipher.size();
	bytes ciphertext;
	ciphertext.resize(e.CiphertextLength(plen));
	
	{
		Guard l(ctx.x_rng);
		e.Encrypt(ctx.m_rng, io_cipher.data(), plen, ciphertext.data());
	}
	
	memset(io_cipher.data(), 0, io_cipher.size());
	io_cipher = std::move(ciphertext);
}
开发者ID:Kingefosa,项目名称:cpp-microdatachain,代码行数:30,代码来源:CryptoPP.cpp

示例2:

	DatagramEncryptor::DatagramEncryptor(const bytes &encryptionKey, const bytes &IV, const bytes &macKey) :
		aesCtr(&IV[0], IV.size(), &encryptionKey[0], encryptionKey.size()),
		hmac(sha1, macKey)
	{
		if (macKey.size() < sha1.outputLen()) throw DsrpException("DatagramEncryptor::DatagramEncryptor: macKey not long enough");
		
	}
开发者ID:SmartActiveNode2,项目名称:san2,代码行数:7,代码来源:datagramencryptor.cpp

示例3: pushLocation

static void pushLocation(bytes& o_code, uint32_t _locationValue)
{
	o_code.push_back((byte)Instruction::PUSH4);
	o_code.resize(o_code.size() + 4);
	bytesRef r(&o_code[o_code.size() - 4], 4);
	toBigEndian(_locationValue, r);
}
开发者ID:AcriCAA,项目名称:cpp-ethereum,代码行数:7,代码来源:Instruction.cpp

示例4: memDump

string dev::memDump(bytes const& _bytes, unsigned _width, bool _html)
{
	stringstream ret;
	if (_html)
		ret << "<pre style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">";
	for (unsigned i = 0; i < _bytes.size(); i += _width)
	{
		ret << hex << setw(4) << setfill('0') << i << " ";
		for (unsigned j = i; j < i + _width; ++j)
			if (j < _bytes.size())
				if (_bytes[j] >= 32 && _bytes[j] < 127)
					if ((char)_bytes[j] == '<' && _html)
						ret << "&lt;";
					else if ((char)_bytes[j] == '&' && _html)
						ret << "&amp;";
					else
						ret << (char)_bytes[j];
				else
					ret << '?';
			else
				ret << ' ';
		ret << " ";
		for (unsigned j = i; j < i + _width && j < _bytes.size(); ++j)
			ret << setfill('0') << setw(2) << hex << (unsigned)_bytes[j] << " ";
		ret << "\n";
	}
	if (_html)
		ret << "</pre>";
	return ret.str();
}
开发者ID:285452612,项目名称:bcos,代码行数:30,代码来源:CommonIO.cpp

示例5: l

void Secp256k1PP::decrypt(Secret const& _k, bytes& io_text)
{
	CryptoPP::ECIES<CryptoPP::ECP>::Decryptor d;
	initializeDLScheme(_k, d);

	if (!io_text.size())
	{
		io_text.resize(1);
		io_text[0] = 0;
	}
	
	size_t clen = io_text.size();
	bytes plain;
	plain.resize(d.MaxPlaintextLength(io_text.size()));
	
	DecodingResult r;
	{
		Guard l(x_rng);
		r = d.Decrypt(m_rng, io_text.data(), clen, plain.data());
	}
	
	if (!r.isValidCoding)
	{
		io_text.clear();
		return;
	}
	
	io_text.resize(r.messageLength);
	io_text = std::move(plain);
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:30,代码来源:CryptoPP.cpp

示例6: parse

void Packet::parse(bytes data) {
    memcpy(&head[0], &data[0], HEADER_LEN);
    body.resize(data.size() - HEADER_LEN);
    memcpy(&body[0], &data[HEADER_LEN], data.size() - HEADER_LEN);
    int i = 0;
    short checkLen = 0x0;
    pull(head, i, version);
    pull(head, i, opCode);
    pull(head, i, switchMac);
    pull(head, i, hostMac);
    pull(head, i, sequenceId);
    pull(head, i, errorCode);
    pull(head, i, checkLen);
    pull(head, i, fragmentOffset);
    pull(head, i, flag);
    pull(head, i, tokenId);
    pull(head, i, checkSum);
    if (this->getLength() != checkLen) {
        printf("Packet Length doesn't match: %lu != %hd\n", data.size(),
                checkLen);
    }
    i = 0;
    dataset d;
    payload = {};
    while (i < (int) body.size() - 4) {
        pull(body, i, d.type);
        pull(body, i, d.len);
        pull(body, i, d.value, d.len);
        payload.push_back(d);
    }
}
开发者ID:jed1,项目名称:smrtlink,代码行数:31,代码来源:Packet.cpp

示例7: make_tuple

std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCode(const bytes& _code, QObject* _objUsedAsParent)
{
	QList<QObject*> codeStr;
	QMap<int, int> codeMapping;
	for (unsigned i = 0; i <= _code.size(); ++i)
	{
		byte b = i < _code.size() ? _code[i] : 0;
		try
		{
			QString s = QString::fromStdString(instructionInfo((Instruction)b).name);
			std::ostringstream out;
			out << std::hex << std::setw(4) << std::setfill('0') << i;
			codeMapping[i] = codeStr.size();
			int line = i;
			if (b >= (byte)Instruction::PUSH1 && b <= (byte)Instruction::PUSH32)
			{
				unsigned bc = getPushNumber((Instruction)b);
				s = "PUSH 0x" + QString::fromStdString(toHex(bytesConstRef(&_code[i + 1], bc)));
				i += bc;
			}
			HumanReadableCode* humanCode = new HumanReadableCode(QString::fromStdString(out.str()) + "  "  + s, line, _objUsedAsParent);
			codeStr.append(humanCode);
		}
		catch (...)
		{
			qDebug() << QString("Unhandled exception!") << endl <<
					 QString::fromStdString(boost::current_exception_diagnostic_information());
			break;	// probably hit data segment
		}
	}
	return std::make_tuple(codeStr, new QQMLMap(codeMapping, _objUsedAsParent));
}
开发者ID:caktux,项目名称:cpp-ethereum,代码行数:32,代码来源:DebuggingStateWrapper.cpp

示例8: pushLiteral

static unsigned pushLiteral(bytes& o_code, u256 _literalValue)
{
	unsigned br = max<unsigned>(1, bytesRequired(_literalValue));
	o_code.push_back((byte)Instruction::PUSH1 + br - 1);
	o_code.resize(o_code.size() + br);
	for (unsigned i = 0; i < br; ++i)
	{
		o_code[o_code.size() - 1 - i] = (byte)(_literalValue & 0xff);
		_literalValue >>= 8;
	}
	return br + 1;
}
开发者ID:AcriCAA,项目名称:cpp-ethereum,代码行数:12,代码来源:Instruction.cpp

示例9: appendCode

static void appendCode(bytes& o_code, vector<unsigned>& o_locs, bytes _code, vector<unsigned>& _locs)
{
	o_locs.reserve(o_locs.size() + _locs.size());
	for (auto i: _locs)
	{
		increaseLocation(_code, i, (unsigned)o_code.size());
		o_locs.push_back(i + (unsigned)o_code.size());
	}
	o_code.reserve(o_code.size() + _code.size());
	for (auto i: _code)
		o_code.push_back(i);
}
开发者ID:AcriCAA,项目名称:cpp-ethereum,代码行数:12,代码来源:Instruction.cpp

示例10: unpadLeft

    bytes unpadLeft(bytes _b)
    {
        unsigned int i = 0;
        if (_b.size() == 0)
            return _b;

        while (i < _b.size() && _b[i] == byte(0))
            i++;

        if (i != 0)
            _b.erase(_b.begin(), _b.begin() + i);
        return _b;
    }
开发者ID:superbitcoin,项目名称:SuperBitcoin,代码行数:13,代码来源:CommonJS.cpp

示例11: mKey

bool Secp256k1PP::decryptECIES(Secret const& _k, bytesConstRef _sharedMacData, bytes& io_text)
{

	// interop w/go ecies implementation
	
	// io_cipher[0] must be 2, 3, or 4, else invalidpublickey
	if (io_text.empty() || io_text[0] < 2 || io_text[0] > 4)
		// invalid message: publickey
		return false;
	
	if (io_text.size() < (1 + Public::size + h128::size + 1 + h256::size))
		// invalid message: length
		return false;

	Secret z;
	if (!ecdh::agree(_k, *(Public*)(io_text.data() + 1), z))
		return false;  // Invalid pubkey or seckey.
	auto key = ecies::kdf(z, bytes(), 64);
	bytesConstRef eKey = bytesConstRef(&key).cropped(0, 16);
	bytesRef mKeyMaterial = bytesRef(&key).cropped(16, 16);
	bytes mKey(32);
	CryptoPP::SHA256 ctx;
	ctx.Update(mKeyMaterial.data(), mKeyMaterial.size());
	ctx.Final(mKey.data());
	
	bytes plain;
	size_t cipherLen = io_text.size() - 1 - Public::size - h128::size - h256::size;
	bytesConstRef cipherWithIV(io_text.data() + 1 + Public::size, h128::size + cipherLen);
	bytesConstRef cipherIV = cipherWithIV.cropped(0, h128::size);
	bytesConstRef cipherNoIV = cipherWithIV.cropped(h128::size, cipherLen);
	bytesConstRef msgMac(cipherNoIV.data() + cipherLen, h256::size);
	h128 iv(cipherIV.toBytes());
	
	// verify tag
	CryptoPP::HMAC<CryptoPP::SHA256> hmacctx(mKey.data(), mKey.size());
	hmacctx.Update(cipherWithIV.data(), cipherWithIV.size());
	hmacctx.Update(_sharedMacData.data(), _sharedMacData.size());
	h256 mac;
	hmacctx.Final(mac.data());
	for (unsigned i = 0; i < h256::size; i++)
		if (mac[i] != msgMac[i])
			return false;
	
	plain = decryptSymNoAuth(SecureFixedHash<16>(eKey), iv, cipherNoIV).makeInsecure();
	io_text.resize(plain.size());
	io_text.swap(plain);
	
	return true;
}
开发者ID:Kingefosa,项目名称:cpp-microdatachain,代码行数:49,代码来源:CryptoPP.cpp

示例12: unpack_context_free_data

static vector<bytes> zlib_decompress_context_free_data(const bytes& data) {
   if( data.size() == 0 )
      return vector<bytes>();

   bytes out = zlib_decompress(data);
   return unpack_context_free_data(out);
}
开发者ID:BestSilent,项目名称:eos,代码行数:7,代码来源:transaction.cpp

示例13: getSessionKey

	bytes SrpClientAuthenticator::getSessionKey(bytes M2_from_server)
	{
		if (M2_from_server.size() == 0) throw DsrpException("SrpClientAuthenticator::getSessionKey: M2_from_server.size() == 0");
		if (M2_calculated.size() == 0) throw DsrpException("SrpClientAuthenticator::getSessionKey: M2_calculated.size() == 0");
		if (M2_from_server != M2_calculated) throw DsrpException("Authentification failed, bad password");
		return K;
	}
开发者ID:SmartActiveNode2,项目名称:san2,代码行数:7,代码来源:srpclientauthenticator.cpp

示例14: kdf

bytes ecies::kdf(Secret const& _z, bytes const& _s1, unsigned kdByteLen)
{
    auto reps = ((kdByteLen + 7) * 8) / 512;
    // SEC/ISO/Shoup specify counter size SHOULD be equivalent
    // to size of hash output, however, it also notes that
    // the 4 bytes is okay. NIST specifies 4 bytes.
    std::array<byte, 4> ctr{{0, 0, 0, 1}};
    bytes k;
    secp256k1_sha256_t ctx;
    for (unsigned i = 0; i <= reps; i++)
    {
        secp256k1_sha256_initialize(&ctx);
        secp256k1_sha256_write(&ctx, ctr.data(), ctr.size());
        secp256k1_sha256_write(&ctx, _z.data(), Secret::size);
        secp256k1_sha256_write(&ctx, _s1.data(), _s1.size());
        // append hash to k
        std::array<byte, 32> digest;
        secp256k1_sha256_finalize(&ctx, digest.data());

        k.reserve(k.size() + h256::size);
        move(digest.begin(), digest.end(), back_inserter(k));

        if (++ctr[3] || ++ctr[2] || ++ctr[1] || ++ctr[0])
            continue;
    }

    k.resize(kdByteLen);
    return k;
}
开发者ID:ethereum,项目名称:cpp-ethereum,代码行数:29,代码来源:Common.cpp

示例15: beginsWith

bool beginsWith(Address _a, bytes const& _b)
{
	for (unsigned i = 0; i < min<unsigned>(20, _b.size()); ++i)
		if (_a[i] != _b[i])
			return false;
	return true;
}
开发者ID:EarthDollar,项目名称:farmer,代码行数:7,代码来源:NewAccount.cpp


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