mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
added support for cloning on EcKey
This commit is contained in:
parent
e64fab8b9d
commit
b3bd64504b
1 changed files with 25 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use core::fmt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use crate::bn::{BigNumContext, BigNumContextRef, BigNumRef};
|
use crate::bn::{BigNumContext, BigNumContextRef, BigNumRef};
|
||||||
|
@ -5,13 +6,11 @@ use crate::error::{cvt, cvt_n, cvt_p, ErrorStack};
|
||||||
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
|
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
|
||||||
|
|
||||||
foreign_type! {
|
foreign_type! {
|
||||||
#[derive(Clone)]
|
|
||||||
pub unsafe type EcGroup: Send + Sync {
|
pub unsafe type EcGroup: Send + Sync {
|
||||||
type CType = ffi::EC_GROUP;
|
type CType = ffi::EC_GROUP;
|
||||||
fn drop = ffi::EC_GROUP_free;
|
fn drop = ffi::EC_GROUP_free;
|
||||||
}
|
}
|
||||||
/// Public and optional private key on the given curve.
|
/// Public and optional private key on the given curve.
|
||||||
#[derive(Clone)]
|
|
||||||
pub unsafe type EcKey {
|
pub unsafe type EcKey {
|
||||||
type CType = ffi::EC_KEY;
|
type CType = ffi::EC_KEY;
|
||||||
fn drop = ffi::EC_KEY_free;
|
fn drop = ffi::EC_KEY_free;
|
||||||
|
@ -125,3 +124,27 @@ impl EcPointRef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToOwned for EcKeyRef {
|
||||||
|
type Owned = EcKey;
|
||||||
|
|
||||||
|
fn to_owned(&self) -> EcKey {
|
||||||
|
unsafe {
|
||||||
|
let r = ffi::EC_KEY_up_ref(self.as_ptr());
|
||||||
|
assert!(r == 1);
|
||||||
|
EcKey::from_ptr(self.as_ptr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for EcKey {
|
||||||
|
fn clone(&self) -> EcKey {
|
||||||
|
(**self).to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for EcKey {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "EcKey")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue