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


C++ bytesConstRef类代码示例

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


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

示例1: writeFile

void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename)
{
	namespace fs = boost::filesystem;
	if (_writeDeleteRename)
	{
		fs::path tempPath = fs::unique_path(_file + "-%%%%%%");
		writeFile(tempPath.string(), _data, false);
		// will delete _file if it exists
		fs::rename(tempPath, _file);
	}
	else
	{
		// create directory if not existent
		fs::path p(_file);
		if (!fs::exists(p.parent_path()))
		{
			fs::create_directories(p.parent_path());
			DEV_IGNORE_EXCEPTIONS(fs::permissions(p.parent_path(), fs::owner_all));
		}

		ofstream s(_file, ios::trunc | ios::binary);
		s.write(reinterpret_cast<char const*>(_data.data()), _data.size());
		if (!s)
			BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _file));
		DEV_IGNORE_EXCEPTIONS(fs::permissions(_file, fs::owner_read|fs::owner_write));
	}
}
开发者ID:285452612,项目名称:bcos,代码行数:27,代码来源:CommonIO.cpp

示例2: hexPrefixEncode

std::string hexPrefixEncode(bytesConstRef _d1, unsigned _o1, bytesConstRef _d2, unsigned _o2, bool _leaf)
{
	unsigned begin1 = _o1;
	unsigned end1 = _d1.size() * 2;
	unsigned begin2 = _o2;
	unsigned end2 = _d2.size() * 2;

	bool odd = (end1 - begin1 + end2 - begin2) & 1;

	std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16);
	ret.reserve((end1 - begin1 + end2 - begin2) / 2 + 1);

	unsigned d = odd ? 1 : 2;
	for (auto i = begin1; i < end1; ++i, ++d)
	{
		byte n = nibble(_d1, i);
		if (d & 1)	// odd
			ret.back() |= n;		// or the nibble onto the back
		else
			ret.push_back(n << 4);	// push the nibble on to the back << 4
	}
	for (auto i = begin2; i < end2; ++i, ++d)
	{
		byte n = nibble(_d2, i);
		if (d & 1)	// odd
			ret.back() |= n;		// or the nibble onto the back
		else
			ret.push_back(n << 4);	// push the nibble on to the back << 4
	}
	return ret;
}
开发者ID:Kingefosa,项目名称:cpp-microdatachain,代码行数:31,代码来源:TrieCommon.cpp

示例3:

void eth::sha3(bytesConstRef _input, bytesRef _output)
{
	CryptoPP::SHA3_256 ctx;
	ctx.Update((byte*)_input.data(), _input.size());
	assert(_output.size() >= 32);
	ctx.Final(_output.data());
}
开发者ID:AlphaPerfect,项目名称:cpp-ethereum,代码行数:7,代码来源:Common.cpp

示例4: aesDecrypt

bytes dev::aesDecrypt(bytesConstRef _ivCipher, std::string const& _password, unsigned _rounds, bytesConstRef _salt)
{
	bytes pw = asBytes(_password);

	if (!_salt.size())
		_salt = &pw;

	bytes target(64);
	CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256>().DeriveKey(target.data(), target.size(), 0, pw.data(), pw.size(), _salt.data(), _salt.size(), _rounds);

	try
	{
		CryptoPP::AES::Decryption aesDecryption(target.data(), 16);
		auto cipher = _ivCipher.cropped(16);
		auto iv = _ivCipher.cropped(0, 16);
		CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, iv.data());
		std::string decrypted;
		CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decrypted));
		stfDecryptor.Put(cipher.data(), cipher.size());
		stfDecryptor.MessageEnd();
		return asBytes(decrypted);
	}
	catch (exception const& e)
	{
		cerr << e.what() << endl;
		return bytes();
	}
}
开发者ID:AndresAH,项目名称:cpp-ethereum,代码行数:28,代码来源:AES.cpp

示例5: eciesKDF

void Secp256k1PP::encryptECIES(Public const& _k, bytesConstRef _sharedMacData, bytes& io_cipher)
{
	// interop w/go ecies implementation
	auto r = KeyPair::create();
	Secret z;
	ecdh::agree(r.sec(), _k, z);
	auto key = eciesKDF(z, bytes(), 32);
	bytesConstRef eKey = bytesConstRef(&key).cropped(0, 16);
	bytesRef mKeyMaterial = bytesRef(&key).cropped(16, 16);
	CryptoPP::SHA256 ctx;
	ctx.Update(mKeyMaterial.data(), mKeyMaterial.size());
	bytes mKey(32);
	ctx.Final(mKey.data());
	
	bytes cipherText = encryptSymNoAuth(SecureFixedHash<16>(eKey), h128(), bytesConstRef(&io_cipher));
	if (cipherText.empty())
		return;

	bytes msg(1 + Public::size + h128::size + cipherText.size() + 32);
	msg[0] = 0x04;
	r.pub().ref().copyTo(bytesRef(&msg).cropped(1, Public::size));
	bytesRef msgCipherRef = bytesRef(&msg).cropped(1 + Public::size + h128::size, cipherText.size());
	bytesConstRef(&cipherText).copyTo(msgCipherRef);
	
	// tag message
	CryptoPP::HMAC<SHA256> hmacctx(mKey.data(), mKey.size());
	bytesConstRef cipherWithIV = bytesRef(&msg).cropped(1 + Public::size, h128::size + cipherText.size());
	hmacctx.Update(cipherWithIV.data(), cipherWithIV.size());
	hmacctx.Update(_sharedMacData.data(), _sharedMacData.size());
	hmacctx.Final(msg.data() + 1 + Public::size + cipherWithIV.size());
	
	io_cipher.resize(msg.size());
	io_cipher.swap(msg);
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:34,代码来源:CryptoPP.cpp

示例6: checkPacket

bool Session::checkPacket(bytesConstRef _msg)
{
    if (_msg[0] > 0x7f || _msg.size() < 2)
        return false;
    if (RLP(_msg.cropped(1)).actualSize() + 1 != _msg.size())
        return false;
    return true;
}
开发者ID:beautifularea,项目名称:aleth,代码行数:8,代码来源:Session.cpp

示例7: exec

static void exec(string const& _args, bytesConstRef _in)
{
	try
	{
		exec_stream_t es("ipfs", _args);
		es.in() << string(_in.begin(), _in.end());
	}
	catch (exception const &e)
	{
		throw IPFSCommunicationError(e.what());
	}
}
开发者ID:elementrem,项目名称:webthree-umbrella,代码行数:12,代码来源:IPFS.cpp

示例8: bytes

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

示例9: import

bool TransactionQueue::import(bytesConstRef _block)
{
	// Check if we already know this transaction.
	h256 h = sha3(_block);
	if (m_data.count(h))
		return false;

	try
	{
		// Check validity of _block as a transaction. To do this we just deserialise and attempt to determine the sender. If it doesn't work, the signature is bad.
		// The transaction's nonce may yet be invalid (or, it could be "valid" but we may be missing a marginally older transaction).
		Transaction t(_block);
		auto s = t.sender();
		if (m_interest.count(s))
			m_interestQueue.push_back(t);

		// If valid, append to blocks.
		m_data[h] = _block.toBytes();
	}
	catch (InvalidTransactionFormat const& _e)
	{
		cwarn << "Ignoring invalid transaction: " << _e.description();
		return false;
	}
	catch (std::exception const& _e)
	{
		cwarn << "Ignoring invalid transaction: " << _e.what();
		return false;
	}

	return true;
}
开发者ID:AronVanAmmers,项目名称:cpp-ethereum,代码行数:32,代码来源:TransactionQueue.cpp

示例10: insertAux

void MemoryDB::insertAux(h256 const& _h, bytesConstRef _v)
{
#if DEV_GUARDED_DB
	WriteGuard l(x_this);
#endif
	m_aux[_h] = make_pair(_v.toBytes(), true);
}
开发者ID:fjl,项目名称:libweb3core,代码行数:7,代码来源:MemoryDB.cpp

示例11:

AddressState::AddressState(u256 _balance, u256 _nonce, bytesConstRef _code):
	m_type(AddressType::Contract),
	m_balance(_balance),
	m_nonce(_nonce),
	m_isComplete(true),
	m_code(_code.toBytes())
{}
开发者ID:AcriCAA,项目名称:cpp-ethereum,代码行数:7,代码来源:AddressState.cpp

示例12: create

h160 FakeExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _init, OnOpFunc const&)
{
	Address na = right160(sha3(rlpList(myAddress, get<1>(addresses[myAddress]))));

	Transaction t(_endowment, gasPrice, io_gas, _init.toBytes());
	callcreates.push_back(t);
	return na;
}
开发者ID:caktux,项目名称:cpp-ethereum,代码行数:8,代码来源:vm.cpp

示例13: insert

void MemoryDB::insert(h256 const& _h, bytesConstRef _v)
{
#if DEV_GUARDED_DB
	WriteGuard l(x_this);
#endif
	auto it = m_main.find(_h);
	if (it != m_main.end())
	{
		it->second.first = _v.toString();
		it->second.second++;
	}
	else
		m_main[_h] = make_pair(_v.toString(), 1);
#if ETH_PARANOIA
	dbdebug << "INST" << _h << "=>" << m_main[_h].second;
#endif
}
开发者ID:fjl,项目名称:libweb3core,代码行数:17,代码来源:MemoryDB.cpp

示例14: decryptECIES

bool dev::decryptECIES(Secret const& _k, bytesConstRef _sharedMacData, bytesConstRef _cipher, bytes& o_plaintext)
{
    bytes io = _cipher.toBytes();
    if (!Secp256k1PP::get()->decryptECIES(_k, _sharedMacData, io))
        return false;
    o_plaintext = std::move(io);
    return true;
}
开发者ID:ethereum,项目名称:cpp-ethereum,代码行数:8,代码来源:Common.cpp

示例15: decryptECIES

bool dev::decryptECIES(Secret const& _k, bytesConstRef _cipher, bytes& o_plaintext)
{
	bytes io = _cipher.toBytes();
	if (!s_secp256k1pp.decryptECIES(_k, io))
		return false;
	o_plaintext = std::move(io);
	return true;
}
开发者ID:AndresAH,项目名称:cpp-ethereum,代码行数:8,代码来源:Common.cpp


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