Schema for new encoding

This commit is contained in:
Tom Alexander 2019-06-02 18:55:01 -04:00
parent 542dedec8d
commit 395ee67a20
4 changed files with 41 additions and 1 deletions

View File

@ -154,6 +154,8 @@ mod tests {
#[test]
fn test_encrypted_value_round_trip() {
// Test that writing a value to the DB and reading it back
// doesn't result in any corruption
let db = Connection::open_in_memory().expect("Failed to open DB");
db.execute_batch("CREATE TABLE test (content BLOB);")
.expect("Failed to create table");

View File

@ -26,6 +26,20 @@ pub struct Account {
pub password: String,
}
#[derive(Debug)]
pub struct DbNamespace {
pub id: i64,
pub name: String,
}
#[derive(Debug)]
pub struct DbNote {
pub id: i64,
pub category: String,
pub title: String,
pub value: String,
}
impl DbHandle {
pub fn new(db_path: &Option<String>) -> DbHandle {
let path: PathBuf = db_path

View File

@ -1,3 +1,5 @@
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS encrypted_values (
id INTEGER PRIMARY KEY AUTOINCREMENT,
iv TEXT,
@ -21,3 +23,17 @@ CREATE TABLE IF NOT EXISTS accounts(
user INTEGER NOT NULL,
password INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS namespaces(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name BLOB NOT NULL
);
CREATE TABLE IF NOT EXISTS notes(
id INTEGER PRIMARY KEY AUTOINCREMENT,
namespace INTEGER,
category TEXT NOT NULL CHECK(category IN ('account', 'note')),
title BLOB NOT NULL,
value BLOB NOT NULL,
FOREIGN KEY(namespace) REFERENCES namespaces(id)
);

View File

@ -142,7 +142,15 @@ fn set(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
println!("Successfully added password");
}
fn transfer(mut db_conn: db::DbHandle, master_key: [u8; 32]) {}
fn transfer(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
for host in db_conn
.list_accounts(master_key)
.into_iter()
.map(|account: db::Account| account.host)
{
println!("{}", host);
}
}
fn main() -> Result<(), Box<dyn Error>> {
pretty_env_logger::init();