diff options
author | Katharina Fey <kookie@spacekookie.de> | 2018-06-10 20:32:38 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2018-06-10 20:32:38 +0200 |
commit | 28b2a6b9eda45946ffd52020ed4f772ad18b9616 (patch) | |
tree | 2e9e7194d035efe3fc4ee0b6fe1532b1b07f9473 | |
parent | 9a30f0d6036dd8c15cffce11830180fb02529887 (diff) |
Removing User & Login traits from core, adding a metadata store to take their place
-rw-r--r-- | lockchain-core/src/crypto/data.rs | 8 | ||||
-rw-r--r-- | lockchain-core/src/crypto/utils.rs | 1 | ||||
-rw-r--r-- | lockchain-core/src/lib.rs | 4 | ||||
-rw-r--r-- | lockchain-core/src/traits.rs | 18 | ||||
-rw-r--r-- | lockchain-core/src/users.rs | 24 | ||||
-rw-r--r-- | lockchain-http/src/handlers.rs | 2 | ||||
-rw-r--r-- | lockchain-http/src/lib.rs | 9 | ||||
-rw-r--r-- | lockchain-http/src/model.rs | 7 |
8 files changed, 35 insertions, 38 deletions
diff --git a/lockchain-core/src/crypto/data.rs b/lockchain-core/src/crypto/data.rs index b87f0dc..2ee8a9a 100644 --- a/lockchain-core/src/crypto/data.rs +++ b/lockchain-core/src/crypto/data.rs @@ -1,10 +1,10 @@ use traits::AutoEncoder; -/// Represents some encrypted packed data +/// Representation of encrypted data as an enecoded format /// -/// Includes nonce, vault iv and blob. This abstraction -/// is important to be able to send encrypted records across -/// a network. +/// Includes all cryptographic state primitives that are +/// required to send the data over a network and decrypt on +/// the other side of a pipe. #[derive(Serialize, Deserialize)] pub struct PackedData { pub nonce: Vec<u8>, diff --git a/lockchain-core/src/crypto/utils.rs b/lockchain-core/src/crypto/utils.rs index a8ae7c0..192703f 100644 --- a/lockchain-core/src/crypto/utils.rs +++ b/lockchain-core/src/crypto/utils.rs @@ -86,6 +86,7 @@ pub mod random { return vec; } + /// A small utility wraper around bcrypt to allow /// easy password checking. pub mod passwd { diff --git a/lockchain-core/src/lib.rs b/lockchain-core/src/lib.rs index 8661894..abf72c3 100644 --- a/lockchain-core/src/lib.rs +++ b/lockchain-core/src/lib.rs @@ -16,9 +16,9 @@ extern crate rand; pub mod errors; pub mod traits; pub mod crypto; -mod users; +mod meta; mod record; pub use self::crypto::PackedData; pub use self::record::{Header, Payload, Record, EncryptedBody}; -pub use self::users::User; +pub use self::meta::MetaDomain;
\ No newline at end of file diff --git a/lockchain-core/src/traits.rs b/lockchain-core/src/traits.rs index 5e9ab13..671843d 100644 --- a/lockchain-core/src/traits.rs +++ b/lockchain-core/src/traits.rs @@ -13,7 +13,7 @@ use record::{EncryptedBody, Header, Payload, Record}; use serde::{de::DeserializeOwned, Serialize}; -use users::User; +use meta::MetaDomain; use base64; use serde_json::{self, Error as SerdeError}; @@ -43,11 +43,6 @@ pub trait LoadRecord<T: Body> { } } -pub trait UserLogin { - /// Login a user and return it with a token - fn login(name: &str, password: &str, salt: &str) -> Option<User>; -} - /// A set of utility function that need to be implemented in order /// for a type to be encryptable or decryptable. pub trait Encryptable: AutoEncoder {} @@ -111,6 +106,17 @@ where fn add_data(&mut self, record: &str, key: &str, data: Payload) -> Option<()>; /// Get the (latest) value of a specific record data field fn get_data(&self, record: &str, key: &str) -> Option<&Payload>; + /// Adds a domain space to the metadata store inside the vault + /// + /// A domain is a collection metadata files that can be + /// returned with a single pull request + fn meta_add_domain(&mut self, domain: &str) -> Option<()>; + /// Returns all records from a meta domain + fn meta_pull_domain(&mut self, domain: &str) -> Option<Vec<MetaDomain>>; + /// Set the value of a field inside a domain. Field names **must not** collide + fn meta_set(&mut self, domain: &str, name: &str, data: Payload) -> Option<()>; + /// Get the value of a (unique) field inside a domain + fn meta_get(&mut self, domain: &str, name: &str) -> Option<Payload>; } /// Auto-implement this trait to serialise types to json diff --git a/lockchain-core/src/users.rs b/lockchain-core/src/users.rs deleted file mode 100644 index fb83283..0000000 --- a/lockchain-core/src/users.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! A commonly used user-abstraction for the lockchain ecosystem - -use bcrypt::{self, DEFAULT_COST}; - -/// Simple user authentication abstraction -#[allow(dead_code)] -pub struct User { - name: String, - pw_hash: String, - pw_salt: String, - token: Option<String>, -} - -impl User { - /// - pub fn register(name: &str, password: &str, salt: &str) -> Option<User> { - Some(User { - name: name.to_owned(), - pw_hash: bcrypt::hash(&format!("{}{}", password, salt), DEFAULT_COST).ok()?, - pw_salt: salt.to_owned(), - token: None, - }) - } -} diff --git a/lockchain-http/src/handlers.rs b/lockchain-http/src/handlers.rs index 64d0b8a..77bc823 100644 --- a/lockchain-http/src/handlers.rs +++ b/lockchain-http/src/handlers.rs @@ -12,6 +12,8 @@ use std::sync::{Arc, Mutex}; type HttpRequestState<T> = HttpRequest<Arc<Mutex<T>>>; /// PUT /vault +/// +/// Check the documentation for more information about how to provide payloads pub fn create_vault<B: Body>(_req: HttpRequestState<impl Vault<B>>) -> impl Responder { format!("Unimplemented!") } diff --git a/lockchain-http/src/lib.rs b/lockchain-http/src/lib.rs index 5192de2..a3872e1 100644 --- a/lockchain-http/src/lib.rs +++ b/lockchain-http/src/lib.rs @@ -10,6 +10,9 @@ //! //! Ideally this shim-layer version should be the same as the `lockchain-core` it binds //! against, however especially during development this won't always be the case. +//! +//! **Note**: API endpoint documentation can be found +//! [here](https://github.com/spacekookie/lockchain/tree/master/lockchain-http#api-reference) #[macro_use] extern crate serde_derive; @@ -23,7 +26,7 @@ mod handlers; mod model; pub use model::CarrierMessage; -use actix_web::{server, App}; +use actix_web::{http, server, App}; use lockchain::traits::{Body, Vault}; use std::sync::{Arc, Mutex}; @@ -58,7 +61,9 @@ pub fn create_server<B: Body + 'static>( server::new(move || { vec![ App::with_state(Arc::clone(&state)) - .resource("/vault", |r| r.f(handlers::create_vault)) + .resource("/vault", |r| { + r.method(http::Method::PUT).with(handlers::create_vault) + }) .resource("/vault/{vaultid}", |r| r.f(handlers::update_vault)) .resource("/vault/{vaultid}", |r| r.f(handlers::delete_vault)) .resource("/vault/{vaultid}/records/{recordid}", |r| { diff --git a/lockchain-http/src/model.rs b/lockchain-http/src/model.rs index c775ee6..f9e2665 100644 --- a/lockchain-http/src/model.rs +++ b/lockchain-http/src/model.rs @@ -14,3 +14,10 @@ pub struct CarrierMessage<T: Serialize + DeserializeOwned> { #[serde(bound(deserialize = "T: Serialize + DeserializeOwned"))] pub data: Option<T>, } + +/// Fields provided when creating a new vault +#[derive(Serialize, Deserialize)] +pub struct VaultCreate { + name: String, + location: String, +} |