DiceKeys Seeded Cryptography Library
signature-verification-key.hpp
1 #pragma once
2 
3 #include <cassert>
4 #include <sodium.h>
5 #include <vector>
6 #include <string>
7 
8 #include "sodium-buffer.hpp"
9 
26 public:
30  const std::vector<unsigned char> signatureVerificationKeyBytes;
34  const std::string recipe;
35 
43  const std::vector<unsigned char> &keyBytes,
44  const std::string& recipe
45  );
46 
54  const std::string& signatureVerificationKeyAsJson
55  );
56 
66  const std::string toJson(
67  int indent = -1,
68  const char indent_char = ' '
69  ) const;
70 
79 private:
80  static bool verify(
81  const unsigned char* signatureVerificationKeyBytes,
82  const unsigned char* message,
83  const size_t messageLength,
84  const unsigned char* signature
85  );
86 
87 public:
106  static bool verify(
107  const unsigned char* signatureVerificationKeyBytes,
108  const size_t signatureVerificationKeyBytesLength,
109  const unsigned char* message,
110  const size_t messageLength,
111  const unsigned char* signature,
112  const size_t signatureLength
113  );
114 
131  static bool verify(
132  const std::vector<unsigned char>& signatureVerificationKeyBytes,
133  const unsigned char* message,
134  const size_t messageLength,
135  const std::vector<unsigned char>& signature
136  );
137 
151  bool verify(
152  const unsigned char* message,
153  const size_t messageLength,
154  const std::vector<unsigned char>& signature
155  ) const;
156 
169  bool verify(
170  const std::vector<unsigned char>& message,
171  const std::vector<unsigned char>& signature
172  ) const;
173 
186  bool verify(
187  const SodiumBuffer& message,
188  const std::vector<unsigned char>& signature
189  ) const;
190 
196  const std::vector<unsigned char> getKeyBytes() const;
197 
203  const std::string getKeyBytesAsHexDigits() const;
204 
211  const std::string getRecipeJson() const {
212  return recipe;
213  }
214 
222  const SodiumBuffer toSerializedBinaryForm() const;
223 
231  static SignatureVerificationKey fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm);
232 
236  const std::string toOpenSshPublicKey() const;
237 };
238 
SignatureVerificationKey::getKeyBytes
const std::vector< unsigned char > getKeyBytes() const
Get the raw signature verification key as a byte vector.
Definition: signature-verification-key.cpp:55
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
SignatureVerificationKey::getRecipeJson
const std::string getRecipeJson() const
Get the JSON-formatted recipe string used to generate the public-private key pair.
Definition: signature-verification-key.hpp:211
SignatureVerificationKey::SignatureVerificationKey
SignatureVerificationKey(const std::vector< unsigned char > &keyBytes, const std::string &recipe)
Construct by passing the classes members.
Definition: signature-verification-key.cpp:16
SignatureVerificationKey::fromSerializedBinaryForm
static SignatureVerificationKey fromSerializedBinaryForm(const SodiumBuffer &serializedBinaryForm)
Deserialize from a byte array stored as a list of: (signatureVerificationKeyBytes,...
Definition: signature-verification-key.cpp:136
SignatureVerificationKey::signatureVerificationKeyBytes
const std::vector< unsigned char > signatureVerificationKeyBytes
The raw binary representation of the cryptographic key.
Definition: signature-verification-key.hpp:30
SignatureVerificationKey::getKeyBytesAsHexDigits
const std::string getKeyBytesAsHexDigits() const
Get the raw signature-verification key as a string of hex digits.
Definition: signature-verification-key.cpp:60
SignatureVerificationKey::toOpenSshPublicKey
const std::string toOpenSshPublicKey() const
Convert the signature-verification key to an OpenSSH public key string.
Definition: signature-verification-key.cpp:145
SignatureVerificationKey::toSerializedBinaryForm
const SodiumBuffer toSerializedBinaryForm() const
Serialize to byte array as a list of: (signatureVerificationKeyBytes, recipe)
Definition: signature-verification-key.cpp:127
SignatureVerificationKey::toJson
const std::string toJson(int indent=-1, const char indent_char=' ') const
Serialize this object to a JSON-formatted string.
Definition: signature-verification-key.cpp:43
SignatureVerificationKey::recipe
const std::string recipe
A JSON Format for Recipes string used to specify how this key is derived.
Definition: signature-verification-key.hpp:34
SignatureVerificationKey
A SignatureVerificationKey is used to verify that messages were signed by its corresponding SigningKe...
Definition: signature-verification-key.hpp:25
SignatureVerificationKey::fromJson
static SignatureVerificationKey fromJson(const std::string &signatureVerificationKeyAsJson)
Construct (reconstitute) a SignatureVerificationKey from JSON format, which may ahve been generated b...
Definition: signature-verification-key.cpp:25