EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
sqlite_crypt_writer.h
Go to the documentation of this file.
1 
11 #ifndef SQLITE_CRYPT_WRITER_H
12 #define SQLITE_CRYPT_WRITER_H
13 
14 #include <stdint.h>
15 #include <sqlite3.h>
16 
17 #define CRYPT_STORE_TABLE_NAME "store"
18 #define CRYPT_STORE_CREATE_TABLE \
19  "CREATE TABLE " CRYPT_STORE_TABLE_NAME \
20  " (key TEXT NOT NULL, value TEXT, id TEXT, iv TEXT, " \
21  "PRIMARY KEY (key));"
22 #define CRYPT_STORE_INSERT_INTO \
23  "INSERT INTO " CRYPT_STORE_TABLE_NAME " VALUES(@key, @value, @id, @iv);"
24 #define CRYPT_STORE_DELETE_FROM \
25  "DELETE FROM " CRYPT_STORE_TABLE_NAME " WHERE key=@key;"
26 #define CRYPT_STORE_GET \
27  "SELECT value, id, iv FROM " CRYPT_STORE_TABLE_NAME " WHERE key=?;"
28 
29 #define CRYPT_SECRETS_TABLE_NAME "secrets"
30 #define CRYPT_SECRETS_CREATE_TABLE \
31  "CREATE TABLE " CRYPT_SECRETS_TABLE_NAME \
32  " (id TEXT NOT NULL, value TEXT, salt TEXT, iv TEXT, " \
33  "PRIMARY KEY (id));"
34 #define CRYPT_SECRETS_INSERT_INTO \
35  "INSERT INTO " CRYPT_SECRETS_TABLE_NAME " VALUES(@id, @value, @salt, @iv);"
36 #define CRYPT_SECRETS_GET \
37  "SELECT value, salt, iv FROM " CRYPT_SECRETS_TABLE_NAME " WHERE id=?;"
38 
43 struct store_row {
44  const char *key;
45  char *value;
46  char *id;
47  char *iv;
48 };
49 
54 struct secrets_row {
55  char *id;
56  char *value;
57  char *salt;
58  char *iv;
59 };
60 
68 int open_sqlite_crypt_db(const char *db_path, sqlite3 **sql);
69 
75 void free_sqlite_crypt_db(sqlite3 *db);
76 
84 int save_sqlite_store_entry(sqlite3 *db, struct store_row *row);
85 
93 int save_sqlite_secrets_entry(sqlite3 *db, struct secrets_row *row);
94 
102 struct store_row *get_sqlite_store_row(sqlite3 *db, const char *key);
103 
109 void free_sqlite_store_row(struct store_row *row);
110 
118 struct secrets_row *get_sqlite_secrets_row(sqlite3 *db, const char *id);
119 
125 void free_sqlite_secrets_row(struct secrets_row *row);
126 #endif
int save_sqlite_store_entry(sqlite3 *db, struct store_row *row)
Save a store entry into the sqlite db.
Definition: sqlite_crypt_writer.c:73
int save_sqlite_secrets_entry(sqlite3 *db, struct secrets_row *row)
Save a secrets entry into the sqlite db.
Definition: sqlite_crypt_writer.c:138
void free_sqlite_crypt_db(sqlite3 *db)
Closes the sqlite db.
Definition: sqlite_crypt_writer.c:67
struct secrets_row * get_sqlite_secrets_row(sqlite3 *db, const char *id)
Get the sqlite secrets entry object.
Definition: sqlite_crypt_writer.c:273
void free_sqlite_secrets_row(struct secrets_row *row)
Frees a secrets row entry.
Definition: sqlite_crypt_writer.c:259
int open_sqlite_crypt_db(const char *db_path, sqlite3 **sql)
Opens the sqlite crypt db.
Definition: sqlite_crypt_writer.c:22
struct store_row * get_sqlite_store_row(sqlite3 *db, const char *key)
Get the sqlite store entry object.
Definition: sqlite_crypt_writer.c:200
void free_sqlite_store_row(struct store_row *row)
Frees a store row entry.
Definition: sqlite_crypt_writer.c:187
The secrets row structure definition.
Definition: sqlite_crypt_writer.h:54
char * salt
Definition: sqlite_crypt_writer.h:57
char * iv
Definition: sqlite_crypt_writer.h:58
char * id
Definition: sqlite_crypt_writer.h:55
char * value
Definition: sqlite_crypt_writer.h:56
The store row structure definition.
Definition: sqlite_crypt_writer.h:43
char * value
Definition: sqlite_crypt_writer.h:45
char * id
Definition: sqlite_crypt_writer.h:46
const char * key
Definition: sqlite_crypt_writer.h:44
char * iv
Definition: sqlite_crypt_writer.h:47