aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-05 17:21:28 +0100
committerTeddy Wing2018-11-05 17:21:28 +0100
commit60ad613c7ca8abfcdc5f83d50c3c64c2385296bb (patch)
tree856a9b3b2664f9ff96e99f66688a16d4249739ad
parentd064a73d6befb4119934a3e3c8b19698d9a780cd (diff)
downloaddome-key-web-60ad613c7ca8abfcdc5f83d50c3c64c2385296bb.tar.bz2
AquaticPrime::sign(): Collect input data values into a string
Collect values from the `HashMap` into a single string. Following the example of the Aquatic Prime PHP and Ruby scripts. Thanks to these Stack Overflow answers for explaining `into_iter()`: https://stackoverflow.com/questions/32354947/type-issue-with-iterator-collect/32355408#32355408 https://stackoverflow.com/questions/32354947/type-issue-with-iterator-collect/32355169#32355169 Otherwise I was getting double string references (`(&&str, &&str)`) from `iter()`. In order to get the `&str` and `iter` references right, take an owned `HashMap` argument instead of a reference as planned earlier. Makes it simpler to manipulate the `&str`s inside.
-rw-r--r--license-generator/aquatic-prime/src/lib.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/license-generator/aquatic-prime/src/lib.rs b/license-generator/aquatic-prime/src/lib.rs
index 4df34bc..f92ad30 100644
--- a/license-generator/aquatic-prime/src/lib.rs
+++ b/license-generator/aquatic-prime/src/lib.rs
@@ -8,7 +8,20 @@ struct AquaticPrime<'a> {
}
impl<'a> AquaticPrime<'a> {
- fn sign(&self, input_data: &HashMap<&str, &str>) -> String {
+ fn sign(&self, input_data: HashMap<&str, &str>) -> String {
+ let mut input_data: Vec<(&str, &str)> = input_data
+ .into_iter()
+ .collect();
+ input_data.sort();
+
+ let data = input_data
+ .into_iter()
+ .map(|(k, v)| v)
+ .collect::<Vec<&str>>()
+ .concat();
+
+ println!("{:?}", data);
+
String::new()
}
}
@@ -32,7 +45,7 @@ mod tests {
license_data.insert("Email", "user@email.com");
license_data.insert("Name", "User");
- let signature = aquatic_prime.sign(&license_data);
+ let signature = aquatic_prime.sign(license_data);
let expected = "Nhe6U/8XCMm7/+2OIzrHjcOsYHNZTg4k8nTajp1dTb+pU5H1cybgQzUJYA1n3IIQAbWe \
qD7a48WFqbzC3powTk6x42b+WpH6boe+u7LW4AXo2ZqGPasVlr1/lUWVHvt5J0OI9oR7 \
@@ -46,7 +59,7 @@ mod tests {
license_data.insert("Name", "Üsér Diacriticà");
license_data.insert("lowercase key", "Keys should be sorted case-insensitive");
- let signature = aquatic_prime.sign(&license_data);
+ let signature = aquatic_prime.sign(license_data);
let expected = "RIhF/3CgyXzPg2wCQ5LShf6W9khtqPcqUDLAHcAZdOIcoeR7PoOHi15423kxq5jOh1lm \
cztBoUJFu8mB45MHE0jmmbRw3qK6FJz9Py2gi1XvGOgH3GW713OCvQBE7vfBj4ZriP0+ \