//------------------------------------------------------------------------------ /* 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_PROTOCOL_RIPPLEPUBLICKEY_H_INCLUDED #define RIPPLE_PROTOCOL_RIPPLEPUBLICKEY_H_INCLUDED #include #include #include #include #include #include #include #include // namespace ripple { // Simplified public key that avoids the complexities of RippleAddress class RipplePublicKey { private: std::array data_; public: /** Construct from a range of unsigned char. */ template ::value_type>::value>> RipplePublicKey (FwdIt first, FwdIt last); template std::string to_string() const; friend bool operator< (RipplePublicKey const& lhs, RipplePublicKey const& rhs) { return lhs.data_ < rhs.data_; } friend bool operator== (RipplePublicKey const& lhs, RipplePublicKey const& rhs) { return lhs.data_ == rhs.data_; } }; template RipplePublicKey::RipplePublicKey (FwdIt first, FwdIt last) { assert(std::distance(first, last) == data_.size()); // VFALCO TODO Use 4-arg copy from C++14 std::copy (first, last, data_.begin()); } template std::string RipplePublicKey::to_string() const { // The expanded form of the key is: // std::array e; e[0] = 28; // node public key type std::copy (data_.begin(), data_.end(), e.begin() + 1); Base58::fourbyte_hash256 (&*(e.begin() + 34), e.data(), 34); // Convert key + checksum to little endian with an extra pad byte std::array le; std::reverse_copy (e.begin(), e.end(), le.begin()); le.back() = 0; // make BIGNUM positive return Base58::raw_encode (le.data(), le.data() + le.size(), Base58::getRippleAlphabet()); } inline std::ostream& operator<< (std::ostream& os, RipplePublicKey const& k) { return os << k.to_string(); } } #endif