mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
Replace std::vector<unsigned char> with Blob
This commit is contained in:
@@ -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