DiceKeys Seeded Cryptography Library
password.hpp
1 #pragma once
2 
3 #include "sodium-buffer.hpp"
4 #include <string>
5 
19 class Password {
20 public:
21  // /**
22  // * @brief The binary representation of the password before it was translated into words.
23  // */
24  // const SodiumBuffer secretBytes;
28  const std::string password;
29 
35  const std::string recipe;
36 
42  Password(
43  const Password &other
44  );
45 
54  Password(
55  // const SodiumBuffer& secretBytes,
56  const std::string& password,
57  const std::string& recipe = {}
58  );
59 
60  // /**
61  // * @brief Derive a password from a seed secret and a set of
62  // * recipe in @ref recipe_format.
63  // *
64  // * @param seedString The secret seed string from which this password should be
65  // * derived. Once the password is derived, you won't need the secretSeedBytes
66  // * again unless you need to re-derive this password.
67  // * @param recipe The recipe in @ref recipe_format.
68  // * @param wordListAsSingleString The word list to use to generate the password, with words
69  // * separated by any number of non-alphabetic characters. This allows word lists to be
70  // * tab-delimited, comma-delimited, line-delimited, or any combination thereof.
71  // */
72  // Password(
73  // const std::string& seedString,
74  // const std::string& recipe,
75  // const std::string& wordListAsSingleString = ""
76  // );
77 
91  const std::string& seedString,
92  const std::string& recipe,
93  const std::string& wordListAsSingleString
94  );
95  static Password deriveFromSeed(
96  const std::string& seedString,
97  const std::string& recipe
98  ) {
99  return Password::deriveFromSeedAndWordList(seedString, recipe, "");
100  };
101 
111  const std::string toJson(
112  int indent = -1,
113  const char indent_char = ' '
114  ) const;
115 
116  // /**
117  // * @brief Derive the word array that can be used to build the final password
118  // *
119  // * @return const std::vector<std::string>
120  // */
121  // const std::vector<std::string> asWordVector(const std::string wordList = "") const;
122 
123  // /**
124  // * @brief Derive the password.
125  // *
126  // * @return const std::vector<std::string>
127  // */
128  // const std::string password(const std::string wordList = "") const;
129 
137  const SodiumBuffer toSerializedBinaryForm() const;
138 
146  static Password fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm);
147 
155  static Password fromJson(
156  const std::string& seedAsJson
157  );
158 
159 };
SodiumBuffer
A byte array containing a length and a pointer to memory (the data field), which ensures data is eras...
Definition: sodium-buffer.hpp:27
Password::deriveFromSeedAndWordList
static Password deriveFromSeedAndWordList(const std::string &seedString, const std::string &recipe, const std::string &wordListAsSingleString)
Derive a secret from a seed secret and a set of recipe in JSON Format for Recipes.
Definition: password.cpp:116
Password::toSerializedBinaryForm
const SodiumBuffer toSerializedBinaryForm() const
Serialize to byte array as a list of: (secretBytes, recipe)
Definition: password.cpp:165
Password::toJson
const std::string toJson(int indent=-1, const char indent_char=' ') const
Serialize this object to a JSON-formatted string.
Definition: password.cpp:152
Password
A secret derived from a seed string and set of options in JSON Format for Recipes.
Definition: password.hpp:19
Password::recipe
const std::string recipe
A string in JSON Format for Recipes string which specifies how the constructor will derive the secret...
Definition: password.hpp:35
Password::password
const std::string password
The binary representation of the password.
Definition: password.hpp:28
Password::fromJson
static Password fromJson(const std::string &seedAsJson)
Construct (reconstitute) a Password from its JSON representation.
Definition: password.cpp:139
Password::Password
Password(const Password &other)
Construct this object as a copy of another object.
Definition: password.cpp:131
Password::fromSerializedBinaryForm
static Password fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm)
Deserialize from a byte array stored as a list of: (secretBytes, recipe)
Definition: password.cpp:174