diff options
author | Teddy Wing | 2018-11-10 15:00:45 +0100 |
---|---|---|
committer | Teddy Wing | 2018-11-10 15:00:45 +0100 |
commit | 8edf2808e1b2f11ecb5e395452886e98ce8acb18 (patch) | |
tree | e3c7729cfa655d32fa2ae12496480aeda450a8cc /license-generator/src/params.rs | |
parent | d87ed40cd99f6c7dae019cc13b0a16db65d847e5 (diff) | |
download | dome-key-web-8edf2808e1b2f11ecb5e395452886e98ce8acb18.tar.bz2 |
Add a helper function to verify webhook requests
The new `request::verified()` takes POST params as a string as does all
the work needed to call `paddle::verify_signature()`.
This involves extracting the `p_signature` POST parameter to get the
signature, and getting the public key PEM.
Change `params::parse()` to return a
`BTreeMap<Cow<'a, str>, Cow<'a, str>>` instead of `String` keys &
values. This is because `paddle::verify_signature()` needs a `(<&str,
&str)` iterator. Actually, it still doesn't solve the problem because
the types don't match. We need to modify the input type of
`verify_signature()`, but at least this change gives us references.
Make `params` private to the crate because we no longer need to use it
in `main()`.
Diffstat (limited to 'license-generator/src/params.rs')
-rw-r--r-- | license-generator/src/params.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/license-generator/src/params.rs b/license-generator/src/params.rs index 80136c2..1b234e7 100644 --- a/license-generator/src/params.rs +++ b/license-generator/src/params.rs @@ -1,9 +1,10 @@ +use std::borrow::Cow; use std::collections::BTreeMap; use url::form_urlencoded; -pub fn parse(params: &str) -> BTreeMap<String, String> { - let iter = form_urlencoded::parse(params.as_bytes()).into_owned(); +pub(crate) fn parse<'a>(params: &'a str) -> BTreeMap<Cow<'a, str>, Cow<'a, str>> { + let iter = form_urlencoded::parse(params.as_bytes()); let mut dict = BTreeMap::new(); for (key, value) in iter { |