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

@@ -0,0 +1,51 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/Sign.h>
namespace ripple {
void
sign (STObject& st, HashPrefix const& prefix,
AnySecretKey const& sk)
{
Serializer ss;
ss.add32(prefix);
st.add(ss, false);
set(st, sfSignature,
sk.sign(ss.data(), ss.size()));
}
bool
verify (STObject const& st,
HashPrefix const& prefix,
AnyPublicKeySlice const& pk)
{
auto const sig = get(st, sfSignature);
if (! sig)
return false;
Serializer ss;
ss.add32(prefix);
st.add(ss, false);
return pk.verify(
ss.data(), ss.size(),
sig->data(), sig->size());
}
} // ripple