DiceKeys Seeded Cryptography Library
Secret Class Reference

A secret derived from a seed string and set of options in JSON Format for Recipes. More...

#include <secret.hpp>

Public Member Functions

 Secret (const Secret &other)
 Construct this object as a copy of another object. More...
 
 Secret (const SodiumBuffer &secretBytes, const std::string &recipe={})
 
 Secret (const std::string &seedString, const std::string &recipe)
 Derive a secret from a seed secret and a set of recipe in JSON Format for Recipes. More...
 
const std::string toJson (int indent=-1, const char indent_char=' ') const
 Serialize this object to a JSON-formatted string. More...
 
const SodiumBuffer toSerializedBinaryForm () const
 Serialize to byte array as a list of: (secretBytes, recipe) More...
 

Static Public Member Functions

static Secret deriveFromSeed (const std::string &seedString, const std::string &recipe)
 Derive a secret from a seed secret and a set of recipe in JSON Format for Recipes. More...
 
static Secret fromSerializedBinaryForm (const SodiumBuffer &serializedBinaryForm)
 Deserialize from a byte array stored as a list of: (secretBytes, recipe) More...
 
static Secret fromJson (const std::string &seedAsJson)
 Construct (reconstitute) a Secret from its JSON representation. More...
 

Public Attributes

const SodiumBuffer secretBytes
 The binary representation of the derived secret.
 
const std::string recipe
 A string in JSON Format for Recipes string which specifies how the constructor will derive the secretBytes from the original secret seed.
 

Detailed Description

A secret derived from a seed string and set of options in JSON Format for Recipes.

Because the secret is derived using a one-way function, its value does not reveal the secret seed used to derive it. Rather, clients can use this secret knowing that, if lost, it can be re-derived from the same seed and recipe that were first used to derive it.

Constructor & Destructor Documentation

◆ Secret() [1/3]

Secret::Secret ( const Secret other)

Construct this object as a copy of another object.

Parameters
otherThe Secret to copy into this new object

◆ Secret() [2/3]

Secret::Secret ( const SodiumBuffer secretBytes,
const std::string &  recipe = {} 
)

Construct a secret from its two fields: the secretBytes and the recipe.

Parameters
secretBytesThe derived secret.
recipeThe recipe in JSON Format for Recipes.

◆ Secret() [3/3]

Secret::Secret ( const std::string &  seedString,
const std::string &  recipe 
)

Derive a secret from a seed secret and a set of recipe in JSON Format for Recipes.

Parameters
seedStringThe secret seed string from which this secret should be derived. Once the secret is derived, you won't need the secretSeedBytes again unless you need to re-derive this secret.
recipeThe recipe in JSON Format for Recipes.

Member Function Documentation

◆ deriveFromSeed()

Secret Secret::deriveFromSeed ( const std::string &  seedString,
const std::string &  recipe 
)
static

Derive a secret from a seed secret and a set of recipe in JSON Format for Recipes.

Parameters
seedStringThe secret seed string from which this secret should be derived. Once the secret is derived, you won't need the secretSeedBytes again unless you need to re-derive this secret.
recipeThe recipe in JSON Format for Recipes.

◆ fromJson()

Secret Secret::fromJson ( const std::string &  seedAsJson)
static

Construct (reconstitute) a Secret from its JSON representation.

Parameters
seedAsJsonA Secret serialized in JSON format via a previous call to toJson.

◆ fromSerializedBinaryForm()

Secret Secret::fromSerializedBinaryForm ( const SodiumBuffer serializedBinaryForm)
static

Deserialize from a byte array stored as a list of: (secretBytes, recipe)

Stored in SodiumBuffer's fixed-length list format. Strings are stored as UTF8 byte arrays.

◆ toJson()

const std::string Secret::toJson ( int  indent = -1,
const char  indent_char = ' ' 
) const

Serialize this object to a JSON-formatted string.

It can be reconstituted by calling the constructor with this string.

Parameters
indentThe number of characters to indent the JSON (optional)
indent_charThe character with which to indent the JSON (optional)
Returns
const std::string A Secret serialized to JSON format.

◆ toSerializedBinaryForm()

const SodiumBuffer Secret::toSerializedBinaryForm ( ) const

Serialize to byte array as a list of: (secretBytes, recipe)

Stored in SodiumBuffer's fixed-length list format. Strings are stored as UTF8 byte arrays.


The documentation for this class was generated from the following files: