diff options
author | Aleksi Lindeman <0xdec05eba@gmail.com> | 2018-04-14 19:45:15 +0200 |
---|---|---|
committer | Aleksi Lindeman <0xdec05eba@gmail.com> | 2018-04-14 19:45:24 +0200 |
commit | 6e4d46f8cf911b82a10e8cd25b65fcc421bbc712 (patch) | |
tree | 3d6ee838990389d920df934e20aea1700052ce74 /include/odhtdb/LocalUserEncrypted.hpp | |
parent | 9c22be3516d5067b98b06271e2f3545713ff6099 (diff) |
Store database storage to files, also loading
Diffstat (limited to 'include/odhtdb/LocalUserEncrypted.hpp')
-rw-r--r-- | include/odhtdb/LocalUserEncrypted.hpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/include/odhtdb/LocalUserEncrypted.hpp b/include/odhtdb/LocalUserEncrypted.hpp new file mode 100644 index 0000000..c250d13 --- /dev/null +++ b/include/odhtdb/LocalUserEncrypted.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "User.hpp" +#include "types.hpp" +#include "Encryption.hpp" + +namespace odhtdb +{ + struct EncryptedPrivateKey + { + u8 nonce[ENCRYPTION_NONCE_BYTE_SIZE]; + u8 encryptedPrivateKey[16 + 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 User + { + public: + static LocalUserEncrypted* create(const Signature::PublicKey &publicKey, const EncryptedPrivateKey &encryptedPrivateKey, const std::string &name, Group *group) + { + return new LocalUserEncrypted(publicKey, encryptedPrivateKey, name, group); + } + + const Signature::PublicKey& getPublicKey() const override + { + return publicKey; + } + + const EncryptedPrivateKey& getPrivateKey() const + { + return encryptedPrivateKey; + } + private: + LocalUserEncrypted(const Signature::PublicKey &_publicKey, const EncryptedPrivateKey &_encryptedPrivateKey, const std::string &name, Group *group) : + User(User::Type::LOCAL_ENCRYPTED, name, group), + publicKey(_publicKey), + encryptedPrivateKey(_encryptedPrivateKey) + { + + } + private: + Signature::PublicKey publicKey; + EncryptedPrivateKey encryptedPrivateKey; + }; +} |