aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-09-08 23:33:22 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-09-08 23:33:22 +0200
commitc352fd1c6b5b7119dfa9cc8eb642aa3ee7127a01 (patch)
treebe59e8c0e0ebfc673fef04c342837c2e41aec1ea
parentddebbc0b7f45eaf07a2242fd91f1a92ee27099a9 (diff)
Assorted code fixes
-rw-r--r--lockchain-core/src/init.rs2
-rw-r--r--lockchain-core/src/lib.rs4
-rw-r--r--lockchain-files/examples/create.rs10
-rw-r--r--lockchain-files/src/lib.rs33
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>,
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<EncryptedBody> = Generator::new().path(name, path).finalise();
+ let mut vault: DataVault<EncryptedBody> = Generator::new()
+ .path(name, path)
+ .user_type(VaultType::SoloUser {
+ username: "spacekookie".into(),
+ secret: "foobar3264".into(),
+ }).finalise()
+ .unwrap();
vault.sync();
// let vault: DataVault<EncryptedBody> = 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<T: Body> DataVault<T> {
self
}
- fn load(mut self) -> Option<Box<Self>> {
+ fn load(mut self) -> Result<Box<Self>, 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<T: Body> LoadRecord<T> for DataVault<T> {}
impl<T: Body> Vault<T> for DataVault<T> {
- fn new(gen: Generator) -> DataVault<T> {
- 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<Box<DataVault<T>>, 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<T: Body> Vault<T> for DataVault<T> {
//
// 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<Box<Self>> {
+ fn load(name: &str, location: &str) -> Result<Box<Self>, VaultError> {
Self {
meta_info: (name.into(), location.into()),
records: HashMap::new(),