From 5fa3cb8632931c181f778cba29be0d0d782497c7 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Thu, 2 Oct 2014 12:55:20 -0400 Subject: [PATCH] Add < operation to private_key to allow usage as an ordered key --- include/fc/crypto/elliptic.hpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/include/fc/crypto/elliptic.hpp b/include/fc/crypto/elliptic.hpp index e7145a4..d96977d 100644 --- a/include/fc/crypto/elliptic.hpp +++ b/include/fc/crypto/elliptic.hpp @@ -6,13 +6,13 @@ #include #include -namespace fc { +namespace fc { namespace ecc { - namespace detail - { - class public_key_impl; - class private_key_impl; + namespace detail + { + class public_key_impl; + class private_key_impl; } typedef fc::array public_key_data; @@ -72,7 +72,7 @@ namespace fc { * @class private_key * @brief an elliptic curve private key. */ - class private_key + class private_key { public: private_key(); @@ -88,7 +88,7 @@ namespace fc { /** * This method of generation enables creating a new private key in a deterministic manner relative to - * an initial seed. A public_key created from the seed can be multiplied by the offset to calculate + * an initial seed. A public_key created from the seed can be multiplied by the offset to calculate * the new public key without having to know the private key. */ static private_key generate_from_seed( const fc::sha256& seed, const fc::sha256& offset = fc::sha256() ); @@ -99,7 +99,7 @@ namespace fc { /** * Given a public key, calculatse a 512 bit shared secret between that - * key and this private key. + * key and this private key. */ fc::sha512 get_shared_secret( const public_key& pub )const; @@ -109,11 +109,19 @@ namespace fc { public_key get_public_key()const; - inline friend bool operator==( const private_key& a, const private_key& b ) { return a.get_secret() == b.get_secret(); } + inline friend bool operator!=( const private_key& a, const private_key& b ) + { + return a.get_secret() != b.get_secret(); + } + inline friend bool operator<( const private_key& a, const private_key& b ) + { + return a.get_secret() < b.get_secret(); + } + private: fc::fwd my; }; @@ -155,7 +163,7 @@ namespace fc { } // namespace raw -} // namespace fc +} // namespace fc #include FC_REFLECT_TYPENAME( fc::ecc::private_key )