aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-09-06 20:28:04 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-09-06 20:28:04 +0200
commitddebbc0b7f45eaf07a2242fd91f1a92ee27099a9 (patch)
tree6ce7b1313f4e94f43c02102546b5f2440aed87de
parentf3824b79256133374aacd910f34ed2764640b1b7 (diff)
Changing the vault trait to use Result<_, VaultError> more liberally
-rw-r--r--lockchain-core/src/errors/vault.rs4
-rw-r--r--lockchain-core/src/init.rs3
-rw-r--r--lockchain-core/src/traits.rs7
3 files changed, 10 insertions, 4 deletions
diff --git a/lockchain-core/src/errors/vault.rs b/lockchain-core/src/errors/vault.rs
index bcfcd13..37d8662 100644
--- a/lockchain-core/src/errors/vault.rs
+++ b/lockchain-core/src/errors/vault.rs
@@ -5,6 +5,10 @@ use std::fmt::{Display, Formatter, Result};
#[derive(Debug, Serialize, Deserialize)]
pub enum Error {
+ /// Indicates that **mandatory** fields in the
+ /// vault generator haven't been set – vault
+ /// constructor was never called.
+ IncompleteGenerator,
/// A vault already exists with that path-id
AlreadyExists,
/// The provided path is invalid
diff --git a/lockchain-core/src/init.rs b/lockchain-core/src/init.rs
index f7f2d5d..bf40518 100644
--- a/lockchain-core/src/init.rs
+++ b/lockchain-core/src/init.rs
@@ -1,4 +1,5 @@
use traits::{Body, Vault};
+use errors::VaultError;
/// Describes the internal permission layout of a vault
pub enum VaultType {
@@ -69,7 +70,7 @@ impl Generator {
}
/// Finally call this function to construct the vault
- pub fn finalise<V, B>(self) -> V
+ pub fn finalise<V, B>(self) -> Result<V, VaultError>
where
V: Vault<B>,
B: Body,
diff --git a/lockchain-core/src/traits.rs b/lockchain-core/src/traits.rs
index efde578..13fc1b3 100644
--- a/lockchain-core/src/traits.rs
+++ b/lockchain-core/src/traits.rs
@@ -11,7 +11,8 @@
//! compilation work without external crates but not calling
//! functions at runtime.
-use initialise::Generator;
+use errors::VaultError;
+use init::Generator;
use meta::{MetaDomain, VaultMetadata};
use record::{EncryptedBody, Header, Payload, Record};
use serde::{de::DeserializeOwned, Serialize};
@@ -123,9 +124,9 @@ where
T: Body,
{
/// Consumes a vault generator to construct a vault
- fn new(cfg: Generator) -> Self;
+ fn new(Generator) -> Result<Box<Self>, VaultError>;
/// Load and open an existing vault
- fn load(name: &str, location: &str) -> Option<Box<Self>>;
+ fn load(name: &str, location: &str) -> Result<Box<Self>, VaultError>;
/// Unlock the vault for a specific user
fn authenticate(&mut self, username: &str, secret: &str) -> Token;
/// End a specific user session