Skip to content

Commit

Permalink
Replace 'crypto' crate with 'sha2' (close snowplow-archive#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Leonard committed Oct 22, 2021
1 parent 8063b44 commit cdac8b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ chrono = "0.2"
colored = "1.2"
mustache = "0.7.0"
rand = "0.3"
rust-crypto = "^0.2"
uuid = { version = "0.2", features = ["v4"] }
hyper = "^0.10"
hyper-native-tls = "0.3.0"
libc = "0.2.17"
ifaces = "0.0.3"
dns-lookup = "0.2.1"
sha2 = "0.9.8"
19 changes: 9 additions & 10 deletions src/factotum/webhook/jobcontext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ mod tests;

use chrono::DateTime;
use chrono::UTC;
use crypto::digest::Digest;
use crypto::sha2::Sha256;
use rustc_serialize::base64::{ToBase64, MIME};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use uuid::Uuid;

Expand All @@ -43,22 +42,22 @@ impl JobContext {
let ff = factfile;

let mut job_digest = Sha256::new();
job_digest.input_str(&ff);
job_digest.update(&ff);

if let Some(ref tags_map) = tags {
let mut sorted_keys: Vec<_> = tags_map.keys().collect();
sorted_keys.sort();
for key in sorted_keys {
job_digest.input_str(key);
job_digest.input_str(&tags_map[key]);
job_digest.update(key);
job_digest.update(&tags_map[key]);
}
}

let job_ref = job_digest.result_str();
let job_ref = job_digest.finalize();

let mut run_digest = Sha256::new();
run_digest.input_str(&format!("{}", Uuid::new_v4()));
let run_ref = run_digest.result_str();
run_digest.update(&format!("{}", Uuid::new_v4()));
let run_ref = run_digest.finalize();

let mut config = MIME;
config.line_length = None;
Expand All @@ -72,8 +71,8 @@ impl JobContext {

JobContext {
job_name: job_name.into(),
job_reference: job_ref,
run_reference: run_ref,
job_reference: format!("{:x}", job_ref),
run_reference: format!("{:x}", run_ref),
factfile: b64_ff,
factotum_version: env!("CARGO_PKG_VERSION").to_string(),
start_time: UTC::now(),
Expand Down
28 changes: 13 additions & 15 deletions src/factotum/webhook/jobcontext/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
use super::*;

use chrono::UTC;
use crypto::digest::Digest;
use crypto::sha2::Sha256;
use rustc_serialize::base64::{ToBase64, MIME};
use sha2::{Digest, Sha256};
use std::collections::HashMap;

#[test]
Expand All @@ -41,12 +40,12 @@ fn new_sets_job_ref_to_hash_of_factfile() {
let job_name = "hello";
let factfile_sim = "{Blabla}";
let mut digest = Sha256::new();
digest.input_str(factfile_sim);
let expected = digest.result_str();
digest.update(factfile_sim);
let expected = digest.finalize();

let context = JobContext::new(job_name, factfile_sim, None);

assert_eq!(context.job_reference, expected);
assert_eq!(context.job_reference, format!("{:x}", expected));
}

#[test]
Expand Down Expand Up @@ -97,18 +96,17 @@ fn tags_are_used_in_job_hash() {
tags.insert("a".into(), "b".into());

let mut digest = Sha256::new();
digest.input_str(factfile_sim);
digest.update(factfile_sim);

digest.input_str("a"); // NB the keys are sorted so the output is reproducible!
digest.input_str("b");
digest.input_str("hello");
digest.input_str("world");
digest.input_str("z");
digest.input_str("sdfsdfs");
digest.update("a"); // NB the keys are sorted so the output is reproducible!
digest.update("b");
digest.update("hello");
digest.update("world");
digest.update("z");
digest.update("sdfsdfs");

let expected = digest.result_str();
let expected = digest.finalize();

let context = JobContext::new(job_name, factfile_sim, Some(tags.clone()));

assert_eq!(context.job_reference, expected);
assert_eq!(context.job_reference, format!("{:x}", expected));
}
2 changes: 1 addition & 1 deletion src/factotum/webhook/jobupdate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use factotum::executor::{
};
use rustc_serialize;
use rustc_serialize::json::{self, Json, ToJson};
use rustc_serialize::Encodable;
use rustc_serialize::{Decodable, Encodable};
use std::collections::BTreeMap;
use std::collections::HashMap;

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
extern crate log;
extern crate chrono;
extern crate colored;
extern crate crypto;
extern crate daggy;
extern crate dns_lookup;
extern crate docopt;
Expand All @@ -27,6 +26,7 @@ extern crate libc;
extern crate log4rs;
extern crate rand;
extern crate rustc_serialize;
extern crate sha2;
extern crate uuid;
extern crate valico;

Expand Down

0 comments on commit cdac8b5

Please sign in to comment.