aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/meta.rs
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-06-10 21:32:21 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-06-10 21:32:21 +0200
commit152be3068866a39ef355276da2f906df1cbc5568 (patch)
tree2684e20bc558375157b687379d47389a6dc8c669 /lockchain-core/src/meta.rs
parentdc5c782b7e787dcf513ec54d6186d398d06e07cb (diff)
Actually adding new meta files
Diffstat (limited to 'lockchain-core/src/meta.rs')
-rw-r--r--lockchain-core/src/meta.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/lockchain-core/src/meta.rs b/lockchain-core/src/meta.rs
new file mode 100644
index 0000000..a602e48
--- /dev/null
+++ b/lockchain-core/src/meta.rs
@@ -0,0 +1,61 @@
+//! A cleartext metadata record for a vault metadata store
+//!
+//! This MetaItem uses a lot of the same traits and mechanisms
+//! as the normal Vault Record, without having to rely on encryption
+//! or trait base security.
+
+use record::Payload;
+use std::collections::HashMap;
+use traits::{AutoEncoder, Body};
+
+/// A metadomain is a simplified version of a cleartext record.
+///
+/// It is not encoded in special ways, it is not used in any way
+/// for secret information. All data inside a metadata file
+/// (for example, living inside the `metadata` folder of a vault)
+/// is public to all.
+///
+/// It can be used for things that need to be stored in encrypted form
+/// where the encryption key is never present. Or for simple authentication
+/// verification such as:
+///
+/// - User registry
+/// - Per-user encrypted primary keys
+/// - Usage statistics shared between clients
+///
+/// It implements a series of traits which means it's possible to easily
+/// interact with to store data.
+#[derive(Serialize, Deserialize)]
+pub struct MetaDomain {
+ /// The name of this meta domain
+ name: String,
+ body: HashMap<String, Payload>,
+}
+
+impl MetaDomain {
+ /// Return the domain name for easy comparison
+ pub fn name(&self) -> &str {
+ &self.name
+ }
+ /// Get the number of items in this domain
+ pub fn size(&self) -> usize {
+ self.body.len()
+ }
+}
+
+impl AutoEncoder for MetaDomain {}
+
+impl Body for MetaDomain {
+ fn get_field(&self, name: &str) -> Option<&Payload> {
+ self.body.get(name)
+ }
+
+ fn set_field(&mut self, key: &str, value: Payload) -> Option<()> {
+ self.body.insert(key.into(), value).map(|_| ())
+ }
+
+ /// Not implemented, always returns None
+ fn flatten(&mut self) -> Option<()> {
+ None
+ }
+}