From 395ee67a20da705faec2d206fa4de6b0e1efadc5 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 2 Jun 2019 18:55:01 -0400 Subject: [PATCH] Schema for new encoding --- src/crypt.rs | 2 ++ src/db.rs | 14 ++++++++++++++ src/init.sql | 16 ++++++++++++++++ src/main.rs | 10 +++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/crypt.rs b/src/crypt.rs index 0343f5f..fa9fdb7 100644 --- a/src/crypt.rs +++ b/src/crypt.rs @@ -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"); diff --git a/src/db.rs b/src/db.rs index 753d1ee..7bd6293 100644 --- a/src/db.rs +++ b/src/db.rs @@ -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) -> DbHandle { let path: PathBuf = db_path diff --git a/src/init.sql b/src/init.sql index 2e3c049..cff6f5c 100644 --- a/src/init.sql +++ b/src/init.sql @@ -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) +); diff --git a/src/main.rs b/src/main.rs index 09a73e0..1d7d411 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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> { pretty_env_logger::init();