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