aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-11-06 02:36:06 +0100
committerTeddy Wing2018-11-06 02:36:06 +0100
commit4aa1c293b4deb97e588268bbd00949d12a26135e (patch)
tree7bed6bae2908400539e11ea8f254d69a8ac946cb
parentab1c6cedb642263ba25812457e60c4e7b1464f0b (diff)
downloaddome-key-web-4aa1c293b4deb97e588268bbd00949d12a26135e.tar.bz2
AquaticPrime::sign(): Return an error if public key != 1024 bits
This check was reproduced from Aquatic Prime's C signature generator: https://github.com/bdrister/AquaticPrime/blob/master/Source/PHP/AquaticPrimeCLI.c#L46-L49 In the case of this library, we should return an error to take advantage of being able to return a `Result`.
-rw-r--r--license-generator/aquatic-prime/src/lib.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/license-generator/aquatic-prime/src/lib.rs b/license-generator/aquatic-prime/src/lib.rs
index 26666a1..c7f43a4 100644
--- a/license-generator/aquatic-prime/src/lib.rs
+++ b/license-generator/aquatic-prime/src/lib.rs
@@ -5,7 +5,14 @@ extern crate error_chain;
extern crate openssl;
mod errors {
- error_chain! {}
+ error_chain! {
+ errors {
+ PublicKeyIncorrectNumBits(bits: i32) {
+ description("public key has incorrect bit size")
+ display("public key has incorrect bit size: '{}'", bits)
+ }
+ }
+ }
}
use std::collections::HashMap;
@@ -45,8 +52,11 @@ impl<'a> AquaticPrime<'a> {
let rsa_e = BigNum::from_u32(3)
.chain_err(|| "public exponent could not be converted to BigNum")?;
- if public_key.num_bits() != 1024 {
- // TODO: Return Err
+ let public_key_bit_size = public_key.num_bits();
+ if public_key_bit_size != 1024 {
+ return Err(
+ ErrorKind::PublicKeyIncorrectNumBits(public_key_bit_size).into()
+ );
}
let digest = sha1(data.as_bytes());