// 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; } }
// 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; }
// 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; } }