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:
Vinnie Falco
2015-02-19 18:00:05 -08:00
committed by Tom Ritchford
parent 79ce4ed226
commit a2acffdfa3
20 changed files with 1277 additions and 65 deletions

View File

@@ -20,7 +20,10 @@
#ifndef RIPPLE_PROTOCOL_STBLOB_H_INCLUDED
#define RIPPLE_PROTOCOL_STBLOB_H_INCLUDED
#include <ripple/basics/Buffer.h>
#include <ripple/basics/Slice.h>
#include <ripple/protocol/STBase.h>
#include <cstring>
#include <memory>
namespace ripple {
@@ -30,19 +33,58 @@ class STBlob
: public STBase
{
public:
using value_type = Slice;
STBlob () = default;
/** Construct with size and initializer.
Init will be called as:
void(void* data, std::size_t size)
*/
template <class Init>
STBlob (SField::ref f, std::size_t size,
Init&& init)
: STBase(f)
{
value.resize(size);
init(value.data(), value.size());
}
STBlob (SField::ref f,
void const* data, std::size_t size)
: STBase(f)
{
value.resize(size);
std::memcpy(value.data(), data, size);
}
STBlob (SField const& f, Buffer&& b)
: STBase(f)
{
// VFALCO TODO Really move the buffer
value.resize(b.size());
std::memcpy(value.data(),
b.data(), b.size());
auto tmp = std::move(b);
}
// VFALCO DEPRECATED
STBlob (Blob const& v)
: value (v)
{ }
{
}
// VFALCO DEPRECATED
STBlob (SField::ref n, Blob const& v)
: STBase (n), value (v)
{ }
: STBase (n)
, value (v)
{
}
STBlob (SField::ref n)
: STBase (n)
{ }
{
}
STBlob (SerialIter&, SField::ref name = sfGeneric);
@@ -53,6 +95,19 @@ public:
return std::make_unique<STBlob> (name, sit.getVL ());
}
std::size_t
size() const
{
return value.size();
}
std::uint8_t const*
data() const
{
return reinterpret_cast<
std::uint8_t const*>(value.data());
}
SerializedTypeID
getSType () const override
{
@@ -95,6 +150,13 @@ public:
value = v;
}
void
setValue (void const* data, std::size_t size)
{
value.resize(size);
std::memcpy(value.data(), data, size);
}
explicit
operator Blob () const
{