diff options
author | Katharina Sabel <katharina.sabel@asquera.de> | 2018-05-07 23:39:10 +0200 |
---|---|---|
committer | Katharina Sabel <katharina.sabel@asquera.de> | 2018-05-07 23:39:10 +0200 |
commit | 3c4030f8fd00c6445731bb102169b4b6b5d6d70e (patch) | |
tree | 0bed36e056d30527105d85eee4afc6e3a99af4e4 /lockchain-crypto/src | |
parent | 94c58c0060d243c162b07dd002cb779aec44e153 (diff) |
Shuffling some stuff around and implementing some traits
Diffstat (limited to 'lockchain-crypto/src')
-rw-r--r-- | lockchain-crypto/src/lib.rs | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/lockchain-crypto/src/lib.rs b/lockchain-crypto/src/lib.rs index 31e1bb2..5648106 100644 --- a/lockchain-crypto/src/lib.rs +++ b/lockchain-crypto/src/lib.rs @@ -1,7 +1,42 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); +//! + +#[macro_use] +extern crate serde_derive; +extern crate serde; + +extern crate lockchain_core as lcc; + +use lcc::{Payload, EncryptedBody}; +use lcc::traits::{Body, AutoEncoder, Base64AutoEncoder, Encryption}; + +use std::collections::BTreeMap; + +#[derive(Serialize, Deserialize)] +pub struct DataBody { + tree: BTreeMap<String, Payload>, +} + +impl AutoEncoder for DataBody {} + +impl Body for DataBody { + fn get_field(&self, key: &str) -> Option<&Payload> { + self.tree.get(key).as_ref()? + } + + fn set_field(&mut self, key: &str, value: Payload) -> Option<()> { + self.tree.insert(key, value); + Some(()) + } + + fn flatten(&mut self) -> Option<()> { + None } } + +impl Encryption for DataBody { + fn encrypt(&mut self) -> EncryptedBody { + EncryptedBody { + cipher: self.encode() + } + } +}
\ No newline at end of file |