Merge pull request #1072 from eoger/dsa-clone

Implement Clone for Dsa
This commit is contained in:
Steven Fackler 2019-02-28 11:56:11 -08:00 committed by GitHub
commit 834c16d5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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());
}
}