Skip to content

Commit

Permalink
Merge pull request #35 from dsietz/development
Browse files Browse the repository at this point in the history
issue #34, 33
  • Loading branch information
dsietz authored Feb 27, 2020
2 parents b997943 + bbab49d commit fc8a0f0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pbd"
version = "0.1.1"
version = "0.1.2"
authors = ["dsietz <[email protected]>"]
edition = "2018"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions examples/postman/pbd.postman_collection.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -46,7 +46,7 @@
},
{
"key": "Data-Tracker-Chain",
"value": "W3siaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjAsInRpbWVzdGFtcCI6MCwiYWN0b3JfaWQiOiIifSwiaGFzaCI6IjE4NTUyODk4NTgzMDIzMDU2Njc2MDIzNjIwMzIyODU4OTI1MDU1NiIsInByZXZpb3VzX2hhc2giOiIwIiwibm9uY2UiOjV9LHsiaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjEsInRpbWVzdGFtcCI6MTU3ODA3MTIzOSwiYWN0b3JfaWQiOiJub3RpZmllcn5iaWxsaW5nfnJlY2VpcHR+ZW1haWwifSwiaGFzaCI6IjI5MTQ3MTk1MDE3MTgwNjM2Mjc5NTA5NzQzMTM0ODE5MTU1MTI0NyIsInByZXZpb3VzX2hhc2giOiIxODU1Mjg5ODU4MzAyMzA1NjY3NjAyMzYyMDMyMjg1ODkyNTA1NTYiLCJub25jZSI6NX1d",
"value": "W3siaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjAsInRpbWVzdGFtcCI6MCwiYWN0b3JfaWQiOiIiLCJwcmV2aW91c19oYXNoIjoiMCJ9LCJoYXNoIjoiMjcyMDgxNjk2NjExNDY0NzczNzI4MDI0OTI2NzkzNzAzMTY3NzgyIiwibm9uY2UiOjV9LHsiaWRlbnRpZmllciI6eyJkYXRhX2lkIjoib3JkZXJ+Y2xvdGhpbmd+aVN0b3JlfjE1MTUwIiwiaW5kZXgiOjEsInRpbWVzdGFtcCI6MTU3ODA3MTIzOSwiYWN0b3JfaWQiOiJub3RpZmllcn5iaWxsaW5nfnJlY2VpcHR+ZW1haWwiLCJwcmV2aW91c19oYXNoIjoiMjcyMDgxNjk2NjExNDY0NzczNzI4MDI0OTI2NzkzNzAzMTY3NzgyIn0sImhhc2giOiI1MDEwNDE0OTcwMTA5ODcwMDYzMjUxMTE0NDEyNTg2NzczNjE5MyIsIm5vbmNlIjo1fV0=",
"type": "text"
}
],
Expand Down
4 changes: 2 additions & 2 deletions src/dtc/extractor/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/dtc/middleware/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}]"#)
}


Expand Down
16 changes: 8 additions & 8 deletions src/dtc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit fc8a0f0

Please sign in to comment.