2014-12-09 20:36:32 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef BLOCKSTORE_UTILS_KEY_H_
|
|
|
|
#define BLOCKSTORE_UTILS_KEY_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
|
|
|
|
// A key here is NOT a key for encryption, but a key as used in key->value mappings ("access handle for a block").
|
|
|
|
class Key {
|
|
|
|
public:
|
|
|
|
//Non-virtual destructor because we want Key objects to be small
|
|
|
|
~Key();
|
|
|
|
|
|
|
|
static constexpr unsigned int KEYLENGTH_BINARY = 16;
|
|
|
|
static constexpr unsigned int KEYLENGTH_STRING = 2 * KEYLENGTH_BINARY; // Hex encoding
|
|
|
|
|
|
|
|
static Key CreateRandomKey();
|
|
|
|
|
|
|
|
static Key FromString(const std::string &key);
|
2014-12-13 11:59:48 +01:00
|
|
|
std::string ToString() const;
|
|
|
|
|
2014-12-13 17:43:02 +01:00
|
|
|
static Key FromBinary(const void *source);
|
2014-12-13 11:59:48 +01:00
|
|
|
void ToBinary(void *target) const;
|
2014-12-09 20:36:32 +01:00
|
|
|
|
|
|
|
const unsigned char *data() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Key();
|
|
|
|
|
|
|
|
unsigned char _key[KEYLENGTH_BINARY];
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const Key &lhs, const Key &rhs);
|
|
|
|
bool operator!=(const Key &lhs, const Key &rhs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|