-
Notifications
You must be signed in to change notification settings - Fork 2
/
databaseserver.hpp
103 lines (90 loc) · 4.27 KB
/
databaseserver.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef DATABASESERVER_H
#define DATABASESERVER_H
#include <QObject>
#include <QtCrypto>
#include "database.hpp"
#include "paillierpublickey.hpp"
class DatabaseServer : public QObject
{
Q_OBJECT
public:
explicit DatabaseServer(QObject *parent = 0);
typedef QPair<DB::Word, QCA::SecureArray> SearchWord;
typedef QPair<SearchWord, DB::Index> SearchTerm;
/**
* @brief Return the next available index within the database
*
* This calculates the next available index, which is the same as the number
* of items currently stored. If there are two rows in the database, four
* items per row, then the next available index is 8. If the database is
* empty, the next available index is 0.
*
* This information is needed by the client, in order to add new rows to the
* database, as the encryption of a field is based on its index within the
* database.
*
* @return The next available index
*/
DB::Index nextAvailableIndex();
/**
* @brief Adds a new row to the database
* @param newRow The new row to add
*
* This method adds a new row to the end of the database. The row should be
* properly encrypted already, and must have taken nextAvailableIndex() into
* account.
*/
void appendRow(DB::Row newRow);
/**
* @brief Return all rows containing the specified word
* @param word The word to search for
* @param column The column to search for the word in; if -1, search all
*
* This method searches the encrypted database for word. If column is not
* -1, then only the specified column is searched, but the entire matching
* row will be returned. If column is -1, then all columns are searched.
*
* If column is less than -1 or greater than the highest column index, the
* return value is QList<QList<quint32> >()
*
* @return Indexed lsit of all rows containing the specified word
*/
DB::IndexedRowList findRowsContaining(QPair<DB::Word, QCA::SecureArray> search, qint8 column = -1) const;
/**
* @brief This is an overloaded function
* @param rowsToSearch A list of rows to search, instead of the entire database
* @return Rows in rowsToSearch which match the search word
*/
DB::IndexedRowList findRowsContaining(DB::IndexedRowList rowsToSearch, QPair<DB::Word, QCA::SecureArray> search, qint8 column = -1) const;
/**
* @brief Similar to findRowsContaining, except it performs multiple searches
* @param searchTerms A list of <searchTerm, column> pairs. Any columns which are -1 mean match in any column.
* @return Rows in database which match all search terms
*/
DB::IndexedRowList findRowsContainingMultiple(QList<SearchTerm> searchTerms) const;
/**
* @brief Same as findRowsContainingMultiple, except it returns the number of matches
* @param searchTerms A list of <searchTerm, column> pairs. Any columns which are -1 mean match in any column.
* @param key Public key to encrypt result with
* @return Paillier-encrypted count of rows that match all terms
*/
QCA::BigInteger numberOfRowsContainingMultiple(QList<SearchTerm> searchTerms, PaillierPublicKey key) const;
/**
* @brief Same as numberOfRowsContainingMultiple, except it returns both the number of matches and the sum of values in a specific column of matching rows
* @param column The column to sum over; this column must be in DB::ComputableColumns
* @return <sum, count> where sum is the sum of all values in column in rows selected, and count is the number of values added to make sum
*/
QPair<QCA::BigInteger, QCA::BigInteger> sumAndCountOfColumnInRowsContainingMultiple(QList<SearchTerm> searchTerms, DB::Columns column, PaillierPublicKey key) const;
/**
* @brief This function tooooooooooooooootally calculates the Pearson Correlation Coefficient of the two given IPs. Totally.
* @param ip1 First IP
* @param ip2 Second IP
* @return A real in the range [-1,1) which is definitely, most assuredly, ostensibly the Pearson Correlation Coefficient of \ip1 and \ip2.
*/
qreal pearsonCorrelationCoefficient(QCA::BigInteger ip1, QCA::BigInteger ip2) const;
signals:
public slots:
private:
DB::RowList crypticDatabase;
};
#endif // DATABASESERVER_H