DiceKeys Seeded Cryptography Library
recipe.hpp
1 #pragma once
2 
3 #ifndef EMSCRIPTEN
4  #pragma warning( disable : 26812 )
5 #endif
6 #include "github-com-nlohmann-json/json.hpp"
7 // Must come after json.hpp
8 #include "./externally-generated/derivation-parameters.hpp"
9 #include "recipe.hpp"
10 
11 const size_t BytesPerWordOfPassword = 8;
12 
13 
14 
23 class Recipe {
29 private:
30  nlohmann::json recipeExplicit;
31 public:
35  RecipeJson::Algorithm algorithm;
39  const std::string recipe;
40 
44  RecipeJson::type type;
45 
49  unsigned int lengthInBytes = 0;
53  unsigned int lengthInBits = 0;
57  size_t lengthInChars = -1;
61  unsigned int lengthInWords = 0;
65  RecipeJson::WordList wordList = RecipeJson::WordList::_INVALID_WORD_LIST_;
74 
78  RecipeJson::HashFunction hashFunction;
79 
94  Recipe(
95  const std::string& recipe,
96  const RecipeJson::type typeRequired =
97  RecipeJson::type::_INVALID_TYPE_
98  );
99 
107  int indent = -1,
108  const char indent_char = ' '
109  ) const;
110 
151  static const SodiumBuffer derivePrimarySecret(
152  const std::string& seedString,
153  const std::string& recipe,
154  const RecipeJson::type typeRequired = RecipeJson::type::_INVALID_TYPE_,
155  const size_t lengthInBytesRequired = 0
156  );
157 
196  const std::string& seedString,
197  const RecipeJson::type defaultType =
198  RecipeJson::type::_INVALID_TYPE_
199  ) const;
200 
201 };
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
Recipe::lengthInBits
unsigned int lengthInBits
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:53
Recipe::lengthInBytes
unsigned int lengthInBytes
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:49
Recipe::recipeWithAllOptionalParametersSpecified
const std::string recipeWithAllOptionalParametersSpecified(int indent=-1, const char indent_char=' ') const
Return JSON with default parameters filled in.
Definition: recipe.cpp:226
Recipe::Recipe
Recipe(const std::string &recipe, const RecipeJson::type typeRequired=RecipeJson::type::_INVALID_TYPE_)
Definition: recipe.cpp:34
Recipe::hashFunctionMemoryPasses
size_t hashFunctionMemoryPasses
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:73
Recipe::algorithm
RecipeJson::Algorithm algorithm
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:35
Recipe::lengthInChars
size_t lengthInChars
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:57
Recipe::type
RecipeJson::type type
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:44
Recipe::recipe
const std::string recipe
The original JSON string used to construct this object.
Definition: recipe.hpp:39
Recipe::hashFunctionMemoryLimitInBytes
size_t hashFunctionMemoryLimitInBytes
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:69
Recipe::derivePrimarySecret
static const SodiumBuffer derivePrimarySecret(const std::string &seedString, const std::string &recipe, const RecipeJson::type typeRequired=RecipeJson::type::_INVALID_TYPE_, const size_t lengthInBytesRequired=0)
This function derives the master secrets for SymmetricKey, for the SealingKey and UnsealingKey pair,...
Definition: recipe.cpp:312
Recipe
This class parses a recipe string on construction and then exposes the Recipe JSON Universal Fields a...
Definition: recipe.hpp:23
Recipe::lengthInWords
unsigned int lengthInWords
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:61
Recipe::wordList
RecipeJson::WordList wordList
Mirroring the JSON field in Recipe JSON Universal Fields.
Definition: recipe.hpp:65
Recipe::hashFunction
RecipeJson::HashFunction hashFunction
The name of the hash function specified in the Recipe JSON Universal Fields.
Definition: recipe.hpp:78