Add ripple::byte_view, ripple::const_byte_view

This commit is contained in:
Vinnie Falco
2014-03-12 01:04:47 -07:00
parent f66aee4e7f
commit 3674b01634
4 changed files with 56 additions and 16 deletions

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
/*
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.
*/
//==============================================================================
#ifndef RIPPLE_BYTE_VIEW_H_INCLUDED
#define RIPPLE_BYTE_VIEW_H_INCLUDED
#include "../../beast/beast/container/buffer_view.h"
#include <cstdint>
namespace ripple {
typedef beast::buffer_view <std::uint8_t> byte_view;
typedef beast::buffer_view <std::uint8_t const> const_byte_view;
}
#endif

View File

@@ -337,16 +337,21 @@ uint256 Serializer::getSHA256 (int size) const
uint256 Serializer::getSHA512Half (int size) const
{
return getSHA512Half (mData, size);
assert (size != 0);
if (size == 0)
return uint256();
if (size < 0 || size > mData.size())
return getSHA512Half (mData);
return getSHA512Half (const_byte_view (
mData.data(), mData.data() + size));
}
uint256 Serializer::getSHA512Half (Blob const& data, int size)
uint256 Serializer::getSHA512Half (const_byte_view v)
{
uint256 j[2];
if ((size < 0) || (size > data.size ())) size = data.size ();
SHA512 (& (data.front ()), size, (unsigned char*) j);
SHA512 (v.data(), v.size(),
reinterpret_cast<unsigned char*> (j));
return j[0];
}
@@ -357,11 +362,6 @@ uint256 Serializer::getSHA512Half (const unsigned char* data, int len)
return j[0];
}
uint256 Serializer::getSHA512Half (const std::string& strData)
{
return getSHA512Half (reinterpret_cast<const unsigned char*> (strData.data ()), strData.size ());
}
uint256 Serializer::getPrefixHash (uint32 prefix, const unsigned char* data, int len)
{
char be_prefix[4];

View File

@@ -20,6 +20,10 @@
#ifndef RIPPLE_SERIALIZER_H
#define RIPPLE_SERIALIZER_H
#include "../../ripple/common/byte_view.h"
namespace ripple {
class CKey; // forward declaration
class Serializer
@@ -98,9 +102,9 @@ public:
uint160 getRIPEMD160 (int size = -1) const;
uint256 getSHA256 (int size = -1) const;
uint256 getSHA512Half (int size = -1) const;
static uint256 getSHA512Half (Blob const& data, int size = -1);
static uint256 getSHA512Half (const_byte_view v);
static uint256 getSHA512Half (const unsigned char* data, int len);
static uint256 getSHA512Half (const std::string& strData);
// prefix hash functions
static uint256 getPrefixHash (uint32 prefix, const unsigned char* data, int len);
@@ -294,5 +298,7 @@ public:
Blob getVL ();
};
}
#endif
// vim:ts=4

View File

@@ -28,17 +28,17 @@ struct bignum_st;
typedef struct bignum_st BIGNUM;
namespace ripple {
#include "crypto/Base58Data.h"
#include "crypto/RFC1751.h"
#include "protocol/BuildInfo.h"
#include "protocol/FieldNames.h"
#include "protocol/HashPrefix.h"
#include "protocol/Protocol.h"
#include "protocol/RippleAddress.h"
#include "protocol/RippleSystem.h"
}
#include "protocol/Serializer.h" // needs CKey
namespace ripple {
#include "protocol/TER.h"
#include "protocol/SerializedTypes.h" // needs Serializer, TER
#include "protocol/SerializedObjectTemplate.h"