From bbab49d4415defa9043eef9575b7d8f8a694c745 Mon Sep 17 00:00:00 2001 From: dsietz Date: Wed, 26 Feb 2020 18:47:16 -0500 Subject: [PATCH] issue #34, 33 --- Cargo.toml | 2 +- examples/postman/pbd.postman_collection.json | 4 ++-- src/dtc/extractor/actix.rs | 4 ++-- src/dtc/middleware/actix.rs | 4 ++-- src/dtc/mod.rs | 16 ++++++++-------- src/lib.rs | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3da16a1..5662cf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pbd" -version = "0.1.1" +version = "0.1.2" authors = ["dsietz "] edition = "2018" readme = "README.md" diff --git a/examples/postman/pbd.postman_collection.json b/examples/postman/pbd.postman_collection.json index 62ddfcd..13bb4d4 100644 --- a/examples/postman/pbd.postman_collection.json +++ b/examples/postman/pbd.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "6a15bfc9-3330-4266-bf05-7b2da4166221", + "_postman_id": "c192d80a-addd-4d68-9af3-23ad9390ca0d", "name": "pbd", "description": "Privacy by Design", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" @@ -46,7 +46,7 @@ }, { "key": "Data-Tracker-Chain", - "value": "W3siaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjAsInRpbWVzdGFtcCI6MCwiYWN0b3JfaWQiOiIifSwiaGFzaCI6IjE4NTUyODk4NTgzMDIzMDU2Njc2MDIzNjIwMzIyODU4OTI1MDU1NiIsInByZXZpb3VzX2hhc2giOiIwIiwibm9uY2UiOjV9LHsiaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjEsInRpbWVzdGFtcCI6MTU3ODA3MTIzOSwiYWN0b3JfaWQiOiJub3RpZmllcn5iaWxsaW5nfnJlY2VpcHR+ZW1haWwifSwiaGFzaCI6IjI5MTQ3MTk1MDE3MTgwNjM2Mjc5NTA5NzQzMTM0ODE5MTU1MTI0NyIsInByZXZpb3VzX2hhc2giOiIxODU1Mjg5ODU4MzAyMzA1NjY3NjAyMzYyMDMyMjg1ODkyNTA1NTYiLCJub25jZSI6NX1d", + "value": "W3siaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjAsInRpbWVzdGFtcCI6MCwiYWN0b3JfaWQiOiIiLCJwcmV2aW91c19oYXNoIjoiMCJ9LCJoYXNoIjoiMjcyMDgxNjk2NjExNDY0NzczNzI4MDI0OTI2NzkzNzAzMTY3NzgyIiwibm9uY2UiOjV9LHsiaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjEsInRpbWVzdGFtcCI6MTU3ODA3MTIzOSwiYWN0b3JfaWQiOiJub3RpZmllcn5iaWxsaW5nfnJlY2VpcHR+ZW1haWwiLCJwcmV2aW91c19oYXNoIjoiMjcyMDgxNjk2NjExNDY0NzczNzI4MDI0OTI2NzkzNzAzMTY3NzgyIn0sImhhc2giOiI1MDEwNDE0OTcwMTA5ODcwMDYzMjUxMTE0NDEyNTg2NzczNjE5MyIsIm5vbmNlIjo1fV0=", "type": "text" } ], diff --git a/src/dtc/extractor/actix.rs b/src/dtc/extractor/actix.rs index 37449a8..6997524 100644 --- a/src/dtc/extractor/actix.rs +++ b/src/dtc/extractor/actix.rs @@ -76,7 +76,7 @@ impl TrackerHeader for Tracker { /// /// fn main() { /// // NOTE: The header value must be Base64 encoded - /// let header_value = HeaderValue::from_static("W3siaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjAsInRpbWVzdGFtcCI6MCwiYWN0b3JfaWQiOiIifSwiaGFzaCI6IjE4NTUyODk4NTgzMDIzMDU2Njc2MDIzNjIwMzIyODU4OTI1MDU1NiIsInByZXZpb3VzX2hhc2giOiIwIiwibm9uY2UiOjV9XQ=="); + /// let header_value = HeaderValue::from_static("W3siaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjAsInRpbWVzdGFtcCI6MCwiYWN0b3JfaWQiOiIiLCJwcmV2aW91c19oYXNoIjoiMCJ9LCJoYXNoIjoiMjcyMDgxNjk2NjExNDY0NzczNzI4MDI0OTI2NzkzNzAzMTY3NzgyIiwibm9uY2UiOjV9XQ=="); /// let tracker = Tracker::tracker_from_header_value(&header_value); /// /// assert!(tracker.is_ok()); @@ -137,7 +137,7 @@ mod tests { // supporting functions fn get_dtc_header() -> String{ - base64::encode(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":""},"hash":"185528985830230566760236203228589250556","previous_hash":"0","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email"},"hash":"291471950171806362795097431348191551247","previous_hash":"185528985830230566760236203228589250556","nonce":5}]"#) + base64::encode(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":"","previous_hash":"0"},"hash":"272081696611464773728024926793703167782","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email","previous_hash":"272081696611464773728024926793703167782"},"hash":"50104149701098700632511144125867736193","nonce":5}]"#) } fn index(_req: HttpRequest) -> HttpResponse { diff --git a/src/dtc/middleware/actix.rs b/src/dtc/middleware/actix.rs index 8beb216..02ce247 100644 --- a/src/dtc/middleware/actix.rs +++ b/src/dtc/middleware/actix.rs @@ -193,11 +193,11 @@ mod tests { // supporting functions fn get_dtc_header() -> String{ - base64::encode(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":""},"hash":"185528985830230566760236203228589250556","previous_hash":"0","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email"},"hash":"291471950171806362795097431348191551247","previous_hash":"185528985830230566760236203228589250556","nonce":5}]"#) + base64::encode(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":"","previous_hash":"0"},"hash":"272081696611464773728024926793703167782","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email","previous_hash":"272081696611464773728024926793703167782"},"hash":"50104149701098700632511144125867736193","nonce":5}]"#) } fn get_dtc_header_invalid() -> String{ - base64::encode(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":""},"hash":"185528985830230566760236203228589250556","previous_hash":"0","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email"},"hash":"291471950171806362795097431348191551247","previous_hash":"185528985830230566760236203228589250557","nonce":5}]"#) + base64::encode(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":"","previous_hash":"0"},"hash":"272081696611464773728024926793703167784","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email","previous_hash":"272081696611464773728024926793703167782"},"hash":"50104149701098700632511144125867736193","nonce":5}]"#) } diff --git a/src/dtc/mod.rs b/src/dtc/mod.rs index 1593e64..04386fd 100644 --- a/src/dtc/mod.rs +++ b/src/dtc/mod.rs @@ -76,7 +76,9 @@ pub struct MarkerIdentifier { // The date and time (Unix timestamp) the data came into posession of the Actor, (1578071239) pub timestamp: u64, /// The unique identifier of the Actor who touched the data, (e.g.: notifier~billing~receipt~email) - pub actor_id: String, + pub actor_id: String, + /// The identifying hash of the previous Marker in the Data Tracker Chain + pub previous_hash: String, } impl MarkerIdentifier { @@ -107,8 +109,6 @@ pub struct Marker { pub identifier: MarkerIdentifier, /// The identifying hash of the Marker pub hash: String, - /// The identifying hash of the previous Marker in the Data Tracker Chain - pub previous_hash: String, /// The difficulty of the Proof of Work nonce: u128, } @@ -143,12 +143,12 @@ impl Marker { index: idx, timestamp: tmstp, actor_id: act_id, + previous_hash: prev_hash, }; Marker { identifier: idfy.clone(), hash: Marker::calculate_hash(idfy, DIFFICULTY).result, - previous_hash: prev_hash, nonce: DIFFICULTY, } } @@ -182,12 +182,12 @@ impl Marker { index: 0, timestamp: 0, actor_id: "".to_string(), + previous_hash: "0".to_string(), }; Marker { identifier: idfy.clone(), hash: Marker::calculate_hash(idfy, DIFFICULTY).result, - previous_hash: "0".to_string(), nonce: DIFFICULTY, } } @@ -293,7 +293,7 @@ impl Tracker { /// use pbd::dtc::Tracker; /// /// fn main() { - /// let tracker = Tracker::from_serialized(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":""},"hash":"185528985830230566760236203228589250556","previous_hash":"0","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email"},"hash":"291471950171806362795097431348191551247","previous_hash":"185528985830230566760236203228589250556","nonce":5}]"#); + /// let tracker = Tracker::from_serialized(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":"","previous_hash":"0"},"hash":"272081696611464773728024926793703167782","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email","previous_hash":"272081696611464773728024926793703167782"},"hash":"50104149701098700632511144125867736193","nonce":5}]"#); /// /// // unwrap() to get the Tracker is Result is Ok /// assert!(tracker.is_ok()); @@ -365,7 +365,7 @@ impl Tracker { } // make sure the relationship with the prior Marker hasn't been altered - if m > 0 && marker.previous_hash != self.chain.clone()[m-1].hash { + if m > 0 && marker.identifier.previous_hash != self.chain.clone()[m-1].hash { return false; } } @@ -463,7 +463,7 @@ mod tests { #[test] fn test_markerchain_from_serialized() { - let mkrchn = Tracker::from_serialized(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":""},"hash":"185528985830230566760236203228589250556","previous_hash":"0","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email"},"hash":"291471950171806362795097431348191551247","previous_hash":"185528985830230566760236203228589250556","nonce":5}]"#); + let mkrchn = Tracker::from_serialized(r#"[{"identifier":{"data_id":"order~clothing~iStore~15150","index":0,"timestamp":0,"actor_id":"","previous_hash":"0"},"hash":"272081696611464773728024926793703167782","nonce":5},{"identifier":{"data_id":"order~clothing~iStore~15150","index":1,"timestamp":1578071239,"actor_id":"notifier~billing~receipt~email","previous_hash":"272081696611464773728024926793703167782"},"hash":"50104149701098700632511144125867736193","nonce":5}]"#); assert!(mkrchn.is_ok()); } diff --git a/src/lib.rs b/src/lib.rs index 89e0eed..45a471b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ //! //! #### Usage //! -//! This crate follows the [privacy design strategies and tactics](./docs/DESIGN-STRATEGIES.md) and is broken down into aligned features. +//! This crate follows the [privacy design strategies and tactics](https://github.com/dsietz/pbd/blob/master/docs/DESIGN-STRATEGIES.md) and is broken down into aligned features. //! These features can be specified in Cargo.toml as a dependency. //! //! >[dependencies.pbd]