#pragma once #include "types.hpp" #include "Encryption.hpp" #include "Signature.hpp" namespace odhtdb { struct EncryptedPrivateKey { u8 nonce[ENCRYPTION_NONCE_BYTE_SIZE]; u8 encryptedPrivateKey[ENCRYPTION_CHECKSUM_BYTE_SIZE + PRIVATE_KEY_NUM_BYTES]; EncryptedPrivateKey(); EncryptedPrivateKey(const EncryptedPrivateKey &other); // Throws DecryptionException if password (or salt) is wrong Signature::PrivateKey decrypt(const DataView &plainPassword, const DataView &salt) const; }; // Local user with encrypted private key class LocalUserEncrypted { public: static LocalUserEncrypted* create(const Signature::PublicKey &publicKey, const EncryptedPrivateKey &encryptedPrivateKey, const std::string &name) { return new LocalUserEncrypted(publicKey, encryptedPrivateKey, name); } const Signature::PublicKey& getPublicKey() const { return publicKey; } const EncryptedPrivateKey& getPrivateKey() const { return encryptedPrivateKey; } const std::string& getName() const { return name; } private: LocalUserEncrypted(const Signature::PublicKey &_publicKey, const EncryptedPrivateKey &_encryptedPrivateKey, const std::string &_name) : publicKey(_publicKey), encryptedPrivateKey(_encryptedPrivateKey), name(_name) { } private: Signature::PublicKey publicKey; EncryptedPrivateKey encryptedPrivateKey; std::string name; }; }