Arguments should be BigNumRef and not BigNum

This commit is contained in:
Rohit Aggarwal 2018-03-10 16:29:54 +00:00
parent 7ab650098c
commit bc304565e7
No known key found for this signature in database
GPG Key ID: 0CEC9082DF18FAAA
1 changed files with 3 additions and 5 deletions

View File

@ -2,14 +2,13 @@
//! //!
use bn::{BigNum, BigNumRef}; use bn::BigNumRef;
use {cvt, cvt_n, cvt_p}; use {cvt, cvt_n, cvt_p};
use ec::EcKeyRef; use ec::EcKeyRef;
use error::ErrorStack; use error::ErrorStack;
use ffi; use ffi;
use foreign_types::{ForeignType, ForeignTypeRef}; use foreign_types::{ForeignType, ForeignTypeRef};
use pkey::{Private, Public}; use pkey::{Private, Public};
use std::mem;
foreign_type_and_impl_send_sync! { foreign_type_and_impl_send_sync! {
@ -48,11 +47,10 @@ impl EcdsaSig {
/// OpenSSL documentation at [`ECDSA_SIG_set0`] /// OpenSSL documentation at [`ECDSA_SIG_set0`]
/// ///
/// [`ECDSA_SIG_set0`]: https://www.openssl.org/docs/man1.1.0/crypto/ECDSA_SIG_set0.html /// [`ECDSA_SIG_set0`]: https://www.openssl.org/docs/man1.1.0/crypto/ECDSA_SIG_set0.html
pub fn from_private_components(r: BigNum, s: BigNum) -> Result<EcdsaSig, ErrorStack> { pub fn from_private_components(r: &BigNumRef, s: &BigNumRef) -> Result<EcdsaSig, ErrorStack> {
unsafe { unsafe {
let sig = cvt_p(ffi::ECDSA_SIG_new())?; let sig = cvt_p(ffi::ECDSA_SIG_new())?;
cvt(compat::set_numbers(sig, r.as_ptr(), s.as_ptr()))?; cvt(compat::set_numbers(sig, r.as_ptr(), s.as_ptr()))?;
mem::forget((r, s));
Ok(EcdsaSig::from_ptr(sig as *mut _)) Ok(EcdsaSig::from_ptr(sig as *mut _))
} }
} }
@ -189,7 +187,7 @@ mod test {
let r = res.private_component_r().unwrap().to_owned().unwrap(); let r = res.private_component_r().unwrap().to_owned().unwrap();
let s = res.private_component_s().unwrap().to_owned().unwrap(); let s = res.private_component_s().unwrap().to_owned().unwrap();
let res2 = EcdsaSig::from_private_components(r, s).unwrap(); let res2 = EcdsaSig::from_private_components(&r, &s).unwrap();
let verification2 = res2.verify(data.as_bytes(), &public_key).unwrap(); let verification2 = res2.verify(data.as_bytes(), &public_key).unwrap();
assert!(verification2); assert!(verification2);
} }