mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 05:25:55 +00:00
Replace std::vector<unsigned char> with Blob
This commit is contained in:
@@ -58,7 +58,7 @@ std::string Base58::encode (const unsigned char* pbegin, const unsigned char* pe
|
||||
|
||||
// Convert big endian data to little endian
|
||||
// Extra zero at the end make sure bignum will interpret as a positive number
|
||||
std::vector<unsigned char> vchTmp(pend-pbegin+1, 0);
|
||||
Blob vchTmp(pend-pbegin+1, 0);
|
||||
std::reverse_copy(pbegin, pend, vchTmp.begin());
|
||||
|
||||
// Convert little endian data to bignum
|
||||
@@ -89,21 +89,21 @@ std::string Base58::encode (const unsigned char* pbegin, const unsigned char* pe
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string Base58::encode (const std::vector<unsigned char>& vch)
|
||||
std::string Base58::encode (Blob const& vch)
|
||||
{
|
||||
return encode (&vch[0], &vch[0] + vch.size());
|
||||
}
|
||||
|
||||
std::string Base58::encodeWithCheck (const std::vector<unsigned char>& vchIn)
|
||||
std::string Base58::encodeWithCheck (Blob const& vchIn)
|
||||
{
|
||||
// add 4-byte hash check to the end
|
||||
std::vector<unsigned char> vch(vchIn);
|
||||
Blob vch(vchIn);
|
||||
uint256 hash = SHA256Hash(vch.begin(), vch.end());
|
||||
vch.insert(vch.end(), (unsigned char*)&hash, (unsigned char*)&hash + 4);
|
||||
return encode (vch);
|
||||
}
|
||||
|
||||
bool Base58::decode (const char* psz, std::vector<unsigned char>& vchRet, const char* pAlpha)
|
||||
bool Base58::decode (const char* psz, Blob & vchRet, const char* pAlpha)
|
||||
{
|
||||
assert (pAlpha != 0);
|
||||
|
||||
@@ -134,7 +134,7 @@ bool Base58::decode (const char* psz, std::vector<unsigned char>& vchRet, const
|
||||
}
|
||||
|
||||
// Get bignum as little endian data
|
||||
std::vector<unsigned char> vchTmp = bn.getvch();
|
||||
Blob vchTmp = bn.getvch();
|
||||
|
||||
// Trim off sign byte if present
|
||||
if (vchTmp.size() >= 2 && vchTmp.end()[-1] == 0 && vchTmp.end()[-2] >= 0x80)
|
||||
@@ -151,12 +151,12 @@ bool Base58::decode (const char* psz, std::vector<unsigned char>& vchRet, const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Base58::decode (const std::string& str, std::vector<unsigned char>& vchRet)
|
||||
bool Base58::decode (const std::string& str, Blob & vchRet)
|
||||
{
|
||||
return decode (str.c_str(), vchRet);
|
||||
}
|
||||
|
||||
bool Base58::decodeWithCheck (const char* psz, std::vector<unsigned char>& vchRet, const char* pAlphabet)
|
||||
bool Base58::decodeWithCheck (const char* psz, Blob & vchRet, const char* pAlphabet)
|
||||
{
|
||||
assert (pAlphabet != NULL);
|
||||
|
||||
@@ -177,7 +177,7 @@ bool Base58::decodeWithCheck (const char* psz, std::vector<unsigned char>& vchRe
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Base58::decodeWithCheck (const std::string& str, std::vector<unsigned char>& vchRet, const char* pAlphabet)
|
||||
bool Base58::decodeWithCheck (const std::string& str, Blob & vchRet, const char* pAlphabet)
|
||||
{
|
||||
return decodeWithCheck (str.c_str(), vchRet, pAlphabet);
|
||||
}
|
||||
|
||||
@@ -45,13 +45,13 @@ public:
|
||||
static char const* getTestnetAlphabet ();
|
||||
|
||||
static std::string encode (const unsigned char* pbegin, const unsigned char* pend);
|
||||
static std::string encode (const std::vector<unsigned char>& vch);
|
||||
static std::string encodeWithCheck (const std::vector<unsigned char>& vchIn);
|
||||
static std::string encode (Blob const& vch);
|
||||
static std::string encodeWithCheck (Blob const& vchIn);
|
||||
|
||||
static bool decode (const char* psz, std::vector<unsigned char>& vchRet, const char* pAlphabet=getCurrentAlphabet ());
|
||||
static bool decode (const std::string& str, std::vector<unsigned char>& vchRet);
|
||||
static bool decodeWithCheck (const char* psz, std::vector<unsigned char>& vchRet, const char* pAlphabet=getCurrentAlphabet ());
|
||||
static bool decodeWithCheck (const std::string& str, std::vector<unsigned char>& vchRet, const char* pAlphabet);
|
||||
static bool decode (const char* psz, Blob & vchRet, const char* pAlphabet=getCurrentAlphabet ());
|
||||
static bool decode (const std::string& str, Blob & vchRet);
|
||||
static bool decodeWithCheck (const char* psz, Blob & vchRet, const char* pAlphabet=getCurrentAlphabet ());
|
||||
static bool decodeWithCheck (const std::string& str, Blob & vchRet, const char* pAlphabet);
|
||||
|
||||
private:
|
||||
static char const* s_currentAlphabet;
|
||||
|
||||
@@ -40,7 +40,7 @@ CBase58Data::~CBase58Data()
|
||||
memset(&vchData[0], 0, vchData.size());
|
||||
}
|
||||
|
||||
void CBase58Data::SetData(int nVersionIn, const std::vector<unsigned char>& vchDataIn)
|
||||
void CBase58Data::SetData(int nVersionIn, Blob const& vchDataIn)
|
||||
{
|
||||
nVersion = nVersionIn;
|
||||
vchData = vchDataIn;
|
||||
@@ -61,7 +61,7 @@ void CBase58Data::SetData(int nVersionIn, const unsigned char *pbegin, const uns
|
||||
|
||||
bool CBase58Data::SetString(const char* psz, unsigned char version, const char* pAlphabet)
|
||||
{
|
||||
std::vector<unsigned char> vchTemp;
|
||||
Blob vchTemp;
|
||||
Base58::decodeWithCheck (psz, vchTemp, pAlphabet);
|
||||
if (vchTemp.empty() || vchTemp[0] != version)
|
||||
{
|
||||
@@ -84,7 +84,7 @@ bool CBase58Data::SetString(const std::string& str, unsigned char version)
|
||||
|
||||
std::string CBase58Data::ToString() const
|
||||
{
|
||||
std::vector<unsigned char> vch(1, nVersion);
|
||||
Blob vch(1, nVersion);
|
||||
|
||||
vch.insert(vch.end(), vchData.begin(), vchData.end());
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@ class CBase58Data
|
||||
{
|
||||
protected:
|
||||
unsigned char nVersion;
|
||||
std::vector<unsigned char> vchData;
|
||||
Blob vchData;
|
||||
|
||||
CBase58Data();
|
||||
~CBase58Data();
|
||||
|
||||
void SetData(int nVersionIn, const std::vector<unsigned char>& vchDataIn);
|
||||
void SetData(int nVersionIn, Blob const& vchDataIn);
|
||||
void SetData(int nVersionIn, const void* pdata, size_t nSize);
|
||||
void SetData(int nVersionIn, const unsigned char *pbegin, const unsigned char *pend);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ CBigNum::CBigNum(unsigned int n) { BN_init(this); setulong(n); }
|
||||
CBigNum::CBigNum(uint64 n) { BN_init(this); setuint64(n); }
|
||||
CBigNum::CBigNum(uint256 n) { BN_init(this); setuint256(n); }
|
||||
|
||||
CBigNum::CBigNum(const std::vector<unsigned char>& vch)
|
||||
CBigNum::CBigNum(Blob const& vch)
|
||||
{
|
||||
BN_init(this);
|
||||
setvch(vch);
|
||||
@@ -154,9 +154,9 @@ uint256 CBigNum::getuint256()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CBigNum::setvch(const std::vector<unsigned char>& vch)
|
||||
void CBigNum::setvch(Blob const& vch)
|
||||
{
|
||||
std::vector<unsigned char> vch2(vch.size() + 4);
|
||||
Blob vch2(vch.size() + 4);
|
||||
unsigned int nSize = vch.size();
|
||||
// BIGNUM's byte stream format expects 4 bytes of
|
||||
// big endian size data info at the front
|
||||
@@ -169,12 +169,12 @@ void CBigNum::setvch(const std::vector<unsigned char>& vch)
|
||||
BN_mpi2bn(&vch2[0], vch2.size(), this);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> CBigNum::getvch() const
|
||||
Blob CBigNum::getvch() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(this, NULL);
|
||||
if (nSize < 4)
|
||||
return std::vector<unsigned char>();
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
return Blob ();
|
||||
Blob vch(nSize);
|
||||
BN_bn2mpi(this, &vch[0]);
|
||||
vch.erase(vch.begin(), vch.begin() + 4);
|
||||
reverse(vch.begin(), vch.end());
|
||||
@@ -184,7 +184,7 @@ std::vector<unsigned char> CBigNum::getvch() const
|
||||
CBigNum& CBigNum::SetCompact(unsigned int nCompact)
|
||||
{
|
||||
unsigned int nSize = nCompact >> 24;
|
||||
std::vector<unsigned char> vch(4 + nSize);
|
||||
Blob vch(4 + nSize);
|
||||
vch[3] = nSize;
|
||||
if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
|
||||
if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
|
||||
@@ -196,7 +196,7 @@ CBigNum& CBigNum::SetCompact(unsigned int nCompact)
|
||||
unsigned int CBigNum::GetCompact() const
|
||||
{
|
||||
unsigned int nSize = BN_bn2mpi(this, NULL);
|
||||
std::vector<unsigned char> vch(nSize);
|
||||
Blob vch(nSize);
|
||||
nSize -= 4;
|
||||
BN_bn2mpi(this, &vch[0]);
|
||||
unsigned int nCompact = nSize << 24;
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
CBigNum(unsigned int n);
|
||||
CBigNum(uint64 n);
|
||||
explicit CBigNum(uint256 n);
|
||||
explicit CBigNum(const std::vector<unsigned char>& vch);
|
||||
explicit CBigNum(Blob const& vch);
|
||||
~CBigNum();
|
||||
|
||||
void setuint(unsigned int n);
|
||||
@@ -81,8 +81,8 @@ public:
|
||||
void setuint64(uint64 n);
|
||||
void setuint256(const uint256& n);
|
||||
uint256 getuint256();
|
||||
void setvch(const std::vector<unsigned char>& vch);
|
||||
std::vector<unsigned char> getvch() const;
|
||||
void setvch(Blob const& vch);
|
||||
Blob getvch() const;
|
||||
CBigNum& SetCompact(unsigned int nCompact);
|
||||
unsigned int GetCompact() const;
|
||||
void SetHex(const std::string& str);
|
||||
|
||||
@@ -224,7 +224,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
|
||||
bool SetPubKey(Blob const& vchPubKey)
|
||||
{
|
||||
return SetPubKey(&vchPubKey[0], vchPubKey.size());
|
||||
}
|
||||
@@ -234,13 +234,13 @@ public:
|
||||
return SetPubKey(pubKey.data(), pubKey.size());
|
||||
}
|
||||
|
||||
std::vector<unsigned char> GetPubKey() const
|
||||
Blob GetPubKey() const
|
||||
{
|
||||
unsigned int nSize = i2o_ECPublicKey(pkey, NULL);
|
||||
assert(nSize<=33);
|
||||
if (!nSize)
|
||||
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey failed");
|
||||
std::vector<unsigned char> vchPubKey(33, 0);
|
||||
Blob vchPubKey(33, 0);
|
||||
unsigned char* pbegin = &vchPubKey[0];
|
||||
if (i2o_ECPublicKey(pkey, &pbegin) != nSize)
|
||||
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey returned unexpected size");
|
||||
@@ -248,7 +248,7 @@ public:
|
||||
return vchPubKey;
|
||||
}
|
||||
|
||||
bool Sign(const uint256& hash, std::vector<unsigned char>& vchSig)
|
||||
bool Sign(const uint256& hash, Blob & vchSig)
|
||||
{
|
||||
unsigned char pchSig[10000];
|
||||
unsigned int nSize = 0;
|
||||
@@ -272,7 +272,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Verify(const uint256& hash, const std::vector<unsigned char>& vchSig) const
|
||||
bool Verify(const uint256& hash, Blob const& vchSig) const
|
||||
{
|
||||
return Verify(hash, &vchSig[0], vchSig.size());
|
||||
}
|
||||
@@ -289,8 +289,8 @@ public:
|
||||
|
||||
// encrypt/decrypt functions with integrity checking.
|
||||
// Note that the other side must somehow know what keys to use
|
||||
std::vector<unsigned char> encryptECIES(CKey& otherKey, const std::vector<unsigned char>& plaintext);
|
||||
std::vector<unsigned char> decryptECIES(CKey& otherKey, const std::vector<unsigned char>& ciphertext);
|
||||
Blob encryptECIES(CKey& otherKey, Blob const& plaintext);
|
||||
Blob decryptECIES(CKey& otherKey, Blob const& ciphertext);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -71,7 +71,7 @@ void CKey::getECIESSecret(CKey& otherKey, ECIES_ENC_KEY_TYPE& enc_key, ECIES_HMA
|
||||
memset(hbuf, 0, ECIES_KEY_LENGTH);
|
||||
}
|
||||
|
||||
static ECIES_HMAC_TYPE makeHMAC(const ECIES_HMAC_KEY_TYPE& secret, const std::vector<unsigned char>& data)
|
||||
static ECIES_HMAC_TYPE makeHMAC(const ECIES_HMAC_KEY_TYPE& secret, Blob const& data)
|
||||
{
|
||||
HMAC_CTX ctx;
|
||||
HMAC_CTX_init(&ctx);
|
||||
@@ -101,7 +101,7 @@ static ECIES_HMAC_TYPE makeHMAC(const ECIES_HMAC_KEY_TYPE& secret, const std::ve
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<unsigned char>& plaintext)
|
||||
Blob CKey::encryptECIES(CKey& otherKey, Blob const& plaintext)
|
||||
{
|
||||
|
||||
ECIES_ENC_IV_TYPE iv;
|
||||
@@ -125,7 +125,7 @@ std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<
|
||||
}
|
||||
secret.zero();
|
||||
|
||||
std::vector<unsigned char> out(plaintext.size() + ECIES_HMAC_SIZE + ECIES_ENC_KEY_SIZE + ECIES_ENC_BLK_SIZE, 0);
|
||||
Blob out(plaintext.size() + ECIES_HMAC_SIZE + ECIES_ENC_KEY_SIZE + ECIES_ENC_BLK_SIZE, 0);
|
||||
int len = 0, bytesWritten;
|
||||
|
||||
// output IV
|
||||
@@ -169,7 +169,7 @@ std::vector<unsigned char> CKey::encryptECIES(CKey& otherKey, const std::vector<
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> CKey::decryptECIES(CKey& otherKey, const std::vector<unsigned char>& ciphertext)
|
||||
Blob CKey::decryptECIES(CKey& otherKey, Blob const& ciphertext)
|
||||
{
|
||||
// minimum ciphertext = IV + HMAC + 1 block
|
||||
if (ciphertext.size() < ((2 * ECIES_ENC_BLK_SIZE) + ECIES_HMAC_SIZE) )
|
||||
@@ -208,7 +208,7 @@ std::vector<unsigned char> CKey::decryptECIES(CKey& otherKey, const std::vector<
|
||||
}
|
||||
|
||||
// decrypt plaintext (after IV and encrypted mac)
|
||||
std::vector<unsigned char> plaintext(ciphertext.size() - ECIES_HMAC_SIZE - ECIES_ENC_BLK_SIZE);
|
||||
Blob plaintext(ciphertext.size() - ECIES_HMAC_SIZE - ECIES_ENC_BLK_SIZE);
|
||||
outlen = plaintext.size();
|
||||
if (EVP_DecryptUpdate(&ctx, &(plaintext.front()), &outlen,
|
||||
&(ciphertext.front()) + ECIES_ENC_BLK_SIZE + ECIES_HMAC_SIZE + 1,
|
||||
@@ -265,17 +265,17 @@ bool checkECIES(void)
|
||||
}
|
||||
|
||||
// generate message
|
||||
std::vector<unsigned char> message(4096);
|
||||
Blob message(4096);
|
||||
int msglen = i%3000;
|
||||
|
||||
RandomNumbers::getInstance ().fillBytes (&message.front(), msglen);
|
||||
message.resize(msglen);
|
||||
|
||||
// encrypt message with sender's private key and recipient's public key
|
||||
std::vector<unsigned char> ciphertext = senderPriv.encryptECIES(recipientPub, message);
|
||||
Blob ciphertext = senderPriv.encryptECIES(recipientPub, message);
|
||||
|
||||
// decrypt message with recipient's private key and sender's public key
|
||||
std::vector<unsigned char> decrypt = recipientPriv.decryptECIES(senderPub, ciphertext);
|
||||
Blob decrypt = recipientPriv.decryptECIES(senderPub, ciphertext);
|
||||
|
||||
if (decrypt != message)
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ RippleAddress RippleAddress::createNodePublic(const RippleAddress& naSeed)
|
||||
return naNew;
|
||||
}
|
||||
|
||||
RippleAddress RippleAddress::createNodePublic(const std::vector<unsigned char>& vPublic)
|
||||
RippleAddress RippleAddress::createNodePublic(Blob const& vPublic)
|
||||
{
|
||||
RippleAddress naNew;
|
||||
|
||||
@@ -87,7 +87,7 @@ uint160 RippleAddress::getNodeID() const
|
||||
throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
|
||||
}
|
||||
}
|
||||
const std::vector<unsigned char>& RippleAddress::getNodePublic() const
|
||||
Blob const& RippleAddress::getNodePublic() const
|
||||
{
|
||||
switch (nVersion) {
|
||||
case VER_NONE:
|
||||
@@ -122,14 +122,14 @@ bool RippleAddress::setNodePublic(const std::string& strPublic)
|
||||
return mIsValid;
|
||||
}
|
||||
|
||||
void RippleAddress::setNodePublic(const std::vector<unsigned char>& vPublic)
|
||||
void RippleAddress::setNodePublic(Blob const& vPublic)
|
||||
{
|
||||
mIsValid = true;
|
||||
|
||||
SetData(VER_NODE_PUBLIC, vPublic);
|
||||
}
|
||||
|
||||
bool RippleAddress::verifyNodePublic(const uint256& hash, const std::vector<unsigned char>& vchSig) const
|
||||
bool RippleAddress::verifyNodePublic(const uint256& hash, Blob const& vchSig) const
|
||||
{
|
||||
CKey pubkey = CKey();
|
||||
bool bVerified;
|
||||
@@ -149,7 +149,7 @@ bool RippleAddress::verifyNodePublic(const uint256& hash, const std::vector<unsi
|
||||
|
||||
bool RippleAddress::verifyNodePublic(const uint256& hash, const std::string& strSig) const
|
||||
{
|
||||
std::vector<unsigned char> vchSig(strSig.begin(), strSig.end());
|
||||
Blob vchSig(strSig.begin(), strSig.end());
|
||||
|
||||
return verifyNodePublic(hash, vchSig);
|
||||
}
|
||||
@@ -171,7 +171,7 @@ RippleAddress RippleAddress::createNodePrivate(const RippleAddress& naSeed)
|
||||
return naNew;
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& RippleAddress::getNodePrivateData() const
|
||||
Blob const& RippleAddress::getNodePrivateData() const
|
||||
{
|
||||
switch (nVersion) {
|
||||
case VER_NONE:
|
||||
@@ -220,7 +220,7 @@ bool RippleAddress::setNodePrivate(const std::string& strPrivate)
|
||||
return mIsValid;
|
||||
}
|
||||
|
||||
void RippleAddress::setNodePrivate(const std::vector<unsigned char>& vPrivate)
|
||||
void RippleAddress::setNodePrivate(Blob const& vPrivate)
|
||||
{
|
||||
mIsValid = true;
|
||||
|
||||
@@ -234,7 +234,7 @@ void RippleAddress::setNodePrivate(uint256 hash256)
|
||||
SetData(VER_NODE_PRIVATE, hash256.begin(), 32);
|
||||
}
|
||||
|
||||
void RippleAddress::signNodePrivate(const uint256& hash, std::vector<unsigned char>& vchSig) const
|
||||
void RippleAddress::signNodePrivate(const uint256& hash, Blob & vchSig) const
|
||||
{
|
||||
CKey ckPrivKey;
|
||||
|
||||
@@ -267,7 +267,7 @@ uint160 RippleAddress::getAccountID() const
|
||||
}
|
||||
|
||||
static boost::mutex rncLock;
|
||||
static boost::unordered_map< std::vector<unsigned char>, std::string > rncMap;
|
||||
static boost::unordered_map< Blob , std::string > rncMap;
|
||||
|
||||
std::string RippleAddress::humanAccountID() const
|
||||
{
|
||||
@@ -278,7 +278,7 @@ std::string RippleAddress::humanAccountID() const
|
||||
case VER_ACCOUNT_ID:
|
||||
{
|
||||
boost::mutex::scoped_lock sl(rncLock);
|
||||
boost::unordered_map< std::vector<unsigned char>, std::string >::iterator it = rncMap.find(vchData);
|
||||
boost::unordered_map< Blob , std::string >::iterator it = rncMap.find(vchData);
|
||||
if (it != rncMap.end())
|
||||
return it->second;
|
||||
if (rncMap.size() > 10000)
|
||||
@@ -337,7 +337,7 @@ RippleAddress RippleAddress::createAccountPublic(const RippleAddress& naGenerato
|
||||
return naNew;
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& RippleAddress::getAccountPublic() const
|
||||
Blob const& RippleAddress::getAccountPublic() const
|
||||
{
|
||||
switch (nVersion) {
|
||||
case VER_NONE:
|
||||
@@ -379,7 +379,7 @@ bool RippleAddress::setAccountPublic(const std::string& strPublic)
|
||||
return mIsValid;
|
||||
}
|
||||
|
||||
void RippleAddress::setAccountPublic(const std::vector<unsigned char>& vPublic)
|
||||
void RippleAddress::setAccountPublic(Blob const& vPublic)
|
||||
{
|
||||
mIsValid = true;
|
||||
|
||||
@@ -393,7 +393,7 @@ void RippleAddress::setAccountPublic(const RippleAddress& generator, int seq)
|
||||
setAccountPublic(pubkey.GetPubKey());
|
||||
}
|
||||
|
||||
bool RippleAddress::accountPublicVerify(const uint256& uHash, const std::vector<unsigned char>& vucSig) const
|
||||
bool RippleAddress::accountPublicVerify(const uint256& uHash, Blob const& vucSig) const
|
||||
{
|
||||
CKey ckPublic;
|
||||
bool bVerified;
|
||||
@@ -469,7 +469,7 @@ bool RippleAddress::setAccountPrivate(const std::string& strPrivate)
|
||||
return mIsValid;
|
||||
}
|
||||
|
||||
void RippleAddress::setAccountPrivate(const std::vector<unsigned char>& vPrivate)
|
||||
void RippleAddress::setAccountPrivate(Blob const& vPrivate)
|
||||
{
|
||||
mIsValid = true;
|
||||
|
||||
@@ -494,7 +494,7 @@ void RippleAddress::setAccountPrivate(const RippleAddress& naGenerator, const Ri
|
||||
setAccountPrivate(uPrivKey);
|
||||
}
|
||||
|
||||
bool RippleAddress::accountPrivateSign(const uint256& uHash, std::vector<unsigned char>& vucSig) const
|
||||
bool RippleAddress::accountPrivateSign(const uint256& uHash, Blob & vucSig) const
|
||||
{
|
||||
CKey ckPrivate;
|
||||
bool bResult;
|
||||
@@ -515,7 +515,7 @@ bool RippleAddress::accountPrivateSign(const uint256& uHash, std::vector<unsigne
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool RippleAddress::accountPrivateVerify(const uint256& uHash, const std::vector<unsigned char>& vucSig) const
|
||||
bool RippleAddress::accountPrivateVerify(const uint256& uHash, Blob const& vucSig) const
|
||||
{
|
||||
CKey ckPrivate;
|
||||
bool bVerified;
|
||||
@@ -535,11 +535,11 @@ bool RippleAddress::accountPrivateVerify(const uint256& uHash, const std::vector
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<unsigned char> RippleAddress::accountPrivateEncrypt(const RippleAddress& naPublicTo, const std::vector<unsigned char>& vucPlainText) const
|
||||
Blob RippleAddress::accountPrivateEncrypt(const RippleAddress& naPublicTo, Blob const& vucPlainText) const
|
||||
{
|
||||
CKey ckPrivate;
|
||||
CKey ckPublic;
|
||||
std::vector<unsigned char> vucCipherText;
|
||||
Blob vucCipherText;
|
||||
|
||||
if (!ckPublic.SetPubKey(naPublicTo.getAccountPublic()))
|
||||
{
|
||||
@@ -566,11 +566,11 @@ std::vector<unsigned char> RippleAddress::accountPrivateEncrypt(const RippleAddr
|
||||
return vucCipherText;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> RippleAddress::accountPrivateDecrypt(const RippleAddress& naPublicFrom, const std::vector<unsigned char>& vucCipherText) const
|
||||
Blob RippleAddress::accountPrivateDecrypt(const RippleAddress& naPublicFrom, Blob const& vucCipherText) const
|
||||
{
|
||||
CKey ckPrivate;
|
||||
CKey ckPublic;
|
||||
std::vector<unsigned char> vucPlainText;
|
||||
Blob vucPlainText;
|
||||
|
||||
if (!ckPublic.SetPubKey(naPublicFrom.getAccountPublic()))
|
||||
{
|
||||
@@ -619,7 +619,7 @@ BIGNUM* RippleAddress::getGeneratorBN() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& RippleAddress::getGenerator() const
|
||||
Blob const& RippleAddress::getGenerator() const
|
||||
{ // returns the public generator
|
||||
switch (nVersion) {
|
||||
case VER_NONE:
|
||||
@@ -655,7 +655,7 @@ bool RippleAddress::setGenerator(const std::string& strGenerator)
|
||||
return mIsValid;
|
||||
}
|
||||
|
||||
void RippleAddress::setGenerator(const std::vector<unsigned char>& vPublic)
|
||||
void RippleAddress::setGenerator(Blob const& vPublic)
|
||||
{
|
||||
mIsValid = true;
|
||||
|
||||
@@ -738,7 +738,7 @@ int RippleAddress::setSeed1751(const std::string& strHuman1751)
|
||||
|
||||
if (1 == iResult)
|
||||
{
|
||||
std::vector<unsigned char> vchLittle(strKey.rbegin(), strKey.rend());
|
||||
Blob vchLittle(strKey.rbegin(), strKey.rend());
|
||||
uint128 uSeed(vchLittle);
|
||||
|
||||
setSeed(uSeed);
|
||||
@@ -844,9 +844,9 @@ BOOST_AUTO_TEST_CASE( check_crypto )
|
||||
BOOST_CHECK_MESSAGE(naNodePrivate.humanNodePrivate() == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", naNodePrivate.humanNodePrivate());
|
||||
|
||||
// Check node signing.
|
||||
std::vector<unsigned char> vucTextSrc = strCopy("Hello, nurse!");
|
||||
Blob vucTextSrc = strCopy("Hello, nurse!");
|
||||
uint256 uHash = Serializer::getSHA512Half(vucTextSrc);
|
||||
std::vector<unsigned char> vucTextSig;
|
||||
Blob vucTextSig;
|
||||
|
||||
naNodePrivate.signNodePrivate(uHash, vucTextSig);
|
||||
BOOST_CHECK_MESSAGE(naNodePublic.verifyNodePublic(uHash, vucTextSig), "Verify failed.");
|
||||
@@ -882,9 +882,9 @@ BOOST_AUTO_TEST_CASE( check_crypto )
|
||||
BOOST_CHECK_MESSAGE(!naAccountPublic0.accountPublicVerify(uHash, vucTextSig), "Anti-verify failed.");
|
||||
|
||||
// Check account encryption.
|
||||
std::vector<unsigned char> vucTextCipher
|
||||
Blob vucTextCipher
|
||||
= naAccountPrivate0.accountPrivateEncrypt(naAccountPublic1, vucTextSrc);
|
||||
std::vector<unsigned char> vucTextRecovered
|
||||
Blob vucTextRecovered
|
||||
= naAccountPrivate1.accountPrivateDecrypt(naAccountPublic0, vucTextCipher);
|
||||
|
||||
BOOST_CHECK_MESSAGE(vucTextSrc == vucTextRecovered, "Encrypt-decrypt failed.");
|
||||
|
||||
@@ -36,31 +36,31 @@ public:
|
||||
// Node Public - Also used for Validators
|
||||
//
|
||||
uint160 getNodeID() const;
|
||||
const std::vector<unsigned char>& getNodePublic() const;
|
||||
Blob const& getNodePublic() const;
|
||||
|
||||
std::string humanNodePublic() const;
|
||||
|
||||
bool setNodePublic(const std::string& strPublic);
|
||||
void setNodePublic(const std::vector<unsigned char>& vPublic);
|
||||
bool verifyNodePublic(const uint256& hash, const std::vector<unsigned char>& vchSig) const;
|
||||
void setNodePublic(Blob const& vPublic);
|
||||
bool verifyNodePublic(const uint256& hash, Blob const& vchSig) const;
|
||||
bool verifyNodePublic(const uint256& hash, const std::string& strSig) const;
|
||||
|
||||
static RippleAddress createNodePublic(const RippleAddress& naSeed);
|
||||
static RippleAddress createNodePublic(const std::vector<unsigned char>& vPublic);
|
||||
static RippleAddress createNodePublic(Blob const& vPublic);
|
||||
static RippleAddress createNodePublic(const std::string& strPublic);
|
||||
|
||||
//
|
||||
// Node Private
|
||||
//
|
||||
const std::vector<unsigned char>& getNodePrivateData() const;
|
||||
Blob const& getNodePrivateData() const;
|
||||
uint256 getNodePrivate() const;
|
||||
|
||||
std::string humanNodePrivate() const;
|
||||
|
||||
bool setNodePrivate(const std::string& strPrivate);
|
||||
void setNodePrivate(const std::vector<unsigned char>& vPrivate);
|
||||
void setNodePrivate(Blob const& vPrivate);
|
||||
void setNodePrivate(uint256 hash256);
|
||||
void signNodePrivate(const uint256& hash, std::vector<unsigned char>& vchSig) const;
|
||||
void signNodePrivate(const uint256& hash, Blob & vchSig) const;
|
||||
|
||||
static RippleAddress createNodePrivate(const RippleAddress& naSeed);
|
||||
|
||||
@@ -82,23 +82,23 @@ public:
|
||||
static std::string createHumanAccountID(const uint160& uiAccountID)
|
||||
{ return createAccountID(uiAccountID).humanAccountID(); }
|
||||
|
||||
static std::string createHumanAccountID(const std::vector<unsigned char>& vPrivate)
|
||||
static std::string createHumanAccountID(Blob const& vPrivate)
|
||||
{ return createAccountPrivate(vPrivate).humanAccountID(); }
|
||||
|
||||
//
|
||||
// Accounts Public
|
||||
//
|
||||
const std::vector<unsigned char>& getAccountPublic() const;
|
||||
Blob const& getAccountPublic() const;
|
||||
|
||||
std::string humanAccountPublic() const;
|
||||
|
||||
bool setAccountPublic(const std::string& strPublic);
|
||||
void setAccountPublic(const std::vector<unsigned char>& vPublic);
|
||||
void setAccountPublic(Blob const& vPublic);
|
||||
void setAccountPublic(const RippleAddress& generator, int seq);
|
||||
|
||||
bool accountPublicVerify(const uint256& uHash, const std::vector<unsigned char>& vucSig) const;
|
||||
bool accountPublicVerify(const uint256& uHash, Blob const& vucSig) const;
|
||||
|
||||
static RippleAddress createAccountPublic(const std::vector<unsigned char>& vPublic)
|
||||
static RippleAddress createAccountPublic(Blob const& vPublic)
|
||||
{
|
||||
RippleAddress naNew;
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
return naNew;
|
||||
}
|
||||
|
||||
static std::string createHumanAccountPublic(const std::vector<unsigned char>& vPublic) {
|
||||
static std::string createHumanAccountPublic(Blob const& vPublic) {
|
||||
return createAccountPublic(vPublic).humanAccountPublic();
|
||||
}
|
||||
|
||||
@@ -122,22 +122,22 @@ public:
|
||||
std::string humanAccountPrivate() const;
|
||||
|
||||
bool setAccountPrivate(const std::string& strPrivate);
|
||||
void setAccountPrivate(const std::vector<unsigned char>& vPrivate);
|
||||
void setAccountPrivate(Blob const& vPrivate);
|
||||
void setAccountPrivate(uint256 hash256);
|
||||
void setAccountPrivate(const RippleAddress& naGenerator, const RippleAddress& naSeed, int seq);
|
||||
|
||||
bool accountPrivateSign(const uint256& uHash, std::vector<unsigned char>& vucSig) const;
|
||||
// bool accountPrivateVerify(const uint256& uHash, const std::vector<unsigned char>& vucSig) const;
|
||||
bool accountPrivateSign(const uint256& uHash, Blob & vucSig) const;
|
||||
// bool accountPrivateVerify(const uint256& uHash, Blob const& vucSig) const;
|
||||
|
||||
// Encrypt a message.
|
||||
std::vector<unsigned char> accountPrivateEncrypt(const RippleAddress& naPublicTo, const std::vector<unsigned char>& vucPlainText) const;
|
||||
Blob accountPrivateEncrypt(const RippleAddress& naPublicTo, Blob const& vucPlainText) const;
|
||||
|
||||
// Decrypt a message.
|
||||
std::vector<unsigned char> accountPrivateDecrypt(const RippleAddress& naPublicFrom, const std::vector<unsigned char>& vucCipherText) const;
|
||||
Blob accountPrivateDecrypt(const RippleAddress& naPublicFrom, Blob const& vucCipherText) const;
|
||||
|
||||
static RippleAddress createAccountPrivate(const RippleAddress& naGenerator, const RippleAddress& naSeed, int iSeq);
|
||||
|
||||
static RippleAddress createAccountPrivate(const std::vector<unsigned char>& vPrivate)
|
||||
static RippleAddress createAccountPrivate(Blob const& vPrivate)
|
||||
{
|
||||
RippleAddress naNew;
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
return naNew;
|
||||
}
|
||||
|
||||
static std::string createHumanAccountPrivate(const std::vector<unsigned char>& vPrivate) {
|
||||
static std::string createHumanAccountPrivate(Blob const& vPrivate) {
|
||||
return createAccountPrivate(vPrivate).humanAccountPrivate();
|
||||
}
|
||||
|
||||
@@ -155,12 +155,12 @@ public:
|
||||
// Use to generate a master or regular family.
|
||||
//
|
||||
BIGNUM* getGeneratorBN() const; // DEPRECATED
|
||||
const std::vector<unsigned char>& getGenerator() const;
|
||||
Blob const& getGenerator() const;
|
||||
|
||||
std::string humanGenerator() const;
|
||||
|
||||
bool setGenerator(const std::string& strGenerator);
|
||||
void setGenerator(const std::vector<unsigned char>& vPublic);
|
||||
void setGenerator(Blob const& vPublic);
|
||||
// void setGenerator(const RippleAddress& seed);
|
||||
|
||||
// Create generator for making public deterministic keys.
|
||||
|
||||
@@ -39,7 +39,7 @@ bool STAmount::currencyFromString(uint160& uDstCurrency, const std::string& sCur
|
||||
}
|
||||
else if (3 == sCurrency.size())
|
||||
{
|
||||
std::vector<unsigned char> vucIso(3);
|
||||
Blob vucIso(3);
|
||||
|
||||
std::transform(sCurrency.begin(), sCurrency.end(), vucIso.begin(), ::toupper);
|
||||
|
||||
@@ -216,10 +216,10 @@ std::string STAmount::createHumanCurrency(const uint160& uCurrency)
|
||||
|
||||
SerializerIterator sit(s);
|
||||
|
||||
std::vector<unsigned char> vucZeros = sit.getRaw(96/8);
|
||||
std::vector<unsigned char> vucIso = sit.getRaw(24/8);
|
||||
std::vector<unsigned char> vucVersion = sit.getRaw(16/8);
|
||||
std::vector<unsigned char> vucReserved = sit.getRaw(24/8);
|
||||
Blob vucZeros = sit.getRaw(96/8);
|
||||
Blob vucIso = sit.getRaw(24/8);
|
||||
Blob vucVersion = sit.getRaw(16/8);
|
||||
Blob vucReserved = sit.getRaw(24/8);
|
||||
|
||||
bool bIso = ::isZero(vucZeros.begin(), vucZeros.size()) // Leading zeros
|
||||
&& ::isZero(vucVersion.begin(), vucVersion.size()) // Zero version
|
||||
|
||||
@@ -599,12 +599,12 @@ uint160 STObject::getFieldAccount160(SField::ref field) const
|
||||
return a;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> STObject::getFieldVL(SField::ref field) const
|
||||
Blob STObject::getFieldVL(SField::ref field) const
|
||||
{
|
||||
const SerializedType* rf = peekAtPField(field);
|
||||
if (!rf) throw std::runtime_error("Field not found");
|
||||
SerializedTypeID id = rf->getSType();
|
||||
if (id == STI_NOTPRESENT) return std::vector<unsigned char>(); // optional field not present
|
||||
if (id == STI_NOTPRESENT) return Blob (); // optional field not present
|
||||
const STVariableLength *cf = dynamic_cast<const STVariableLength *>(rf);
|
||||
if (!cf) throw std::runtime_error("Wrong field type");
|
||||
return cf->getValue();
|
||||
@@ -739,7 +739,7 @@ void STObject::setFieldAccount(SField::ref field, const uint160& v)
|
||||
cf->setValueH160(v);
|
||||
}
|
||||
|
||||
void STObject::setFieldVL(SField::ref field, const std::vector<unsigned char>& v)
|
||||
void STObject::setFieldVL(SField::ref field, Blob const& v)
|
||||
{
|
||||
SerializedType* rf = getPField(field, true);
|
||||
if (!rf) throw std::runtime_error("Field not found");
|
||||
@@ -1267,7 +1267,7 @@ BOOST_AUTO_TEST_CASE( FieldManipulation_test )
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
std::vector<unsigned char> j(i, 2);
|
||||
Blob j(i, 2);
|
||||
|
||||
object1.setFieldVL(sfTestVL, j);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
uint256 getFieldH256(SField::ref field) const;
|
||||
RippleAddress getFieldAccount(SField::ref field) const;
|
||||
uint160 getFieldAccount160(SField::ref field) const;
|
||||
std::vector<unsigned char> getFieldVL(SField::ref field) const;
|
||||
Blob getFieldVL(SField::ref field) const;
|
||||
const STAmount& getFieldAmount(SField::ref field) const;
|
||||
const STPathSet& getFieldPathSet(SField::ref field) const;
|
||||
const STVector256& getFieldV256(SField::ref field) const;
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
void setFieldH128(SField::ref field, const uint128&);
|
||||
void setFieldH160(SField::ref field, const uint160&);
|
||||
void setFieldH256(SField::ref field, const uint256&);
|
||||
void setFieldVL(SField::ref field, const std::vector<unsigned char>&);
|
||||
void setFieldVL(SField::ref field, Blob const&);
|
||||
void setFieldAccount(SField::ref field, const uint160&);
|
||||
void setFieldAccount(SField::ref field, const RippleAddress& addr)
|
||||
{ setFieldAccount(field, addr.getAccountID()); }
|
||||
|
||||
@@ -269,8 +269,8 @@ STAccount* STAccount::construct(SerializerIterator& u, SField::ref name)
|
||||
// Return a new object from a SerializerIterator.
|
||||
STVector256* STVector256::construct(SerializerIterator& u, SField::ref name)
|
||||
{
|
||||
std::vector<unsigned char> data = u.getVL();
|
||||
std::vector<unsigned char>::iterator begin = data.begin();
|
||||
Blob data = u.getVL();
|
||||
Blob ::iterator begin = data.begin();
|
||||
|
||||
UPTR_T<STVector256> vec(new STVector256(name));
|
||||
|
||||
@@ -283,7 +283,7 @@ STVector256* STVector256::construct(SerializerIterator& u, SField::ref name)
|
||||
unsigned int uEnd = uStart + (256 / 8);
|
||||
|
||||
// This next line could be optimized to construct a default uint256 in the vector and then copy into it
|
||||
vec->mValue.push_back(uint256(std::vector<unsigned char>(begin + uStart, begin + uEnd)));
|
||||
vec->mValue.push_back(uint256(Blob (begin + uStart, begin + uEnd)));
|
||||
uStart = uEnd;
|
||||
}
|
||||
|
||||
|
||||
@@ -574,8 +574,8 @@ private:
|
||||
class STVariableLength : public SerializedType
|
||||
{
|
||||
public:
|
||||
STVariableLength(const std::vector<unsigned char>& v) : value(v) { ; }
|
||||
STVariableLength(SField::ref n, const std::vector<unsigned char>& v) : SerializedType(n), value(v) { ; }
|
||||
STVariableLength(Blob const& v) : value(v) { ; }
|
||||
STVariableLength(SField::ref n, Blob const& v) : SerializedType(n), value(v) { ; }
|
||||
STVariableLength(SField::ref n) : SerializedType(n) { ; }
|
||||
STVariableLength(SerializerIterator&, SField::ref name = sfGeneric);
|
||||
STVariableLength() { ; }
|
||||
@@ -586,17 +586,17 @@ public:
|
||||
virtual std::string getText() const;
|
||||
void add(Serializer& s) const { s.addVL(value); }
|
||||
|
||||
const std::vector<unsigned char>& peekValue() const { return value; }
|
||||
std::vector<unsigned char>& peekValue() { return value; }
|
||||
std::vector<unsigned char> getValue() const { return value; }
|
||||
void setValue(const std::vector<unsigned char>& v) { value=v; }
|
||||
Blob const& peekValue() const { return value; }
|
||||
Blob & peekValue() { return value; }
|
||||
Blob getValue() const { return value; }
|
||||
void setValue(Blob const& v) { value=v; }
|
||||
|
||||
operator std::vector<unsigned char>() const { return value; }
|
||||
operator Blob () const { return value; }
|
||||
virtual bool isEquivalent(const SerializedType& t) const;
|
||||
virtual bool isDefault() const { return value.empty(); }
|
||||
|
||||
private:
|
||||
std::vector<unsigned char> value;
|
||||
Blob value;
|
||||
|
||||
virtual STVariableLength* duplicate() const { return new STVariableLength(*this); }
|
||||
static STVariableLength* construct(SerializerIterator&, SField::ref);
|
||||
@@ -605,8 +605,8 @@ private:
|
||||
class STAccount : public STVariableLength
|
||||
{
|
||||
public:
|
||||
STAccount(const std::vector<unsigned char>& v) : STVariableLength(v) { ; }
|
||||
STAccount(SField::ref n, const std::vector<unsigned char>& v) : STVariableLength(n, v) { ; }
|
||||
STAccount(Blob const& v) : STVariableLength(v) { ; }
|
||||
STAccount(SField::ref n, Blob const& v) : STVariableLength(n, v) { ; }
|
||||
STAccount(SField::ref n, const uint160& v);
|
||||
STAccount(SField::ref n) : STVariableLength(n) { ; }
|
||||
STAccount() { ; }
|
||||
|
||||
@@ -64,7 +64,7 @@ int Serializer::add256(const uint256& i)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Serializer::addRaw(const std::vector<unsigned char> &vector)
|
||||
int Serializer::addRaw(Blob const& vector)
|
||||
{
|
||||
int ret = mData.size();
|
||||
mData.insert(mData.end(), vector.begin(), vector.end());
|
||||
@@ -239,16 +239,16 @@ int Serializer::removeLastByte()
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Serializer::getRaw(std::vector<unsigned char>& o, int offset, int length) const
|
||||
bool Serializer::getRaw(Blob & o, int offset, int length) const
|
||||
{
|
||||
if ((offset + length) > mData.size()) return false;
|
||||
o.assign(mData.begin() + offset, mData.begin() + offset + length);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> Serializer::getRaw(int offset, int length) const
|
||||
Blob Serializer::getRaw(int offset, int length) const
|
||||
{
|
||||
std::vector<unsigned char> o;
|
||||
Blob o;
|
||||
if ((offset + length) > mData.size()) return o;
|
||||
o.assign(mData.begin() + offset, mData.begin() + offset + length);
|
||||
return o;
|
||||
@@ -275,7 +275,7 @@ uint256 Serializer::getSHA512Half(int size) const
|
||||
return getSHA512Half(mData, size);
|
||||
}
|
||||
|
||||
uint256 Serializer::getSHA512Half(const std::vector<unsigned char>& data, int size)
|
||||
uint256 Serializer::getSHA512Half(Blob const& data, int size)
|
||||
{
|
||||
uint256 j[2];
|
||||
if ((size < 0) || (size > data.size())) size = data.size();
|
||||
@@ -315,7 +315,7 @@ uint256 Serializer::getPrefixHash(uint32 prefix, const unsigned char *data, int
|
||||
|
||||
bool Serializer::checkSignature(int pubkeyOffset, int signatureOffset) const
|
||||
{
|
||||
std::vector<unsigned char> pubkey, signature;
|
||||
Blob pubkey, signature;
|
||||
if (!getRaw(pubkey, pubkeyOffset, 65)) return false;
|
||||
if (!getRaw(signature, signatureOffset, 72)) return false;
|
||||
|
||||
@@ -324,26 +324,26 @@ bool Serializer::checkSignature(int pubkeyOffset, int signatureOffset) const
|
||||
return pubCKey.Verify(getSHA512Half(signatureOffset), signature);
|
||||
}
|
||||
|
||||
bool Serializer::checkSignature(const std::vector<unsigned char> &signature, CKey& key) const
|
||||
bool Serializer::checkSignature(Blob const& signature, CKey& key) const
|
||||
{
|
||||
return key.Verify(getSHA512Half(), signature);
|
||||
}
|
||||
|
||||
bool Serializer::makeSignature(std::vector<unsigned char> &signature, CKey& key) const
|
||||
bool Serializer::makeSignature(Blob &signature, CKey& key) const
|
||||
{
|
||||
return key.Sign(getSHA512Half(), signature);
|
||||
}
|
||||
|
||||
bool Serializer::addSignature(CKey& key)
|
||||
{
|
||||
std::vector<unsigned char> signature;
|
||||
Blob signature;
|
||||
if (!key.Sign(getSHA512Half(), signature)) return false;
|
||||
assert(signature.size() == 72);
|
||||
addRaw(signature);
|
||||
return true;
|
||||
}
|
||||
|
||||
int Serializer::addVL(const std::vector<unsigned char>& vector)
|
||||
int Serializer::addVL(Blob const& vector)
|
||||
{
|
||||
int ret = addRaw(encodeVL(vector.size()));
|
||||
addRaw(vector);
|
||||
@@ -367,7 +367,7 @@ int Serializer::addVL(const std::string& string)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Serializer::getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const
|
||||
bool Serializer::getVL(Blob & objectVL, int offset, int& length) const
|
||||
{
|
||||
int b1;
|
||||
if (!get8(b1, offset++)) return false;
|
||||
@@ -432,20 +432,20 @@ bool Serializer::getVLLength(int& length, int offset) const
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> Serializer::encodeVL(int length)
|
||||
Blob Serializer::encodeVL(int length)
|
||||
{
|
||||
unsigned char lenBytes[4];
|
||||
if (length <= 192)
|
||||
{
|
||||
lenBytes[0] = static_cast<unsigned char>(length);
|
||||
return std::vector<unsigned char>(&lenBytes[0], &lenBytes[1]);
|
||||
return Blob (&lenBytes[0], &lenBytes[1]);
|
||||
}
|
||||
else if (length <= 12480)
|
||||
{
|
||||
length -= 193;
|
||||
lenBytes[0] = 193 + static_cast<unsigned char>(length >> 8);
|
||||
lenBytes[1] = static_cast<unsigned char>(length & 0xff);
|
||||
return std::vector<unsigned char>(&lenBytes[0], &lenBytes[2]);
|
||||
return Blob (&lenBytes[0], &lenBytes[2]);
|
||||
}
|
||||
else if (length <= 918744)
|
||||
{
|
||||
@@ -453,7 +453,7 @@ std::vector<unsigned char> Serializer::encodeVL(int length)
|
||||
lenBytes[0] = 241 + static_cast<unsigned char>(length >> 16);
|
||||
lenBytes[1] = static_cast<unsigned char>((length >> 8) & 0xff);
|
||||
lenBytes[2] = static_cast<unsigned char>(length & 0xff);
|
||||
return std::vector<unsigned char>(&lenBytes[0], &lenBytes[3]);
|
||||
return Blob (&lenBytes[0], &lenBytes[3]);
|
||||
}
|
||||
else throw std::overflow_error("lenlen");
|
||||
}
|
||||
@@ -574,16 +574,16 @@ uint256 SerializerIterator::get256()
|
||||
return val;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> SerializerIterator::getVL()
|
||||
Blob SerializerIterator::getVL()
|
||||
{
|
||||
int length;
|
||||
std::vector<unsigned char> vl;
|
||||
Blob vl;
|
||||
if (!mSerializer.getVL(vl, mPos, length)) throw std::runtime_error("invalid serializer getVL");
|
||||
mPos += length;
|
||||
return vl;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> SerializerIterator::getRaw(int iLength)
|
||||
Blob SerializerIterator::getRaw(int iLength)
|
||||
{
|
||||
int iPos = mPos;
|
||||
mPos += iLength;
|
||||
|
||||
@@ -9,15 +9,15 @@ public:
|
||||
typedef boost::shared_ptr<Serializer> pointer;
|
||||
|
||||
protected:
|
||||
std::vector<unsigned char> mData;
|
||||
Blob mData;
|
||||
|
||||
public:
|
||||
Serializer(int n = 256) { mData.reserve(n); }
|
||||
Serializer(const std::vector<unsigned char> &data) : mData(data) { ; }
|
||||
Serializer(Blob const& data) : mData(data) { ; }
|
||||
Serializer(const std::string& data) : mData(data.data(), (data.data()) + data.size()) { ; }
|
||||
Serializer(std::vector<unsigned char>::iterator begin, std::vector<unsigned char>::iterator end) :
|
||||
Serializer(Blob ::iterator begin, Blob ::iterator end) :
|
||||
mData(begin, end) { ; }
|
||||
Serializer(std::vector<unsigned char>::const_iterator begin, std::vector<unsigned char>::const_iterator end) :
|
||||
Serializer(Blob ::const_iterator begin, Blob ::const_iterator end) :
|
||||
mData(begin, end) { ; }
|
||||
|
||||
// assemble functions
|
||||
@@ -28,12 +28,12 @@ public:
|
||||
int add128(const uint128&); // private key generators
|
||||
int add160(const uint160&); // account names, hankos
|
||||
int add256(const uint256&); // transaction and ledger hashes
|
||||
int addRaw(const std::vector<unsigned char> &vector);
|
||||
int addRaw(Blob const& vector);
|
||||
int addRaw(const void *ptr, int len);
|
||||
int addRaw(const Serializer& s);
|
||||
int addZeros(size_t uBytes);
|
||||
|
||||
int addVL(const std::vector<unsigned char> &vector);
|
||||
int addVL(Blob const& vector);
|
||||
int addVL(const std::string& string);
|
||||
int addVL(const void *ptr, int len);
|
||||
|
||||
@@ -47,10 +47,10 @@ public:
|
||||
bool get160(uint160&, int offset) const;
|
||||
bool get256(uint256&, int offset) const;
|
||||
uint256 get256(int offset) const;
|
||||
bool getRaw(std::vector<unsigned char>&, int offset, int length) const;
|
||||
std::vector<unsigned char> getRaw(int offset, int length) const;
|
||||
bool getRaw(Blob &, int offset, int length) const;
|
||||
Blob getRaw(int offset, int length) const;
|
||||
|
||||
bool getVL(std::vector<unsigned char>& objectVL, int offset, int& length) const;
|
||||
bool getVL(Blob & objectVL, int offset, int& length) const;
|
||||
bool getVLLength(int& length, int offset) const;
|
||||
|
||||
bool getFieldID(int& type, int& name, int offset) const;
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
uint160 getRIPEMD160(int size=-1) const;
|
||||
uint256 getSHA256(int size=-1) const;
|
||||
uint256 getSHA512Half(int size=-1) const;
|
||||
static uint256 getSHA512Half(const std::vector<unsigned char>& data, int size=-1);
|
||||
static uint256 getSHA512Half(Blob const& data, int size=-1);
|
||||
static uint256 getSHA512Half(const unsigned char *data, int len);
|
||||
static uint256 getSHA512Half(const std::string& strData);
|
||||
|
||||
@@ -69,15 +69,15 @@ public:
|
||||
static uint256 getPrefixHash(uint32 prefix, const unsigned char *data, int len);
|
||||
uint256 getPrefixHash(uint32 prefix) const
|
||||
{ return getPrefixHash(prefix, &(mData.front()), mData.size()); }
|
||||
static uint256 getPrefixHash(uint32 prefix, const std::vector<unsigned char>& data)
|
||||
static uint256 getPrefixHash(uint32 prefix, Blob const& data)
|
||||
{ return getPrefixHash(prefix, &(data.front()), data.size()); }
|
||||
static uint256 getPrefixHash(uint32 prefix, const std::string& strData)
|
||||
{ return getPrefixHash(prefix, reinterpret_cast<const unsigned char *>(strData.data()), strData.size()); }
|
||||
|
||||
// totality functions
|
||||
const std::vector<unsigned char>& peekData() const { return mData; }
|
||||
std::vector<unsigned char> getData() const { return mData; }
|
||||
std::vector<unsigned char>& modData() { return mData; }
|
||||
Blob const& peekData() const { return mData; }
|
||||
Blob getData() const { return mData; }
|
||||
Blob & modData() { return mData; }
|
||||
int getCapacity() const { return mData.capacity(); }
|
||||
int getDataLength() const { return mData.size(); }
|
||||
const void* getDataPtr() const { return &mData.front(); }
|
||||
@@ -90,28 +90,28 @@ public:
|
||||
bool chop(int num);
|
||||
|
||||
// vector-like functions
|
||||
std::vector<unsigned char>::iterator begin() { return mData.begin(); }
|
||||
std::vector<unsigned char>::iterator end() { return mData.end(); }
|
||||
std::vector<unsigned char>::const_iterator begin() const { return mData.begin(); }
|
||||
std::vector<unsigned char>::const_iterator end() const { return mData.end(); }
|
||||
std::vector<unsigned char>::size_type size() const { return mData.size(); }
|
||||
Blob ::iterator begin() { return mData.begin(); }
|
||||
Blob ::iterator end() { return mData.end(); }
|
||||
Blob ::const_iterator begin() const { return mData.begin(); }
|
||||
Blob ::const_iterator end() const { return mData.end(); }
|
||||
Blob ::size_type size() const { return mData.size(); }
|
||||
void reserve(size_t n) { mData.reserve(n); }
|
||||
void resize(size_t n) { mData.resize(n); }
|
||||
size_t capacity() const { return mData.capacity(); }
|
||||
|
||||
bool operator==(const std::vector<unsigned char>& v) { return v == mData; }
|
||||
bool operator!=(const std::vector<unsigned char>& v) { return v != mData; }
|
||||
bool operator==(Blob const& v) { return v == mData; }
|
||||
bool operator!=(Blob const& v) { return v != mData; }
|
||||
bool operator==(const Serializer& v) { return v.mData == mData; }
|
||||
bool operator!=(const Serializer& v) { return v.mData != mData; }
|
||||
|
||||
// signature functions
|
||||
bool checkSignature(int pubkeyOffset, int signatureOffset) const;
|
||||
bool checkSignature(const std::vector<unsigned char>& signature, CKey& rkey) const;
|
||||
bool makeSignature(std::vector<unsigned char>& signature, CKey& rkey) const;
|
||||
bool checkSignature(Blob const& signature, CKey& rkey) const;
|
||||
bool makeSignature(Blob & signature, CKey& rkey) const;
|
||||
bool addSignature(CKey& rkey);
|
||||
|
||||
// low-level VL length encode/decode functions
|
||||
static std::vector<unsigned char> encodeVL(int length);
|
||||
static Blob encodeVL(int length);
|
||||
static int lengthVL(int length) { return length + encodeLengthLength(length); }
|
||||
static int encodeLengthLength(int length); // length to encode length
|
||||
static int decodeLengthLength(int b1);
|
||||
@@ -152,9 +152,9 @@ public:
|
||||
|
||||
void getFieldID(int& type, int& field);
|
||||
|
||||
std::vector<unsigned char> getRaw(int iLength);
|
||||
Blob getRaw(int iLength);
|
||||
|
||||
std::vector<unsigned char> getVL();
|
||||
Blob getVL();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user