Implement Clone for Dsa

This commit is contained in:
Edouard Oger 2019-02-28 14:10:49 -05:00
parent a99f75fccd
commit 55fee497bb
2 changed files with 24 additions and 0 deletions

View File

@ -5,6 +5,7 @@ use *;
extern "C" {
pub fn DSA_new() -> *mut DSA;
pub fn DSA_free(dsa: *mut DSA);
pub fn DSA_up_ref(dsa: *mut DSA) -> c_int;
pub fn DSA_size(dsa: *const DSA) -> c_int;
pub fn DSA_sign(
dummy: c_int,

View File

@ -59,6 +59,23 @@ generic_foreign_type_and_impl_send_sync! {
pub struct DsaRef<T>;
}
impl<T> Clone for Dsa<T> {
fn clone(&self) -> Dsa<T> {
(**self).to_owned()
}
}
impl<T> ToOwned for DsaRef<T> {
type Owned = Dsa<T>;
fn to_owned(&self) -> Dsa<T> {
unsafe {
ffi::DSA_up_ref(self.as_ptr());
Dsa::from_ptr(self.as_ptr())
}
}
}
impl<T> DsaRef<T>
where
T: HasPublic,
@ -412,4 +429,10 @@ mod test {
verifier.update(TEST_DATA).unwrap();
assert!(verifier.verify(&signature[..]).unwrap());
}
#[test]
fn clone() {
let key = Dsa::generate(2048).unwrap();
drop(key.clone());
}
}