Changeset View
Changeset View
Standalone View
Standalone View
src/base58.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | std::string EncodeBase58(const uint8_t *pbegin, const uint8_t *pend) { | ||||
str.assign(zeroes, '1'); | str.assign(zeroes, '1'); | ||||
while (it != b58.end()) { | while (it != b58.end()) { | ||||
str += pszBase58[*(it++)]; | str += pszBase58[*(it++)]; | ||||
} | } | ||||
return str; | return str; | ||||
} | } | ||||
std::string EncodeBase58(const std::vector<uint8_t> &vch) { | std::string EncodeBase58(const std::vector<uint8_t> &vch) { | ||||
return EncodeBase58(&vch[0], &vch[0] + vch.size()); | return EncodeBase58(vch.data(), vch.data() + vch.size()); | ||||
} | } | ||||
bool DecodeBase58(const std::string &str, std::vector<uint8_t> &vchRet) { | bool DecodeBase58(const std::string &str, std::vector<uint8_t> &vchRet) { | ||||
return DecodeBase58(str.c_str(), vchRet); | return DecodeBase58(str.c_str(), vchRet); | ||||
} | } | ||||
std::string EncodeBase58Check(const std::vector<uint8_t> &vchIn) { | std::string EncodeBase58Check(const std::vector<uint8_t> &vchIn) { | ||||
// add 4-byte hash check to the end | // add 4-byte hash check to the end | ||||
Show All 27 Lines | CBase58Data::CBase58Data() { | ||||
vchData.clear(); | vchData.clear(); | ||||
} | } | ||||
void CBase58Data::SetData(const std::vector<uint8_t> &vchVersionIn, | void CBase58Data::SetData(const std::vector<uint8_t> &vchVersionIn, | ||||
const void *pdata, size_t nSize) { | const void *pdata, size_t nSize) { | ||||
vchVersion = vchVersionIn; | vchVersion = vchVersionIn; | ||||
vchData.resize(nSize); | vchData.resize(nSize); | ||||
if (!vchData.empty()) { | if (!vchData.empty()) { | ||||
memcpy(&vchData[0], pdata, nSize); | memcpy(vchData.data(), pdata, nSize); | ||||
} | } | ||||
} | } | ||||
void CBase58Data::SetData(const std::vector<uint8_t> &vchVersionIn, | void CBase58Data::SetData(const std::vector<uint8_t> &vchVersionIn, | ||||
const uint8_t *pbegin, const uint8_t *pend) { | const uint8_t *pbegin, const uint8_t *pend) { | ||||
SetData(vchVersionIn, (void *)pbegin, pend - pbegin); | SetData(vchVersionIn, (void *)pbegin, pend - pbegin); | ||||
} | } | ||||
bool CBase58Data::SetString(const char *psz, unsigned int nVersionBytes) { | bool CBase58Data::SetString(const char *psz, unsigned int nVersionBytes) { | ||||
std::vector<uint8_t> vchTemp; | std::vector<uint8_t> vchTemp; | ||||
bool rc58 = DecodeBase58Check(psz, vchTemp); | bool rc58 = DecodeBase58Check(psz, vchTemp); | ||||
if ((!rc58) || (vchTemp.size() < nVersionBytes)) { | if ((!rc58) || (vchTemp.size() < nVersionBytes)) { | ||||
vchData.clear(); | vchData.clear(); | ||||
vchVersion.clear(); | vchVersion.clear(); | ||||
return false; | return false; | ||||
} | } | ||||
vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes); | vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes); | ||||
vchData.resize(vchTemp.size() - nVersionBytes); | vchData.resize(vchTemp.size() - nVersionBytes); | ||||
if (!vchData.empty()) { | if (!vchData.empty()) { | ||||
memcpy(&vchData[0], &vchTemp[nVersionBytes], vchData.size()); | memcpy(vchData.data(), vchTemp.data() + nVersionBytes, vchData.size()); | ||||
} | } | ||||
memory_cleanse(&vchTemp[0], vchTemp.size()); | memory_cleanse(vchTemp.data(), vchTemp.size()); | ||||
return true; | return true; | ||||
} | } | ||||
bool CBase58Data::SetString(const std::string &str) { | bool CBase58Data::SetString(const std::string &str) { | ||||
return SetString(str.c_str()); | return SetString(str.c_str()); | ||||
} | } | ||||
std::string CBase58Data::ToString() const { | std::string CBase58Data::ToString() const { | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |