Remove unused and obsolete Ripple identifiers and tidy up:

These identifiers were part of a failed set of classes to replace
the functionality combined into RippleAddress. They are not used
and therefore can be removed.

* Remove RippleAccountPrivateKey
* Remove RippleAccountPublicKey
* Remove RippleAccountID
* Remove RipplePrivateKey
* Remove RipplePublicKeyHash
* Remove RippleLedgerHash
* Remove unused withCheck argument
* Remove CryptoIdentifier
* Remove IdentifierStorage
* Remove IdentifierType
* Remove SimpleIdentifier
* Add missing include
This commit is contained in:
Vinnie Falco
2014-12-12 10:41:19 -08:00
parent 28b09bde4b
commit 409b8bac00
20 changed files with 9 additions and 1151 deletions

View File

@@ -3166,12 +3166,6 @@
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\ByteOrder.h"> <ClInclude Include="..\..\src\ripple\types\ByteOrder.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\CryptoIdentifier.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\IdentifierStorage.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\IdentifierType.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\types\impl\Base58.cpp"> <ClCompile Include="..\..\src\ripple\types\impl\Base58.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild> <ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile> </ClCompile>
@@ -3181,30 +3175,15 @@
<ClCompile Include="..\..\src\ripple\types\impl\Issue.cpp"> <ClCompile Include="..\..\src\ripple\types\impl\Issue.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild> <ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\types\impl\RippleIdentifierTests.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\types\impl\strHex.cpp"> <ClCompile Include="..\..\src\ripple\types\impl\strHex.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild> <ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\types\Issue.h"> <ClInclude Include="..\..\src\ripple\types\Issue.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleAccountID.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleAccountPrivateKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleAccountPublicKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleLedgerHash.h"> <ClInclude Include="..\..\src\ripple\types\RippleLedgerHash.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\RipplePrivateKey.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RipplePublicKey.h"> <ClInclude Include="..\..\src\ripple\types\RipplePublicKey.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\RipplePublicKeyHash.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\SimpleIdentifier.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\strHex.h"> <ClInclude Include="..\..\src\ripple\types\strHex.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\UInt160.h"> <ClInclude Include="..\..\src\ripple\types\UInt160.h">

View File

@@ -4308,15 +4308,6 @@
<ClInclude Include="..\..\src\ripple\types\ByteOrder.h"> <ClInclude Include="..\..\src\ripple\types\ByteOrder.h">
<Filter>ripple\types</Filter> <Filter>ripple\types</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\CryptoIdentifier.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\IdentifierStorage.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\IdentifierType.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\types\impl\Base58.cpp"> <ClCompile Include="..\..\src\ripple\types\impl\Base58.cpp">
<Filter>ripple\types\impl</Filter> <Filter>ripple\types\impl</Filter>
</ClCompile> </ClCompile>
@@ -4326,39 +4317,18 @@
<ClCompile Include="..\..\src\ripple\types\impl\Issue.cpp"> <ClCompile Include="..\..\src\ripple\types\impl\Issue.cpp">
<Filter>ripple\types\impl</Filter> <Filter>ripple\types\impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\ripple\types\impl\RippleIdentifierTests.cpp">
<Filter>ripple\types\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\types\impl\strHex.cpp"> <ClCompile Include="..\..\src\ripple\types\impl\strHex.cpp">
<Filter>ripple\types\impl</Filter> <Filter>ripple\types\impl</Filter>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\types\Issue.h"> <ClInclude Include="..\..\src\ripple\types\Issue.h">
<Filter>ripple\types</Filter> <Filter>ripple\types</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleAccountID.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleAccountPrivateKey.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleAccountPublicKey.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RippleLedgerHash.h"> <ClInclude Include="..\..\src\ripple\types\RippleLedgerHash.h">
<Filter>ripple\types</Filter> <Filter>ripple\types</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\RipplePrivateKey.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\RipplePublicKey.h"> <ClInclude Include="..\..\src\ripple\types\RipplePublicKey.h">
<Filter>ripple\types</Filter> <Filter>ripple\types</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\types\RipplePublicKeyHash.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\SimpleIdentifier.h">
<Filter>ripple\types</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\strHex.h"> <ClInclude Include="..\..\src\ripple\types\strHex.h">
<Filter>ripple\types</Filter> <Filter>ripple\types</Filter>
</ClInclude> </ClInclude>

View File

@@ -17,6 +17,7 @@
*/ */
//============================================================================== //==============================================================================
#include <beast/ByteOrder.h>
#include <algorithm> #include <algorithm>
namespace ripple { namespace ripple {

View File

@@ -25,11 +25,6 @@
#include <ripple/types/RipplePublicKey.h> #include <ripple/types/RipplePublicKey.h>
#include <ripple/types/UInt160.h> #include <ripple/types/UInt160.h>
#include <ripple/protocol/UintTypes.h> #include <ripple/protocol/UintTypes.h>
#include <ripple/types/RippleAccountID.h>
#include <ripple/types/RippleAccountPrivateKey.h>
#include <ripple/types/RippleAccountPublicKey.h>
#include <ripple/types/RipplePrivateKey.h>
#include <ripple/types/RipplePublicKeyHash.h>
namespace ripple { namespace ripple {
@@ -284,61 +279,6 @@ operator>=(RippleAddress const& lhs, RippleAddress const& rhs)
return !(lhs < rhs); return !(lhs < rhs);
} }
/** RipplePublicKeyHash */
template <>
struct RipplePublicKeyHashTraits::assign <RippleAddress>
{
void operator() (value_type& value, RippleAddress const& v) const
{
auto const ui (v.getNodeID ());
construct (ui.begin(), ui.end(), value);
}
};
/** RipplePrivateKey */
template <>
struct RipplePrivateKeyTraits::assign <RippleAddress>
{
void operator() (value_type& value, RippleAddress const& v) const
{
uint256 const ui (v.getNodePrivate ());
construct (ui.begin(), ui.end(), value);
}
};
/** RippleAccountID */
template <>
struct RippleAccountIDTraits::assign <RippleAddress>
{
void operator() (value_type& value, RippleAddress const& v) const
{
auto const ui (v.getAccountID ());
construct (ui.begin(), ui.end(), value);
}
};
/** RippleAccountPublicKey */
template <>
struct RippleAccountPublicKeyTraits::assign <RippleAddress>
{
void operator() (value_type& value, RippleAddress const& v) const
{
Blob const& b (v.getAccountPublic ());
construct (&b.front(), &b.back()+1, value);
}
};
/** RippleAccountPrivateKey */
template <>
struct RippleAccountPrivateKeyTraits::assign <RippleAddress>
{
void operator() (value_type& value, RippleAddress const& v) const
{
uint256 const ui (v.getAccountPrivate ());
construct (ui.begin(), ui.end(), value);
}
};
} // ripple } // ripple
#endif #endif

View File

@@ -981,47 +981,11 @@ public:
expect (publicKey.to_string() == deprecatedPublicKey.humanNodePublic(), expect (publicKey.to_string() == deprecatedPublicKey.humanNodePublic(),
publicKey.to_string()); publicKey.to_string());
testcase ("RipplePrivateKey");
RippleAddress deprecatedPrivateKey (RippleAddress::createNodePrivate (seed));
expect (deprecatedPrivateKey.humanNodePrivate () ==
"pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe",
deprecatedPrivateKey.humanNodePrivate ());
RipplePrivateKey privateKey (deprecatedPrivateKey);
expect (privateKey.to_string() == deprecatedPrivateKey.humanNodePrivate(),
privateKey.to_string());
testcase ("Generator"); testcase ("Generator");
RippleAddress generator (RippleAddress::createGeneratorPublic (seed)); RippleAddress generator (RippleAddress::createGeneratorPublic (seed));
expect (generator.humanGenerator () == expect (generator.humanGenerator () ==
"fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt", "fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt",
generator.humanGenerator ()); generator.humanGenerator ());
testcase ("RippleAccountID");
RippleAddress deprecatedAccountPublicKey (
RippleAddress::createAccountPublic (generator, 0));
expect (deprecatedAccountPublicKey.humanAccountID () ==
"rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
deprecatedAccountPublicKey.humanAccountID ());
RippleAccountID accountID (deprecatedAccountPublicKey);
expect (accountID.to_string() ==
deprecatedAccountPublicKey.humanAccountID(),
accountID.to_string());
testcase ("RippleAccountPublicKey");
expect (deprecatedAccountPublicKey.humanAccountPublic () ==
"aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw",
deprecatedAccountPublicKey.humanAccountPublic ());
testcase ("RippleAccountPrivateKey");
RippleAddress deprecatedAccountPrivateKey (
RippleAddress::createAccountPrivate (generator, seed, 0));
expect (deprecatedAccountPrivateKey.humanAccountPrivate () ==
"p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh",
deprecatedAccountPrivateKey.humanAccountPrivate ());
RippleAccountPrivateKey accountPrivateKey (deprecatedAccountPrivateKey);
expect (accountPrivateKey.to_string() ==
deprecatedAccountPrivateKey.humanAccountPrivate(),
privateKey.to_string());
} }
}; };

View File

@@ -87,9 +87,8 @@ public:
static Alphabet const& getBitcoinAlphabet (); static Alphabet const& getBitcoinAlphabet ();
static Alphabet const& getRippleAlphabet (); static Alphabet const& getRippleAlphabet ();
static std::string raw_encode ( static std::string raw_encode (unsigned char const* begin,
unsigned char const* begin, unsigned char const* end, unsigned char const* end, Alphabet const& alphabet);
Alphabet const& alphabet, bool withCheck);
static void fourbyte_hash256 (void* out, void const* in, std::size_t bytes); static void fourbyte_hash256 (void* out, void const* in, std::size_t bytes);
@@ -122,7 +121,7 @@ public:
std::back_inserter (v)); std::back_inserter (v));
// Pad zero to make the BIGNUM positive // Pad zero to make the BIGNUM positive
v.push_back (0); v.push_back (0);
return raw_encode (&v.front(), &v.back()+1, alphabet, withCheck); return raw_encode (&v.front(), &v.back()+1, alphabet);
} }
template <class Container> template <class Container>

View File

@@ -1,137 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_CRYPTOIDENTIFIER_H_INCLUDED
#define RIPPLE_TYPES_CRYPTOIDENTIFIER_H_INCLUDED
#include <ripple/types/Base58.h>
#include <ripple/types/IdentifierStorage.h>
#include <beast/ByteOrder.h>
#include <beast/crypto/Sha256.h>
#include <array>
#include <cstring>
namespace ripple {
/** Shared IdentifierType traits for Ripple crypto identifiers.
@tparam Size The number of bytes in the identifier, exclusive of version,
checksum, or padding.
@tparam Token A byte prepended to the binary data that distinguishes
the type of identifier.
@tparam Checked A `bool` indicating whether or not the string
representation includes an appended a four byte checksum on
the data including the Token.
*/
template <std::size_t Size, std::uint8_t Token, bool Checked>
class CryptoIdentifier
{
public:
typedef std::size_t size_type;
// 1 token byte,
static std::size_t const pre_size = 1;
static size_type const size = Size;
// 4 checksum bytes (optional)
static std::size_t const post_size = (Checked ? 4 : 0);
static std::uint8_t const token = Token;
static bool const checked = Checked;
// This is what the wrapper creates, it includes the padding.
typedef IdentifierStorage <
pre_size, size, post_size> value_type;
typedef typename value_type::hasher hasher;
typedef typename value_type::key_equal key_equal;
/** Initialize from an input sequence. */
static void construct (
std::uint8_t const* begin, std::uint8_t const* end,
value_type& value)
{
value.storage()[0] = Token;
assert (std::distance (begin, end) == size);
std::copy (begin, end, value.begin());
if (Checked)
{
beast::Sha256::digest_type digest;
auto const& vs = value.storage();
beast::Sha256::hash (beast::Sha256::hash (vs.data(),
vs.data() + (vs.size() - post_size)),
digest);
// We use the first 4 bytes as a checksum
std::copy (digest.begin(), digest.begin() + 4,
value.end());
}
}
/** Base class for IdentifierType. */
class base
{
public:
template <class UnsignedIntegralType>
static value_type createFromInteger (UnsignedIntegralType i)
{
static_assert (size >= sizeof (UnsignedIntegralType), "");
std::array <std::uint8_t, size> data;
data.fill (0);
i = beast::toNetworkByteOrder <UnsignedIntegralType> (i);
std::memcpy (data.data () + (data.size() - sizeof (i)), &i, std::min (size, sizeof (i)));
value_type value;
construct (data.data(), data.data() + data.size(), value);
return value;
}
};
/** Convert to std::string. */
static std::string to_string (value_type const& value)
{
typename value_type::storage_type const& storage (value.storage());
// We will convert to little endian with an extra pad byte
std::array <std::uint8_t, value_type::storage_size + 1> le;
std::reverse_copy (storage.begin(), storage.end(), le.begin());
// Set pad byte zero to make BIGNUM always positive
le.back() = 0;
return Base58::raw_encode (le.data(), le.data() + le.size(),
Base58::getRippleAlphabet(), Checked);
}
/** Convert from std::string. */
static std::pair <value_type, bool> from_string (std::string const& s)
{
value_type value;
bool success (! s.empty());
if (success && !Base58::raw_decode (&s.front(), &s.back()+1,
value.storage().data(), value_type::storage_size, Checked,
Base58::getRippleAlphabet()))
success = false;
if (success && value.storage()[0] != Token)
success = false;
return std::make_pair (value, success);
}
};
template <std::size_t Size, std::uint8_t Token, bool Checked>
typename CryptoIdentifier <Size, Token, Checked>::size_type
const CryptoIdentifier <Size, Token, Checked>::size;
}
#endif

View File

@@ -1,189 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_IDENTIFIERSTORAGE_H_INCLUDED
#define RIPPLE_TYPES_IDENTIFIERSTORAGE_H_INCLUDED
#include <beast/container/hardened_hash.h>
#include <array>
#include <cassert>
namespace ripple {
/** A padded std::array used with IdentifierType traits. */
template <std::size_t PreSize, std::size_t Size, std::size_t PostSize>
class IdentifierStorage
{
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef std::uint8_t value_type;
typedef value_type* iterator;
typedef value_type const* const_iterator;
typedef value_type& reference;
typedef value_type const& const_reference;
static size_type const pre_size = PreSize;
static size_type const size = Size;
static size_type const post_size = PostSize;
static size_type const storage_size = pre_size + size + post_size;
typedef std::array <
std::uint8_t, storage_size> storage_type;
/** Value hashing function.
The seed prevents crafted inputs from causing degenarate parent containers.
*/
typedef beast::hardened_hash <> hasher;
/** Container equality testing function. */
class key_equal
{
public:
bool operator() (IdentifierStorage const& lhs,
IdentifierStorage const& rhs) const
{
return lhs == rhs;
}
};
// iterator access
iterator begin() { return &m_storage[pre_size]; }
const_iterator begin() const { return &m_storage[pre_size]; }
const_iterator cbegin() const { return &m_storage[pre_size]; }
iterator end() { return &m_storage[storage_size-post_size]; }
const_iterator end() const { return &m_storage[storage_size-post_size]; }
const_iterator cend() const { return &m_storage[storage_size-post_size]; }
typedef std::reverse_iterator <iterator> reverse_iterator;
typedef std::reverse_iterator <const_iterator> const_reverse_iterator;
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
const_reverse_iterator crend() const { return const_reverse_iterator(begin()); }
reference operator[](size_type i)
{
assert (i < size);
return m_storage[pre_size+i];
}
const_reference operator[](size_type i) const
{
assert (i < size);
return m_storage[pre_size+i];
}
reference front() { return m_storage[pre_size]; }
reference back() { return m_storage[storage_size-post_size-1]; }
const_reference front () const { return m_storage[pre_size]; }
const_reference back() const { return m_storage[storage_size-post_size-1]; }
value_type const* data() const { return &m_storage[pre_size]; }
value_type* data() { return &m_storage[pre_size]; }
value_type* c_array() { return &m_storage[pre_size]; }
void assign (value_type value) { fill (value); }
void fill (value_type value) { std::fill_n (begin(), size, value); }
void clear () { fill (value_type ()); }
// Access storage
storage_type& storage() { return m_storage; }
storage_type const& storage() const { return m_storage; }
void rangecheck (size_type i)
{
if (i >= size)
throw std::out_of_range ("IdentifierStorage<>: index out of range");
}
bool isZero() const
{
for (const_iterator iter(begin()); iter != end(); ++iter)
if ((*iter)!=0)
return false;
return true;
}
bool isNotZero() const
{
return !isZero();
}
template <class Hasher>
friend void hash_append (Hasher& h, IdentifierStorage const& a) noexcept
{
using beast::hash_append;
hash_append (h, a.m_storage);
}
private:
storage_type m_storage;
};
//------------------------------------------------------------------------------
template <std::size_t PrePadSize, std::size_t Size, std::size_t PostPadSize>
bool operator== (IdentifierStorage <PrePadSize, Size, PostPadSize> const& lhs,
IdentifierStorage <PrePadSize, Size, PostPadSize> const& rhs)
{
return std::equal (lhs.begin(), lhs.end(), rhs.begin());
}
template <std::size_t PrePadSize, std::size_t Size, std::size_t PostPadSize>
bool operator!= (IdentifierStorage <PrePadSize, Size, PostPadSize> const& lhs,
IdentifierStorage <PrePadSize, Size, PostPadSize> const& rhs)
{
return !(lhs==rhs);
}
template <std::size_t PrePadSize, std::size_t Size, std::size_t PostPadSize>
bool operator< (IdentifierStorage <PrePadSize, Size, PostPadSize> const& lhs,
IdentifierStorage <PrePadSize, Size, PostPadSize> const& rhs)
{
return std::lexicographical_compare (lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template <std::size_t PrePadSize, std::size_t Size, std::size_t PostPadSize>
bool operator> (IdentifierStorage <PrePadSize, Size, PostPadSize> const& lhs,
IdentifierStorage <PrePadSize, Size, PostPadSize> const& rhs)
{
return rhs<lhs;
}
template <std::size_t PrePadSize, std::size_t Size, std::size_t PostPadSize>
bool operator<= (IdentifierStorage <PrePadSize, Size, PostPadSize> const& lhs,
IdentifierStorage <PrePadSize, Size, PostPadSize> const& rhs)
{
return !(rhs<lhs);
}
template <std::size_t PrePadSize, std::size_t Size, std::size_t PostPadSize>
bool operator>= (IdentifierStorage <PrePadSize, Size, PostPadSize> const& lhs,
IdentifierStorage <PrePadSize, Size, PostPadSize> const& rhs)
{
return !(lhs<rhs);
}
}
#endif

View File

@@ -1,298 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_IDENTIFIERTYPE_H_INCLUDED
#define RIPPLE_TYPES_IDENTIFIERTYPE_H_INCLUDED
#include <beast/utility/noexcept.h>
#include <cstdint>
#include <functional>
#include <iterator>
#include <ios>
#include <sstream>
#include <string>
namespace ripple {
//------------------------------------------------------------------------------
/** Template for generalizing the cryptographic primitives used. */
template <class Traits>
class IdentifierType : public Traits::base
{
public:
static std::size_t const size = Traits::size;
typedef typename Traits::value_type value_type;
typedef typename value_type::const_iterator const_iterator;
typedef typename value_type::const_reverse_iterator const_reverse_iterator;
/** Wraps Traits::hasher. */
class hasher
{
public:
hasher()
{ }
template <typename Arg>
hasher (Arg arg) : m_hasher (arg)
{ }
std::size_t operator() (IdentifierType const& id) const noexcept
{ return m_hasher(id.value()); }
private:
typename Traits::hasher m_hasher;
};
/** Wraps Traits::equal. */
class key_equal
{
public:
key_equal()
{ }
template <typename Arg>
key_equal (Arg arg) : m_equal (arg)
{ }
bool operator() (IdentifierType const& lhs,
IdentifierType const& rhs) const noexcept
{ return m_equal (lhs.value(), rhs.value()); }
private:
typename Traits::key_equal m_equal;
};
/** Create an uninitialized value. */
IdentifierType ()
{ }
/** Implicit conversion construction from value_type.
This allows the IdentifierType to appear as an lvalue where the
rvalue is the underlying container type.
*/
IdentifierType (value_type const& value)
: m_value (value)
{ }
/** Create a copy of the value from range of bytes. */
IdentifierType (std::uint8_t const* begin, std::uint8_t const* end)
{ Traits::construct (begin, end, m_value); }
/** Conversion construction from any specialized type. */
template <typename Other>
explicit IdentifierType (Other const& other)
{
this->operator= (other);
}
/** Assign a copy from another value. */
IdentifierType& operator= (value_type const& value)
{
m_value = value;
return *this;
}
/** Copy conversion from any specialized type. */
template <typename Other>
IdentifierType& operator= (Other const& other)
{
typename Traits::template assign <Other> () (
m_value, other);
return *this;
}
/** Access the value. */
value_type const& value() const
{ return m_value; }
/** Smart dereference.
This provides access to the underlying container for compatibility.
For example, to call member functions that are otherwise not
available.
*/
/** @{ */
value_type const* operator->() const
{ return &value(); }
value_type const& operator*() const
{ return value(); }
/** @} */
/** Implicit conversion to value_type.
This lets the IdentifierType appear as an rvalue in an assignment
where the lvalue is of type value_type.
*/
operator value_type const& () const
{
return value();
}
/** Iterator access. */
/** @{ */
const_iterator begin() const { return value().begin(); }
const_iterator end() const { return value().end(); }
const_iterator cbegin() const { return value().cbegin(); }
const_iterator cend() const { return value().cend(); }
const_reverse_iterator rbegin() const { return value().rbegin(); }
const_reverse_iterator rend() const { return value().rend(); }
const_reverse_iterator crbegin() const { return value().crbegin(); }
const_reverse_iterator crend() const { return value().crend(); }
/** @} */
/** Conversion to std::string. */
std::string to_string() const
{
return Traits::to_string (m_value);
}
/** Conversion from std::string.
The `bool` indicates the success of the conversion.
*/
static std::pair <IdentifierType, bool> from_string (std::string const& s)
{
return Traits::from_string (s);
}
private:
value_type m_value;
};
template <class Hasher, class Traits>
inline
void
hash_append(Hasher& h, IdentifierType<Traits> const& id)
{
using beast::hash_append;
hash_append (h, id.value());
}
//------------------------------------------------------------------------------
template <class Traits>
bool operator== (IdentifierType<Traits> const& lhs,
IdentifierType<Traits> const& rhs)
{ return lhs.value() == rhs.value(); }
template <class Traits>
bool operator!= (IdentifierType<Traits> const& lhs,
IdentifierType<Traits> const& rhs)
{ return lhs.value() != rhs.value(); }
template <class Traits>
bool operator< (IdentifierType<Traits> const& lhs,
IdentifierType<Traits> const& rhs)
{ return lhs.value() < rhs.value(); }
template <class Traits>
bool operator> (IdentifierType<Traits> const& lhs,
IdentifierType<Traits> const& rhs)
{ return lhs.value() > rhs.value(); }
template <class Traits>
bool operator<= (IdentifierType<Traits> const& lhs,
IdentifierType<Traits> const& rhs)
{ return lhs.value() <= rhs.value(); }
template <class Traits>
bool operator>= (IdentifierType<Traits> const& lhs,
IdentifierType<Traits> const& rhs)
{ return lhs.value() >= rhs.value(); }
//------------------------------------------------------------------------------
template <class Traits>
std::ostream& operator<< (std::ostream& os,
IdentifierType <Traits> const& id)
{
os << id.to_string();
return os;
}
template <class Traits>
std::istream& operator>> (std::istream& is,
IdentifierType <Traits> const& id)
{
return is;
}
//------------------------------------------------------------------------------
}
namespace std {
/** Specialization for hash. */
template <class Traits>
struct hash <ripple::IdentifierType <Traits> >
{
public:
typedef ripple::IdentifierType <Traits> argument_type;
typedef std::size_t result_type;
hash ()
{
static typename argument_type::hasher s_hash;
m_hash = s_hash;
}
template <typename Arg>
explicit hash (Arg arg)
: m_hash (arg)
{
}
result_type operator() (argument_type const& key) const
{
return m_hash (key);
}
private:
typename argument_type::hasher m_hash;
};
//------------------------------------------------------------------------------
/** Specialization for equal_to. */
template <class Traits>
struct equal_to <ripple::IdentifierType <Traits> >
{
public:
typedef bool result_type;
typedef ripple::IdentifierType <Traits> argument_type;
typedef argument_type first_argument_type;
typedef argument_type second_argument_type;
equal_to ()
{
}
template <typename Arg>
explicit equal_to (Arg arg)
: m_equal (arg)
{
}
result_type operator() (argument_type const& lhs,
argument_type const& rhs) const
{
return m_equal (lhs, rhs);
}
private:
typename argument_type::key_equal m_equal;
};
}
#endif

View File

@@ -1,65 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_RIPPLEACCOUNTID_H_INCLUDED
#define RIPPLE_TYPES_RIPPLEACCOUNTID_H_INCLUDED
#include <ripple/types/CryptoIdentifier.h>
#include <ripple/types/IdentifierType.h>
#include <array>
namespace ripple {
class RippleAccountIDTraits
: public CryptoIdentifier <20, 0, true>
{
public:
template <typename Other>
struct assign
{
void operator() (value_type& value, Other const& other)
{
value = other;
}
};
/** Convert to std::string.
*/
// VFALCO TODO Cache results in an associative map, to replicated
// the optimization performed in RippledAddress.cp
//
static std::string to_string (value_type const& value)
{
value_type::storage_type const& storage (value.storage());
// We will convert to little endian with an extra pad byte
std::array <std::uint8_t, value_type::storage_size + 1> le;
std::reverse_copy (storage.begin(), storage.end(), le.begin());
// Set pad byte zero to make BIGNUM always positive
le.back() = 0;
return Base58::raw_encode (le.data(), le.data() + le.size(),
Base58::getRippleAlphabet(), checked);
}
};
typedef IdentifierType <RippleAccountIDTraits> RippleAccountID;
}
#endif

View File

@@ -1,45 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_RIPPLEACCOUNTPRIVATEKEY_H_INCLUDED
#define RIPPLE_TYPES_RIPPLEACCOUNTPRIVATEKEY_H_INCLUDED
#include <ripple/types/CryptoIdentifier.h>
namespace ripple {
class RippleAccountPrivateKeyTraits
: public CryptoIdentifier <32, 34, true>
{
public:
template <typename Other>
struct assign
{
void operator() (value_type& value, Other const& other)
{
value = other;
}
};
};
typedef IdentifierType <RippleAccountPrivateKeyTraits> RippleAccountPrivateKey;
}
#endif

View File

@@ -1,45 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_RIPPLEACCOUNTPUBLICKEY_H_INCLUDED
#define RIPPLE_TYPES_RIPPLEACCOUNTPUBLICKEY_H_INCLUDED
#include <ripple/types/CryptoIdentifier.h>
namespace ripple {
class RippleAccountPublicKeyTraits
: public CryptoIdentifier <33, 35, true>
{
public:
template <typename Other>
struct assign
{
void operator() (value_type& value, Other const& other)
{
value = other;
}
};
};
typedef IdentifierType <RippleAccountPublicKeyTraits> RippleAccountPublicKey;
}
#endif

View File

@@ -20,36 +20,11 @@
#ifndef RIPPLE_TYPES_RIPPLELEDGERHASH_H_INCLUDED #ifndef RIPPLE_TYPES_RIPPLELEDGERHASH_H_INCLUDED
#define RIPPLE_TYPES_RIPPLELEDGERHASH_H_INCLUDED #define RIPPLE_TYPES_RIPPLELEDGERHASH_H_INCLUDED
#include <ripple/types/IdentifierType.h> #include <ripple/types/base_uint.h>
#include <ripple/types/RippleLedgerHash.h>
#include <ripple/types/SimpleIdentifier.h>
namespace ripple { namespace ripple {
/* using LedgerHash = uint256;
Hashes are used to uniquely identify objects like
transactions, peers, validators, and accounts.
For historical reasons, some hashes are 256 bits and some are 160.
David:
"The theory is that you may need to communicate public keys
to others, so having them be shorter is a good idea. plus,
you can't arbitrarily tweak them because you wouldn't know
the corresponding private key anyway. So the security
requirements aren't as great."
*/
/** The SHA256 bit hash of a signed ledger. */
class RippleLedgerHashTraits : public SimpleIdentifier <32>
{
public:
};
/** A ledger hash. */
typedef IdentifierType <RippleLedgerHashTraits> RippleLedgerHash;
// Legacy
typedef uint256 LedgerHash;
} }

View File

@@ -1,45 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_RIPPLEPRIVATEKEY_H_INCLUDED
#define RIPPLE_TYPES_RIPPLEPRIVATEKEY_H_INCLUDED
#include <ripple/types/CryptoIdentifier.h>
namespace ripple {
class RipplePrivateKeyTraits
: public CryptoIdentifier <32, 32, true>
{
public:
template <typename Other>
struct assign
{
void operator() (value_type& value, Other const& other)
{
value = other;
}
};
};
typedef IdentifierType <RipplePrivateKeyTraits> RipplePrivateKey;
}
#endif

View File

@@ -85,7 +85,7 @@ RipplePublicKey::to_string() const
std::reverse_copy (e.begin(), e.end(), le.begin()); std::reverse_copy (e.begin(), e.end(), le.begin());
le.back() = 0; // make BIGNUM positive le.back() = 0; // make BIGNUM positive
return Base58::raw_encode (le.data(), return Base58::raw_encode (le.data(),
le.data() + le.size(), Base58::getRippleAlphabet(), true); le.data() + le.size(), Base58::getRippleAlphabet());
} }
inline inline

View File

@@ -1,47 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_RIPPLEPUBLICKEYHASH_H_INCLUDED
#define RIPPLE_TYPES_RIPPLEPUBLICKEYHASH_H_INCLUDED
#include <ripple/types/SimpleIdentifier.h>
namespace ripple {
/** Traits for the public key hash. */
class RipplePublicKeyHashTraits : public SimpleIdentifier <20>
{
public:
template <typename Other>
struct assign
{
void operator() (value_type& value, Other const& other)
{
value = other;
}
};
};
/** A container holding the 160-bit hash of the 257-bit public key. */
typedef IdentifierType <RipplePublicKeyHashTraits> RipplePublicKeyHash;
}
#endif

View File

@@ -1,73 +0,0 @@
//------------------------------------------------------------------------------
/*
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_TYPES_SIMPLEIDENTIFIER_H_INCLUDED
#define RIPPLE_TYPES_SIMPLEIDENTIFIER_H_INCLUDED
#include <ripple/types/base_uint.h>
namespace ripple {
/** Provides common traits for non-signing identifiers like ledger hashes.
The storage is a suitably sized instance of base_uint.
*/
template <std::size_t Bytes>
class SimpleIdentifier
{
public:
static std::size_t const size = Bytes;
typedef std::size_t size_type;
typedef base_uint <Bytes*8> value_type;
typedef typename value_type::hasher hasher;
typedef typename value_type::key_equal key_equal;
/** Initialize from an input sequence. */
static void construct (
std::uint8_t const* begin, std::uint8_t const* end,
value_type& value)
{
std::copy (begin, end, value.begin());
}
/** Base class for IdentifierType. */
struct base { };
/** Convert to std::string. */
static std::string to_string (value_type const& value)
{
return strHex (value.cbegin(), size);
}
/** Assignment specializations.
When Other is the same as value_type, this is a copy assignment.
*/
template <typename Other>
struct assign
{
void operator() (value_type& value, Other const& other)
{
value = other;
}
};
};
}
#endif

View File

@@ -66,9 +66,8 @@ Base58::Alphabet const& Base58::getRippleAlphabet ()
return alphabet; return alphabet;
} }
std::string Base58::raw_encode ( std::string Base58::raw_encode (unsigned char const* begin,
unsigned char const* begin, unsigned char const* end, unsigned char const* end, Alphabet const& alphabet)
Alphabet const& alphabet, bool withCheck)
{ {
CAutoBN_CTX pctx; CAutoBN_CTX pctx;
CBigNum bn58 = 58; CBigNum bn58 = 58;

View File

@@ -1,24 +0,0 @@
//------------------------------------------------------------------------------
/*
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.
*/
//==============================================================================
namespace ripple {
// Relocated to RippleAddress.cpp
}

View File

@@ -22,5 +22,4 @@
#include <ripple/types/impl/Base58.cpp> #include <ripple/types/impl/Base58.cpp>
#include <ripple/types/impl/ByteOrder.cpp> #include <ripple/types/impl/ByteOrder.cpp>
#include <ripple/types/impl/strHex.cpp> #include <ripple/types/impl/strHex.cpp>
#include <ripple/types/impl/RippleIdentifierTests.cpp>
#include <ripple/types/impl/Issue.cpp> #include <ripple/types/impl/Issue.cpp>