Make x509 constructors unsafe

This commit is contained in:
Steven Fackler 2016-08-05 19:51:59 -07:00
parent c47be8b14b
commit 4e911e7972
1 changed files with 9 additions and 7 deletions

View File

@ -407,7 +407,7 @@ pub struct X509<'ctx> {
impl<'ctx> X509<'ctx> { impl<'ctx> X509<'ctx> {
/// Creates new from handle with desired ownership. /// Creates new from handle with desired ownership.
pub fn new(handle: *mut ffi::X509, owned: bool) -> X509<'ctx> { pub unsafe fn new(handle: *mut ffi::X509, owned: bool) -> X509<'ctx> {
X509 { X509 {
ctx: None, ctx: None,
handle: handle, handle: handle,
@ -417,7 +417,7 @@ impl<'ctx> X509<'ctx> {
/// Creates a new certificate from context. Doesn't take ownership /// Creates a new certificate from context. Doesn't take ownership
/// of handle. /// of handle.
pub fn new_in_ctx(handle: *mut ffi::X509, ctx: &'ctx X509StoreContext) -> X509<'ctx> { pub unsafe fn new_in_ctx(handle: *mut ffi::X509, ctx: &'ctx X509StoreContext) -> X509<'ctx> {
X509 { X509 {
ctx: Some(ctx), ctx: Some(ctx),
handle: handle, handle: handle,
@ -525,13 +525,15 @@ extern "C" {
impl<'ctx> Clone for X509<'ctx> { impl<'ctx> Clone for X509<'ctx> {
fn clone(&self) -> X509<'ctx> { fn clone(&self) -> X509<'ctx> {
unsafe { rust_X509_clone(self.handle) } unsafe {
rust_X509_clone(self.handle);
// FIXME: given that we now have refcounting control, 'owned' should be uneeded, the 'ctx // FIXME: given that we now have refcounting control, 'owned' should be uneeded, the 'ctx
// is probably also uneeded. We can remove both to condense the x509 api quite a bit // is probably also uneeded. We can remove both to condense the x509 api quite a bit
// //
X509::new(self.handle, true) X509::new(self.handle, true)
} }
} }
}
impl<'ctx> Drop for X509<'ctx> { impl<'ctx> Drop for X509<'ctx> {
fn drop(&mut self) { fn drop(&mut self) {