本文整理汇总了C++中ConstBufferPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ConstBufferPtr类的具体用法?C++ ConstBufferPtr怎么用?C++ ConstBufferPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConstBufferPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EncryptNew
void VolumeHeader::EncryptNew (const BufferPtr &newHeaderBuffer, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf)
{
if (newHeaderBuffer.Size() != HeaderSize || newSalt.Size() != SaltSize)
throw ParameterIncorrect (SRC_POS);
shared_ptr <EncryptionMode> mode = EA->GetMode()->GetNew();
shared_ptr <EncryptionAlgorithm> ea = EA->GetNew();
if (typeid (*mode) == typeid (EncryptionModeXTS))
{
mode->SetKey (newHeaderKey.GetRange (EA->GetKeySize(), EA->GetKeySize()));
ea->SetKey (newHeaderKey.GetRange (0, ea->GetKeySize()));
}
else
{
mode->SetKey (newHeaderKey.GetRange (0, mode->GetKeySize()));
ea->SetKey (newHeaderKey.GetRange (LegacyEncryptionModeKeyAreaSize, ea->GetKeySize()));
}
ea->SetMode (mode);
newHeaderBuffer.CopyFrom (newSalt);
BufferPtr headerData = newHeaderBuffer.GetRange (EncryptedHeaderDataOffset, EncryptedHeaderDataSize);
Serialize (headerData);
ea->Encrypt (headerData);
if (newPkcs5Kdf)
Pkcs5 = newPkcs5Kdf;
}
示例2: DeserializeEntryAt
T VolumeHeader::DeserializeEntryAt (const ConstBufferPtr &header, const size_t &offset) const
{
if (offset > header.Size())
throw ParameterIncorrect (SRC_POS);
return Endian::Big (*reinterpret_cast<const T *> (header.Get() + offset));
}
示例3: Block
bool
Block::fromBuffer(const ConstBufferPtr& wire, size_t offset, Block& block)
{
Buffer::const_iterator tempBegin = wire->begin() + offset;
uint32_t type;
bool isOk = Tlv::readType(tempBegin, wire->end(), type);
if (!isOk)
return false;
uint64_t length;
isOk = Tlv::readVarNumber(tempBegin, wire->end(), length);
if (!isOk)
return false;
if (length > static_cast<uint64_t>(wire->end() - tempBegin))
{
return false;
}
block = Block(wire, type,
wire->begin() + offset, tempBegin + length,
tempBegin, tempBegin + length);
return true;
}
示例4: CopyFrom
void BufferPtr::CopyFrom (const ConstBufferPtr &bufferPtr) const
{
if (bufferPtr.Size() > DataSize)
throw ParameterTooLarge (SRC_POS);
Memory::Copy (DataPtr, bufferPtr.Get(), bufferPtr.Size());
}
示例5: update
Digest<Hash>&
Digest<Hash>::operator<<(Digest<Hash>& src)
{
ConstBufferPtr buffer = src.computeDigest();
update(buffer->get(), buffer->size());
return *this;
}
示例6: WriteAt
void File::WriteAt (const ConstBufferPtr &buffer, uint64 position) const
{
if_debug (ValidateState());
#ifdef TC_TRACE_FILE_OPERATIONS
TraceFileOperation (FileHandle, Path, true, buffer.Size(), position);
#endif
throw_sys_sub_if (pwrite (FileHandle, buffer, buffer.Size(), position) != (ssize_t) buffer.Size(), wstring (Path));
}
示例7: PasswordEmpty
bool VolumeHeader::Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes)
{
if (password.Size() < 1)
throw PasswordEmpty (SRC_POS);
ConstBufferPtr salt (encryptedData.GetRange (SaltOffset, SaltSize));
SecureBuffer header (EncryptedHeaderDataSize);
SecureBuffer headerKey (GetLargestSerializedKeySize());
foreach (shared_ptr <Pkcs5Kdf> pkcs5, keyDerivationFunctions)
{
pkcs5->DeriveKey (headerKey, password, salt);
foreach (shared_ptr <EncryptionMode> mode, encryptionModes)
{
if (typeid (*mode) != typeid (EncryptionModeXTS))
mode->SetKey (headerKey.GetRange (0, mode->GetKeySize()));
foreach (shared_ptr <EncryptionAlgorithm> ea, encryptionAlgorithms)
{
if (!ea->IsModeSupported (mode))
continue;
/*
printf("trying %ls, %ls, %ls\n", pkcs5->GetName().c_str(),
mode->GetName().c_str(),
ea->GetName().c_str()
);
*/
if (typeid (*mode) == typeid (EncryptionModeXTS))
{
ea->SetKey (headerKey.GetRange (0, ea->GetKeySize()));
mode = mode->GetNew();
mode->SetKey (headerKey.GetRange (ea->GetKeySize(), ea->GetKeySize()));
}
else
{
ea->SetKey (headerKey.GetRange (LegacyEncryptionModeKeyAreaSize, ea->GetKeySize()));
}
ea->SetMode (mode);
header.CopyFrom (encryptedData.GetRange (EncryptedHeaderDataOffset, EncryptedHeaderDataSize));
ea->Decrypt (header);
if (Deserialize (header, ea, mode))
{
EA = ea;
Pkcs5 = pkcs5;
return true;
}
}
}
}
示例8: StringSource
std::ostream&
operator<<(std::ostream& os, Digest<Hash>& digest)
{
using namespace CryptoPP;
std::string output;
ConstBufferPtr buffer = digest.computeDigest();
StringSource(buffer->buf(), buffer->size(), true, new HexEncoder(new FileSink(os)));
return os;
}
示例9: SetKey
void EncryptionAlgorithm::SetKey (const ConstBufferPtr &key)
{
if (Ciphers.size() < 1)
throw NotInitialized (SRC_POS);
if (GetKeySize() != key.Size())
throw ParameterIncorrect (SRC_POS);
size_t keyOffset = 0;
foreach_ref (Cipher &c, Ciphers)
{
c.SetKey (key.GetRange (keyOffset, c.GetKeySize()));
keyOffset += c.GetKeySize();
}
示例10: ParameterIncorrect
uint64 MemoryStream::Read (const BufferPtr &buffer)
{
if (Data.size() == 0)
throw ParameterIncorrect (SRC_POS);
ConstBufferPtr streamBuf (*this);
size_t len = buffer.Size();
if (streamBuf.Size() - ReadPosition < len)
len = streamBuf.Size() - ReadPosition;
BufferPtr(buffer).CopyFrom (streamBuf.GetRange (ReadPosition, len));
ReadPosition += len;
return len;
}
示例11:
std::ostream& operator << ( std::ostream& os, const ICommand& command )
{
ConstBufferPtr buffer = command.getBuffer();
if( buffer )
os << lunchbox::disableFlush << "command< type "
<< uint32_t( command.getType( )) << " cmd " << command.getCommand()
<< " size " << command.getSize() << '/' << buffer->getSize() << '/'
<< buffer->getMaxSize() << " from " << command.getNode() << " to "
<< command.getLocalNode() << " >" << lunchbox::enableFlush;
else
os << "command< empty >";
if( command._impl->func.isValid( ))
os << ' ' << command._impl->func << std::endl;
return os;
}
示例12: SetKey
void EncryptionModeLRW::SetKey (const ConstBufferPtr &key)
{
if (key.Size() != 16)
throw ParameterIncorrect (SRC_POS);
if (!KeySet)
GfContext.Allocate (sizeof (GfCtx));
if (!Gf64TabInit ((unsigned char *) key.Get(), (GfCtx *) (GfContext.Ptr())))
throw bad_alloc();
if (!Gf128Tab64Init ((unsigned char *) key.Get(), (GfCtx *) (GfContext.Ptr())))
throw bad_alloc();
Key.CopyFrom (key);
KeySet = true;
}
示例13: Block
Component
Component::fromImplicitSha256Digest(const ConstBufferPtr& digest)
{
if (digest->size() != crypto::SHA256_DIGEST_SIZE)
BOOST_THROW_EXCEPTION(Error("Cannot create ImplicitSha256DigestComponent (input digest must be " +
to_string(crypto::SHA256_DIGEST_SIZE) + " octets)"));
return Block(tlv::ImplicitSha256DigestComponent, digest);
}
示例14: Serialize
void Serializer::Serialize (const string &name, const ConstBufferPtr &data)
{
SerializeString (name);
uint64 size = data.Size();
Serialize (size);
DataStream->Write (data);
}
示例15: faceStatus
void
MulticastDiscovery::registerHubDiscoveryPrefix(const ConstBufferPtr& buffer)
{
std::vector<uint64_t> multicastFaces;
size_t offset = 0;
while (offset < buffer->size()) {
bool isOk = false;
Block block;
std::tie(isOk, block) = Block::fromBuffer(buffer, offset);
if (!isOk) {
std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
break;
}
offset += block.size();
nfd::FaceStatus faceStatus(block);
ndn::util::FaceUri uri(faceStatus.getRemoteUri());
if (uri.getScheme() == "udp4") {
namespace ip = boost::asio::ip;
boost::system::error_code ec;
ip::address address = ip::address::from_string(uri.getHost(), ec);
if (!ec && address.is_multicast()) {
multicastFaces.push_back(faceStatus.getFaceId());
}
else
continue;
}
}
if (multicastFaces.empty()) {
m_nextStageOnFailure("No multicast faces available, skipping multicast discovery stage");
}
else {
nfd::ControlParameters parameters;
parameters
.setName(LOCALHOP_HUB_DISCOVERY_PREFIX)
.setCost(1)
.setExpirationPeriod(time::seconds(30));
nRequestedRegs = multicastFaces.size();
nFinishedRegs = 0;
for (const auto& face : multicastFaces) {
parameters.setFaceId(face);
m_controller.start<nfd::RibRegisterCommand>(parameters,
bind(&MulticastDiscovery::onRegisterSuccess,
this),
bind(&MulticastDiscovery::onRegisterFailure,
this, _1, _2));
}
}
}