mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
New serialized object, public key, and private key interfaces
This introduces functions get and set, and a family of specialized structs called STExchange. These interfaces allow efficient and seamless interchange between serialized object fields and user defined types, especially variable length objects. A new base class template TypedField is mixed into existing SField declarations to encode information on the field, allowing template metaprograms to both customize interchange based on the type and detect misuse at compile-time. New types AnyPublicKey and AnySecretKey are introduced. These are intended to replace the corresponding functionality in the deprecated class RippleAddress. Specializations of STExchange for these types are provided to allow interchange. New free functions verify and sign allow signature verification and signature generation for serialized objects. * Add Buffer and Slice primitives * Add TypedField and modify some SField * Add STExchange and specializations for STBlob and STInteger * Improve STBlob and STInteger to support STExchange * Expose raw data in RippleAddress and Serializer
This commit is contained in:
committed by
Tom Ritchford
parent
79ce4ed226
commit
a2acffdfa3
@@ -22,9 +22,16 @@
|
||||
|
||||
#include <ripple/basics/BasicTypes.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// Forwards
|
||||
class STBlob;
|
||||
template <class>
|
||||
class STInteger;
|
||||
|
||||
enum SerializedTypeID
|
||||
{
|
||||
// special types
|
||||
@@ -139,7 +146,7 @@ public:
|
||||
{}
|
||||
#endif
|
||||
|
||||
private:
|
||||
protected:
|
||||
// These constructors can only be called from FieldNames.cpp
|
||||
SField (SerializedTypeID tid, int fv, const char* fn,
|
||||
int meta = sMD_Default, bool signing = true);
|
||||
@@ -253,6 +260,25 @@ private:
|
||||
static int num;
|
||||
};
|
||||
|
||||
/** A field with a type known at compile time. */
|
||||
template <class T>
|
||||
struct TypedField : SField
|
||||
{
|
||||
using type = T;
|
||||
|
||||
template <class... Args>
|
||||
explicit
|
||||
TypedField (Args&&... args)
|
||||
: SField(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
|
||||
TypedField (TypedField&& u)
|
||||
: SField(std::move(u))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
extern SField const sfInvalid;
|
||||
extern SField const sfGeneric;
|
||||
extern SField const sfLedgerEntry;
|
||||
@@ -272,7 +298,7 @@ extern SField const sfTransactionType;
|
||||
// 32-bit integers (common)
|
||||
extern SField const sfFlags;
|
||||
extern SField const sfSourceTag;
|
||||
extern SField const sfSequence;
|
||||
extern TypedField<STInteger<std::uint32_t>> const sfSequence;
|
||||
extern SField const sfPreviousTxnLgrSeq;
|
||||
extern SField const sfLedgerSequence;
|
||||
extern SField const sfCloseTime;
|
||||
@@ -359,12 +385,12 @@ extern SField const sfRippleEscrow;
|
||||
extern SField const sfDeliveredAmount;
|
||||
|
||||
// variable length
|
||||
extern SField const sfPublicKey;
|
||||
extern TypedField<STBlob> const sfPublicKey;
|
||||
extern SField const sfMessageKey;
|
||||
extern SField const sfSigningPubKey;
|
||||
extern TypedField<STBlob> const sfSigningPubKey;
|
||||
extern SField const sfTxnSignature;
|
||||
extern SField const sfGenerator;
|
||||
extern SField const sfSignature;
|
||||
extern TypedField<STBlob> const sfSignature;
|
||||
extern SField const sfDomain;
|
||||
extern SField const sfFundCode;
|
||||
extern SField const sfRemoveCode;
|
||||
@@ -413,6 +439,8 @@ extern SField const sfSufficient;
|
||||
extern SField const sfAffectedNodes;
|
||||
extern SField const sfMemos;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user