rippled
Seed.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_PROTOCOL_SEED_H_INCLUDED
21 #define RIPPLE_PROTOCOL_SEED_H_INCLUDED
22 
23 #include <ripple/basics/base_uint.h>
24 #include <ripple/basics/Slice.h>
25 #include <ripple/protocol/tokens.h>
26 #include <boost/optional.hpp>
27 #include <array>
28 
29 namespace ripple {
30 
32 class Seed
33 {
34 private:
36 
37 public:
39 
40  Seed() = delete;
41 
42  Seed (Seed const&) = default;
43  Seed& operator= (Seed const&) = default;
44 
48  ~Seed();
49 
52  explicit Seed (Slice const& slice);
53  explicit Seed (uint128 const& seed);
56  std::uint8_t const*
57  data() const
58  {
59  return buf_.data();
60  }
61 
63  size() const
64  {
65  return buf_.size();
66  }
67 
69  begin() const noexcept
70  {
71  return buf_.begin();
72  }
73 
75  cbegin() const noexcept
76  {
77  return buf_.cbegin();
78  }
79 
81  end() const noexcept
82  {
83  return buf_.end();
84  }
85 
87  cend() const noexcept
88  {
89  return buf_.cend();
90  }
91 };
92 
93 //------------------------------------------------------------------------------
94 
96 Seed
97 randomSeed();
98 
110 Seed
111 generateSeed (std::string const& passPhrase);
112 
114 template <>
115 boost::optional<Seed>
116 parseBase58 (std::string const& s);
117 
119 boost::optional<Seed>
120 parseGenericSeed (std::string const& str);
121 
124 seedAs1751 (Seed const& seed);
125 
127 inline
129 toBase58 (Seed const& seed)
130 {
131  return base58EncodeToken(TokenType::FamilySeed, seed.data(), seed.size());
132 }
133 
134 }
135 
136 #endif
ripple::Dir::const_iterator
Definition: Directory.h:49
std::string
STL class.
ripple::base58EncodeToken
std::string base58EncodeToken(TokenType type, void const *token, std::size_t size)
Definition: tokens.cpp:182
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:43
std::array::size
T size(T... args)
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:29
ripple::Seed::~Seed
~Seed()
Destroy the seed.
Definition: Seed.cpp:37
ripple::base_uint
Definition: base_uint.h:65
ripple::TokenType::FamilySeed
@ FamilySeed
ripple::seedAs1751
std::string seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition: Seed.cpp:133
array
ripple::randomSeed
Seed randomSeed()
Create a seed using secure random numbers.
Definition: Seed.cpp:61
ripple::parseGenericSeed
boost::optional< Seed > parseGenericSeed(std::string const &str)
Attempt to parse a string as a seed.
Definition: Seed.cpp:96
std::uint8_t
ripple::Seed::buf_
std::array< uint8_t, 16 > buf_
Definition: Seed.h:35
ripple::generateSeed
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition: Seed.cpp:74
ripple::Seed::size
std::size_t size() const
Definition: Seed.h:63
ripple::Seed::Seed
Seed()=delete
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Seed::begin
const_iterator begin() const noexcept
Definition: Seed.h:69
ripple::Seed
Seeds are used to generate deterministic secret keys.
Definition: Seed.h:32
ripple::Seed::operator=
Seed & operator=(Seed const &)=default
std::array::begin
T begin(T... args)
std::size_t
std::array::end
T end(T... args)
ripple::Seed::cend
const_iterator cend() const noexcept
Definition: Seed.h:87
ripple::Seed::end
const_iterator end() const noexcept
Definition: Seed.h:81
ripple::Seed::const_iterator
std::array< uint8_t, 16 >::const_iterator const_iterator
Definition: Seed.h:38
ripple::parseBase58
boost::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:36
std::array::data
T data(T... args)
ripple::Seed::data
std::uint8_t const * data() const
Definition: Seed.h:57
ripple::Seed::cbegin
const_iterator cbegin() const noexcept
Definition: Seed.h:75