本文整理汇总了C++中OTData类的典型用法代码示例。如果您正苦于以下问题:C++ OTData类的具体用法?C++ OTData怎么用?C++ OTData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OTData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
serializedAsymmetricKey TrezorCrypto::HDNodeToSerialized(
const HDNode& node,
const DerivationMode privateVersion) const
{
serializedAsymmetricKey key = std::make_shared<proto::AsymmetricKey>();
key->set_version(1);
key->set_type(proto::AKEYTYPE_SECP256K1);
if (privateVersion) {
key->set_mode(proto::KEYMODE_PRIVATE);
key->set_chaincode(node.chain_code, sizeof(node.chain_code));
OTPassword plaintextKey;
plaintextKey.setMemory(node.private_key, sizeof(node.private_key));
OTData encryptedKey;
BinarySecret masterPassword(
App::Me().Crypto().AES().InstantiateBinarySecretSP());
masterPassword = CryptoSymmetric::GetMasterKey("");
bool encrypted = Libsecp256k1::EncryptPrivateKey(
plaintextKey,
*masterPassword,
encryptedKey);
if (encrypted) {
key->set_key(encryptedKey.GetPointer(), encryptedKey.GetSize());
}
} else {
key->set_mode(proto::KEYMODE_PUBLIC);
key->set_key(node.public_key, sizeof(node.public_key));
}
return key;
}
示例2: GetData
// This function will base64 DECODE the string contents
// and return them as binary in theData
bool OTASCIIArmor::GetData(OTData & theData, bool bLineBreaks) const //linebreaks=true
{
return GetAndUnpackData(theData, bLineBreaks);
size_t outSize = 0;
uint8_t * pData = NULL;
theData.Release();
if (GetLength() < 1)
return true;
pData = OT_base64_decode(Get(), &outSize, (bLineBreaks ? 1 : 0));
if (pData)
{
theData.Assign(pData, outSize);
delete [] pData; pData=NULL;
return true;
}
else
{
OTLog::Error("Error while base64_decoding in OTASCIIArmor::GetData.\n");
return false;
}
}
示例3: Pubkey
const std::string PaymentCode::asBase58() const
{
OTData pubkey = Pubkey();
uint8_t serialized[81]{};
serialized[0] = PaymentCode::BIP47_VERSION_BYTE;
serialized[1] = version_;
serialized[2] = hasBitmessage_ ? 0x80 : 0;
OTPassword::safe_memcpy(
&serialized[3],
33,
pubkey.GetPointer(),
pubkey.GetSize(),
false);
OTPassword::safe_memcpy(
&serialized[36],
32,
chain_code_.GetPointer(),
chain_code_.GetSize(),
false);
serialized[68] = bitmessage_version_;
serialized[69] = bitmessage_stream_;
OTData binaryVersion(serialized, sizeof(serialized));
return App::Me().Crypto().Util().Base58CheckEncode(binaryVersion).Get();
}
示例4: SetData
// This function will base64 ENCODE theData,
// and then Set() that as the string contents.
bool OTASCIIArmor::SetData(const OTData & theData, bool bLineBreaks/*=true*/)
{
return SetAndPackData(theData, bLineBreaks);
char * pString = NULL;
Release();
if (theData.GetSize() < 1)
return true;
pString = OT_base64_encode((const uint8_t*)theData.GetPointer(), theData.GetSize(), (bLineBreaks ? 1 : 0));
if (pString)
{
Set(pString);
delete [] pString; pString=NULL;
return true;
}
else
{
OTLog::Error("Error while base64_encoding in OTASCIIArmor::GetData.\n");
return false;
}
}
示例5: GetData
// Base64-decode
bool OTASCIIArmor::GetData(OTData& theData,
bool bLineBreaks) const // linebreaks=true
{
theData.Release();
if (GetLength() < 1) return true;
size_t outSize = 0;
uint8_t* pData = App::Me().Crypto().Util().Base64Decode(Get(), &outSize, bLineBreaks);
// Some versions of OpenSSL will handle input without line breaks when bLineBreaks is true,
// other versions of OpenSSL will return a zero-length output.
//
// Functions which call this method do not always know the correct value for bLineBreaks, since
// the input may be too short to warrant a line break.
//
// To make this funciton less fragile, if the first attempt does not result in the expected
// output, try again with the opposite value set for bLineBreaks.
if (!pData||(0==outSize)) {
pData = App::Me().Crypto().Util().Base64Decode(Get(), &outSize, !bLineBreaks);
if (!pData||(0==outSize)) {
otErr << __FUNCTION__ << "Base64Decode fail\n";
return false;
}
}
theData.Assign(pData, outSize);
delete[] pData;
return true;
}
示例6: SetAndPackData
// This function will base64 ENCODE theData,
// and then Set() that as the string contents.
// Additionally it will pack and compress the data!
//
bool OTASCIIArmor::SetAndPackData(const OTData & theData, bool bLineBreaks/*=true*/)
{
char * pString = NULL;
Release();
if (theData.GetSize() < 1)
return true;
// --------------------------------------------------------
OTDB::OTPacker * pPacker = OTASCIIArmor::GetPacker(); // No need to check for failure, since this already ASSERTS. No need to cleanup either.
// Here I use the default storage context to create the object (the blob.)
// I also originally created OTASCIIArmor::GetPacker() using OTDB_DEFAULT_PACKER,
// so I know everything is compatible.
//
OTDB::Blob * pBlob = dynamic_cast<OTDB::Blob *>(OTDB::CreateObject(OTDB::STORED_OBJ_BLOB));
OT_ASSERT(NULL != pBlob); // Beyond this point, responsible to delete pBlob.
OTCleanup<OTDB::Blob> theBlobAngel(*pBlob); // make sure memory is cleaned up.
// ----------------------------
pBlob->m_memBuffer.assign(static_cast<const unsigned char *>(theData.GetPointer()),
static_cast<const unsigned char *>(theData.GetPointer())+theData.GetSize());
OTDB::PackedBuffer * pBuffer = pPacker->Pack(*pBlob); // Now we PACK our data before compressing/encoding it.
if (NULL == pBuffer)
{
OTLog::Error("Failed packing data in OTASCIIArmor::SetAndPackData. \n");
return false;
}
OTCleanup<OTDB::PackedBuffer> theBufferAngel(*pBuffer); // make sure memory is cleaned up.
// --------------------------------------------------------
const uint8_t* pUint = static_cast<const uint8_t*>(pBuffer->GetData());
const size_t theSize = pBuffer->GetSize();
if (NULL != pUint)
pString = OTCrypto::It()->Base64Encode(pUint, static_cast<int>(theSize), bLineBreaks);
// pString = OT_base64_encode(pUint, static_cast<int> (theSize), (bLineBreaks ? 1 : 0));
else
{
OTLog::Error("Error while base64_encoding in OTASCIIArmor::SetAndPackData.\n");
return false;
}
// -------------------------------------
if (NULL != pString)
{
Set(pString);
delete [] pString; pString=NULL;
return true;
}
else
{
OTLog::Error("Error while base64_encoding in OTASCIIArmor::SetAndPackData.\n");
return false;
}
}
示例7: setMemory
int32_t OTPassword::setMemory(const OTData& data)
{
const uint32_t dataSize = data.GetSize();
uint32_t returnedSize = dataSize;
bool memorySet = setMemory(data.GetPointer(), returnedSize);
// TODO maybe we should check for truncation?
return memorySet;
}
示例8: GetAndUnpackData
// This function will base64 DECODE the string contents
// and return them as binary in theData
// Additionally it will decompress and unpack the data!
//
bool OTASCIIArmor::GetAndUnpackData(OTData & theData, bool bLineBreaks) const //linebreaks=true
{
size_t outSize = 0;
uint8_t * pData = NULL;
theData.Release();
if (GetLength() < 1)
return true;
// --------------------------------------------------------------
//
pData = OT_base64_decode(Get(), &outSize, (bLineBreaks ? 1 : 0));
if (pData)
{
// --------------------------------------------------------
OTDB::OTPacker * pPacker = OTASCIIArmor::GetPacker(); // No need to check for failure, since this already ASSERTS. No need to cleanup either.
OTDB::PackedBuffer * pBuffer = pPacker->CreateBuffer(); // Need to clean this up.
OT_ASSERT(NULL != pBuffer);
OTCleanup<OTDB::PackedBuffer> theBufferAngel(*pBuffer); // make sure buffer is deleted.
pBuffer->SetData(static_cast<const unsigned char*>(pData), outSize);
delete [] pData; pData=NULL;
// -----------------------------
OTDB::Blob * pBlob = dynamic_cast<OTDB::Blob *>(OTDB::CreateObject(OTDB::STORED_OBJ_BLOB));
OT_ASSERT(NULL != pBlob);
OTCleanup<OTDB::Blob> theBlobAngel(*pBlob); // clean up this blob.
bool bUnpacked = pPacker->Unpack(*pBuffer, *pBlob);
// ----------------------
if (false == bUnpacked)
{
OTLog::Error("Failed unpacking data in OTASCIIArmor::GetAndUnpackData.\n");
delete [] pData; pData=NULL;
return false;
}
// --------------------------------------------------------
theData.Assign(pBlob->m_memBuffer.data(), pBlob->m_memBuffer.size());
delete [] pData; pData=NULL;
return true;
}
else
{
OTLog::Error("Error while base64_decoding in OTASCIIArmor::GetAndUnpackData.\n");
return false;
}
}
示例9: Nonce
String CryptoUtil::Nonce(const uint32_t size, OTData& rawOutput) const
{
rawOutput.zeroMemory();
rawOutput.SetSize(size);
OTPassword source;
source.randomizeMemory(size);
String nonce(Base58CheckEncode(source));
rawOutput.Assign(source.getMemory(), source.getMemorySize());
return nonce;
}
示例10: ConstructKey
void PaymentCode::ConstructKey(const OTData& pubkey, const OTData& chaincode)
{
proto::AsymmetricKey newKey;
newKey.set_version(1);
newKey.set_type(proto::AKEYTYPE_SECP256K1);
newKey.set_mode(proto::KEYMODE_PUBLIC);
newKey.set_role(proto::KEYROLE_SIGN);
newKey.set_key(pubkey.GetPointer(), pubkey.GetSize());
newKey.set_chaincode(chaincode.GetPointer(), chaincode.GetSize());
OTAsymmetricKey* key = OTAsymmetricKey::KeyFactory(newKey);
pubkey_.reset(key);
}
示例11: abort
uint32_t OTPayload::ReadBytesFrom(OTData & theData, uint32_t lSize)
{
// The size requested to read MUST be less or equal to size of theData
if (theData.GetSize() < lSize)
abort();
OTPayload & refPayload = (OTPayload &)theData;
// Copy from theData to this, up until lSize
Assign(refPayload.GetPayloadPointer(), lSize);
// Create a temp var, starting from theData+lSize, copying to the end of theData
OTData TEMPdata((unsigned char *)refPayload.GetPayloadPointer() + lSize, theData.GetSize() - lSize);
// theData is assigned to TEMPdata (thus removing from it the bytes that we just read into this.)
theData.Assign(TEMPdata);
return lSize;
}
示例12: SetData
// Base64-encode
bool OTASCIIArmor::SetData(const OTData& theData, bool bLineBreaks)
{
Release();
if (theData.GetSize() < 1) return true;
char* pString = App::Me().Crypto().Util().Base64Encode(
static_cast<const uint8_t*>(theData.GetPointer()), theData.GetSize(),
bLineBreaks);
if (!pString) {
otErr << __FUNCTION__ << "Base64Encode fail\n";
return false;
}
Set(pString);
delete[] pString;
return true;
}
示例13: Assign
void OTData::Assign(const OTData &theSource)
{
if ((&theSource) == this)
return; // can't assign to self.
if (false == theSource.IsEmpty()) // If something is there...
{
Assign(theSource.m_pData, theSource.m_lSize); // Copy it.
}
else
Release(); // Otherwise if it's empty, then empty this also.
}
示例14: Assign
void OTData::Assign(const OTData& source)
{
// can't assign to self.
if (&source == this) {
return;
}
if (!source.IsEmpty()) {
Assign(source.data_, source.size_);
}
else {
// Otherwise if it's empty, then empty this also.
Release();
}
}
示例15: CalculateDigest
bool Identifier::CalculateDigest(const OTData& dataInput)
{
auto dataPtr = static_cast<const unsigned char*>(dataInput.GetPointer());
return CalculateDigest(dataPtr, dataInput.GetSize());
}