diff options
author | dec05eba <0xdec05eba@gmail.com> | 2018-05-15 20:39:12 +0200 |
---|---|---|
committer | dec05eba <0xdec05eba@gmail.com> | 2018-05-15 20:39:15 +0200 |
commit | 9163d30c3c62598e4177d57e0fc088e74def1c66 (patch) | |
tree | 1af4f1b09c142ef1afbba7df371e72de02e9de06 /include | |
parent | d8e5c76c364450179f12fa985d50b7e4bfb5aa78 (diff) |
Allow storing user without nodes
Diffstat (limited to 'include')
-rw-r--r-- | include/odhtdb/DataView.hpp | 1 | ||||
-rw-r--r-- | include/odhtdb/Database.hpp | 5 | ||||
-rw-r--r-- | include/odhtdb/DatabaseStorage.hpp | 15 |
3 files changed, 21 insertions, 0 deletions
diff --git a/include/odhtdb/DataView.hpp b/include/odhtdb/DataView.hpp index 0ecf9fb..2f22d83 100644 --- a/include/odhtdb/DataView.hpp +++ b/include/odhtdb/DataView.hpp @@ -12,6 +12,7 @@ namespace odhtdb DataView() : data(nullptr), size(0) {} DataView(void *_data, usize _size) : data(_data), size(_size) {} bool operator == (const DataView &other) const; + bool operator != (const DataView &other) const; void *data; usize size; diff --git a/include/odhtdb/Database.hpp b/include/odhtdb/Database.hpp index 43c1ad9..ca9369f 100644 --- a/include/odhtdb/Database.hpp +++ b/include/odhtdb/Database.hpp @@ -176,6 +176,11 @@ namespace odhtdb ntp::NtpTimestamp getSyncedTimestampUtc() const; + bool doesStoredUserExist(const std::string &username) const; + + // Throws SqlExecException if user with same name already exists + void storeUserWithoutNodes(const std::string &username, const std::string &password); + // Username has to be either unique or if it's the same as existing one, then password has to match. // Node has to be unique for the user. // Throws DatabaseStorageWrongPassword or SqlExecException on failure (if username is not unique in node). diff --git a/include/odhtdb/DatabaseStorage.hpp b/include/odhtdb/DatabaseStorage.hpp index 613f2e8..f03bd9e 100644 --- a/include/odhtdb/DatabaseStorage.hpp +++ b/include/odhtdb/DatabaseStorage.hpp @@ -58,6 +58,12 @@ namespace odhtdb DatabaseStorageWrongPassword(const std::string &errMsg) : DatabaseStorageException(errMsg) {} }; + class DatabaseStorageNoSuchStoredUser : public DatabaseStorageException + { + public: + DatabaseStorageNoSuchStoredUser(const std::string &errMsg) : DatabaseStorageException(errMsg) {} + }; + const int PASSWORD_SALT_LEN = 16; const int HASHED_PASSWORD_LEN = 32; @@ -111,6 +117,11 @@ namespace odhtdb // Throws DatabaseStorageNotFound if user doesn't exist in node u64 getUserActionCounter(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const; + bool doesStoredUserExist(const std::string &username) const; + + // Throws SqlExecException if user with same name already exists + void storeUserWithoutNodes(const std::string &username, const std::string &password); + // Username has to be either unique or if it's the same as existing one, then password has to match. // Node has to be unique for the user. // Throws DatabaseStorageWrongPassword or SqlExecException on failure (if username is not unique in node). @@ -118,6 +129,7 @@ namespace odhtdb // Returns nodes, public key and private key of encrypted user. // Throws DatabaseStorageWrongPassword if password for the stored user is wrong. + // Throws DatabaseStorageNoSuchStoredUser if user doesn't exist. std::vector<NodeUserKeyPair> getStoredUserNodeDataDecrypted(const std::string &username, const std::string &password); // Returns true and node decryption key if node exists and we have the decryption key, @@ -148,6 +160,9 @@ namespace odhtdb void setNodeAddDataDecrypted(i64 rowId); void setNodeAddDataDecryptedData(i64 rowId, const DataView &decryptedData); + + // Throws DatabaseStorageNoSuchStoredUser or DatabaseStorageWrongPassword + i64 getStoredUserId(const std::string &username, const DataView &hashedPassword); private: Database *database; sqlite3 *sqliteDb; |