Skip to content

Commit

Permalink
OTASCIIArmor: remove (Get|Set)(AndPack)?StringMap
Browse files Browse the repository at this point in the history
This is unused code that bloats the interface.

The class already allows armoring arbitrary byte arrays. Supporting arbitrary
data structures here makes no sense. In this case it creates a hard dependency
on the storage subsystem.  The encoding into byte arrays should be chosen at the
call site.
  • Loading branch information
OttoAllmendinger committed Oct 14, 2014
1 parent 4b4ec1f commit 055869f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 143 deletions.
12 changes: 0 additions & 12 deletions include/opentxs/core/crypto/OTASCIIArmor.hpp
Expand Up @@ -267,18 +267,6 @@ class OTASCIIArmor : public OTString
EXPORT bool SetAndPackString(const OTString& theData,
bool bLineBreaks = true);

EXPORT bool GetStringMap(std::map<std::string, std::string>& the_map,
bool bLineBreaks = true) const;
EXPORT bool GetAndUnpackStringMap(
std::map<std::string, std::string>& the_map,
bool bLineBreaks = true) const;

EXPORT bool SetStringMap(const std::map<std::string, std::string>& the_map,
bool bLineBreaks = true);
EXPORT bool SetAndPackStringMap(
const std::map<std::string, std::string>& the_map,
bool bLineBreaks = true);

private:
static std::unique_ptr<OTDB::OTPacker> s_pPacker;
};
Expand Down
131 changes: 0 additions & 131 deletions src/core/crypto/OTASCIIArmor.cpp
Expand Up @@ -480,137 +480,6 @@ bool OTASCIIArmor::GetString(OTString& strData,
return GetAndUnpackString(strData, bLineBreaks);
}

bool OTASCIIArmor::GetStringMap(std::map<std::string, std::string>& the_map,
bool bLineBreaks) const
{
return GetAndUnpackStringMap(the_map, bLineBreaks);
}

bool OTASCIIArmor::GetAndUnpackStringMap(
std::map<std::string, std::string>& the_map, bool bLineBreaks) const
{
size_t outSize = 0;
uint8_t* pData = nullptr;

the_map.clear();

if (GetLength() < 1) return true;

pData = OTCrypto::It()->Base64Decode(Get(), &outSize, bLineBreaks);

if (pData) {

OTDB::OTPacker* pPacker =
OTASCIIArmor::GetPacker(); // No need to check for failure, since
// this already ASSERTS. No need to
// cleanup either.

std::unique_ptr<OTDB::PackedBuffer> pBuffer(
pPacker->CreateBuffer()); // Need to clean this up.
OT_ASSERT(nullptr != pBuffer);

pBuffer->SetData(static_cast<const uint8_t*>(pData), outSize);
delete[] pData;
pData = nullptr;

std::unique_ptr<OTDB::StringMap> pStringMap(
dynamic_cast<OTDB::StringMap*>(
OTDB::CreateObject(OTDB::STORED_OBJ_STRING_MAP)));
OT_ASSERT(nullptr != pStringMap);

bool bUnpacked = pPacker->Unpack(*pBuffer, *pStringMap);

if (!bUnpacked) {
otErr << "Failed unpacking data in "
"OTASCIIArmor::GetAndUnpackStringMap.\n";
delete[] pData;
pData = nullptr;
return false;
}

the_map = pStringMap->the_map;

delete[] pData;
pData = nullptr;
return true;
}
else {
otErr << "Error while base64_decoding in "
"OTASCIIArmor::GetAndUnpackStringMap.\n";
return false;
}
}

bool OTASCIIArmor::SetStringMap(
const std::map<std::string, std::string>& the_map, bool bLineBreaks)
{
return SetAndPackStringMap(the_map, bLineBreaks);
}

bool OTASCIIArmor::SetAndPackStringMap(
const std::map<std::string, std::string>& the_map, bool bLineBreaks)
{
char* pString = nullptr;

Release();

if (the_map.empty()) 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 string
// map.)
// I also originally created OTASCIIArmor::GetPacker() using
// OTDB_DEFAULT_PACKER,
// so I know everything is compatible.
//
std::unique_ptr<OTDB::StringMap> pStringMap(dynamic_cast<OTDB::StringMap*>(
OTDB::CreateObject(OTDB::STORED_OBJ_STRING_MAP)));

OT_ASSERT(nullptr !=
pStringMap); // Beyond this point, responsible to delete
// pStringMap.

pStringMap->the_map = the_map;

std::unique_ptr<OTDB::PackedBuffer> pBuffer(pPacker->Pack(
*pStringMap)); // Now we PACK our data before compressing/encoding it.

if (nullptr == pBuffer) {
otErr << "Failed packing data in OTASCIIArmor::SetAndPackStringMap. \n";
return false;
}

const uint8_t* pUint = static_cast<const uint8_t*>(pBuffer->GetData());
const size_t theSize = pBuffer->GetSize();

if (nullptr != pUint)
pString = OTCrypto::It()->Base64Encode(
pUint, static_cast<int32_t>(theSize), bLineBreaks);
// pString = OT_base64_encode(pUint, static_cast<int32_t> (theSize),
// (bLineBreaks ? 1 : 0));
else {
otErr << "Error while base64_encoding in "
"OTASCIIArmor::SetAndPackStringMap.\n";
return false;
}

if (nullptr != pString) {
Set(pString);
delete[] pString;
pString = nullptr;
return true;
}
else {
otErr << "Error while base64_encoding in "
"OTASCIIArmor::SetAndPackStringMap.\n";
return false;
}
}

// This function will base64 DECODE the string contents
// and return them as binary in theData
bool OTASCIIArmor::GetData(OTData& theData,
Expand Down

0 comments on commit 055869f

Please sign in to comment.