diff options
| author | Teddy Wing | 2018-11-10 20:39:48 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-11-10 20:39:48 +0100 | 
| commit | 20f7a268cce05cd63842adbc7a5d05d4d4cc5bc7 (patch) | |
| tree | 4b7f5318f7ca07ab6087295510776c02a684a28c /license-generator/src | |
| parent | d2587251a9b1b1d4d8f887fe079a3e0bbc017de8 (diff) | |
| download | dome-key-web-20f7a268cce05cd63842adbc7a5d05d4d4cc5bc7.tar.bz2 | |
paddle::verify_signature(): Extract signature from params
Make it easier on users by not requiring them to pass a signature into
the method. This means they don't have to extract the `p_signature`
param and base64 decode it themselves.
Essentially, we want to move the code from `request` that removes the
`p_signature` key and base64 decodes it into the
`paddle::verify_signature()` function.
We need to make the string-like type params in `verify_signature()`
conform additionally to `PartialEq<str>` and `PartialOrd`. Doing so
allows us to find the key "p_signature".
To remove the `p_signature` param from the iterator, we partition it
into two iterators: one for the `p_signature` entry, and another for the
rest. We then extract the value of `p_signature` and base64 decode it
for verification.
Add a new error type in case no `p_signature` entry is found in the
iterator.
Diffstat (limited to 'license-generator/src')
| -rw-r--r-- | license-generator/src/errors.rs | 2 | ||||
| -rw-r--r-- | license-generator/src/lib.rs | 2 | ||||
| -rw-r--r-- | license-generator/src/request.rs | 12 | 
3 files changed, 2 insertions, 14 deletions
| diff --git a/license-generator/src/errors.rs b/license-generator/src/errors.rs index e21edd4..0799c3e 100644 --- a/license-generator/src/errors.rs +++ b/license-generator/src/errors.rs @@ -1,4 +1,3 @@ -use base64;  use log;  use mysql;  use paddle; @@ -8,7 +7,6 @@ error_chain! {          EnvVar(::std::env::VarError);          Io(::std::io::Error); -        Base64(base64::DecodeError);          Log(log::SetLoggerError);          MySql(mysql::error::Error); diff --git a/license-generator/src/lib.rs b/license-generator/src/lib.rs index e2c02b6..bf3ed57 100644 --- a/license-generator/src/lib.rs +++ b/license-generator/src/lib.rs @@ -1,5 +1,3 @@ -extern crate base64; -  #[macro_use]  extern crate error_chain;  extern crate log; diff --git a/license-generator/src/request.rs b/license-generator/src/request.rs index 325fdec..190a756 100644 --- a/license-generator/src/request.rs +++ b/license-generator/src/request.rs @@ -1,19 +1,11 @@ -use base64;  use paddle;  use errors::*;  use params;  pub fn verified(req_params: &str) -> Result<bool> { -    let mut p = params::parse(&req_params); -    let signature = p.remove("p_signature"); +    let p = params::parse(&req_params);      let pem = include_bytes!("../private/paddle.pubkey.asc"); -    match signature { -        Some(signature) => { -            let signature = base64::decode(signature.as_bytes())?; -            Ok(paddle::verify_signature(pem, &signature, p)?) -        }, -        None => Ok(false), -    } +    Ok(paddle::verify_signature(pem, p)?)  } | 
