From c352fd1c6b5b7119dfa9cc8eb642aa3ee7127a01 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sat, 8 Sep 2018 23:33:22 +0200 Subject: Assorted code fixes --- lockchain-core/src/init.rs | 2 +- lockchain-core/src/lib.rs | 4 ++-- lockchain-files/examples/create.rs | 10 ++++++++-- lockchain-files/src/lib.rs | 33 ++++++++++++++++++--------------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lockchain-core/src/init.rs b/lockchain-core/src/init.rs index bf40518..0e666bb 100644 --- a/lockchain-core/src/init.rs +++ b/lockchain-core/src/init.rs @@ -75,6 +75,6 @@ impl Generator { V: Vault, B: Body, { - V::new(self) + V::new(self).map(|b| *b) } } diff --git a/lockchain-core/src/lib.rs b/lockchain-core/src/lib.rs index 52139bb..bdcebdc 100644 --- a/lockchain-core/src/lib.rs +++ b/lockchain-core/src/lib.rs @@ -81,12 +81,12 @@ mod init; pub use self::crypto::PackedData; pub use self::meta::{MetaDomain, VaultMetadata}; pub use self::record::{EncryptedBody, Header, Payload, Record}; -pub use self::init::Generator; +pub use self::init::{VaultType, Generator}; /// Export commonly used types via the prelude pub mod prelude { pub use super::crypto::PackedData; pub use super::meta::{MetaDomain, VaultMetadata}; pub use super::record::{EncryptedBody, Header, Payload, Record}; - pub use super::init::Generator; + pub use super::init::{VaultType, Generator}; } diff --git a/lockchain-files/examples/create.rs b/lockchain-files/examples/create.rs index b1c6a94..68fd980 100644 --- a/lockchain-files/examples/create.rs +++ b/lockchain-files/examples/create.rs @@ -4,7 +4,7 @@ extern crate lockchain_files as files; use files::DataVault; use lcc::traits::Vault; use lcc::users::User; -use lcc::{Generator, EncryptedBody, Payload, Record}; +use lcc::{EncryptedBody, Generator, Payload, Record, VaultType}; use std::env; fn main() { @@ -12,7 +12,13 @@ fn main() { let path = env::args().nth(1).unwrap(); let name = env::args().nth(2).unwrap(); - let mut vault: DataVault = Generator::new().path(name, path).finalise(); + let mut vault: DataVault = Generator::new() + .path(name, path) + .user_type(VaultType::SoloUser { + username: "spacekookie".into(), + secret: "foobar3264".into(), + }).finalise() + .unwrap(); vault.sync(); // let vault: DataVault = DataVault::new(&name, &path); diff --git a/lockchain-files/src/lib.rs b/lockchain-files/src/lib.rs index 5926355..af7271e 100644 --- a/lockchain-files/src/lib.rs +++ b/lockchain-files/src/lib.rs @@ -56,6 +56,7 @@ extern crate serde; use lcc::traits::{Body, LoadRecord, Vault}; use lcc::{ + errors::VaultError, users::{Access, Token}, Generator, MetaDomain, Payload, Record, VaultMetadata, }; @@ -101,30 +102,32 @@ impl DataVault { self } - fn load(mut self) -> Option> { + fn load(mut self) -> Result, VaultError> { self.config = match VaultConfig::load(&self.fs.root) { Ok(cfg) => cfg, - _ => return None, + _ => return Err(VaultError::FailedLoading), }; - Some(Box::new(self)) + Ok(Box::new(self)) } } impl LoadRecord for DataVault {} impl Vault for DataVault { - fn new(gen: Generator) -> DataVault { - Self { - meta_info: ( - gen.name.clone().unwrap().into(), - gen.location.clone().unwrap().into(), - ), - records: HashMap::new(), - config: VaultConfig::new(), - metadata: HashMap::new(), - fs: Filesystem::new(&gen.location.unwrap(), &gen.name.unwrap()), - }.initialize() + fn new(gen: Generator) -> Result>, VaultError> { + Ok(Box::new( + Self { + meta_info: ( + gen.name.clone().unwrap().into(), + gen.location.clone().unwrap().into(), + ), + records: HashMap::new(), + config: VaultConfig::new(), + metadata: HashMap::new(), + fs: Filesystem::new(&gen.location.unwrap(), &gen.name.unwrap()), + }.initialize(), + )) } fn create_user( @@ -144,7 +147,7 @@ impl Vault for DataVault { // // If it's compatible we can open the vault into memory // (loading all required paths into the struct), then return it - fn load(name: &str, location: &str) -> Option> { + fn load(name: &str, location: &str) -> Result, VaultError> { Self { meta_info: (name.into(), location.into()), records: HashMap::new(), -- cgit v1.2.3