From 4aa1c293b4deb97e588268bbd00949d12a26135e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 6 Nov 2018 02:36:06 +0100 Subject: 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`. --- license-generator/aquatic-prime/src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'license-generator') 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()); -- cgit v1.2.3