Skip to content

Commit

Permalink
experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
reaperhulk committed Sep 1, 2024
1 parent d6dfbd2 commit e81f984
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions openssl/src/md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ use crate::error::ErrorStack;
use crate::lib_ctx::LibCtxRef;
use crate::nid::Nid;
use cfg_if::cfg_if;
use foreign_types::ForeignType;
use foreign_types::{ForeignTypeRef, Opaque};
use openssl_macros::corresponds;
#[cfg(ossl300)]
use std::ffi::CString;
use std::ops::Deref;
#[cfg(ossl300)]
use std::ptr;

cfg_if! {
if #[cfg(ossl300)] {
use foreign_types::ForeignType;
use std::ops::{Deref, DerefMut};

type Inner = *mut ffi::EVP_MD;
use std::ops::DerefMut;

impl Drop for Md {
#[inline]
Expand All @@ -31,32 +30,6 @@ cfg_if! {
}
}

impl ForeignType for Md {
type CType = ffi::EVP_MD;
type Ref = MdRef;

#[inline]
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self {
Md(ptr)
}

#[inline]
fn as_ptr(&self) -> *mut Self::CType {
self.0
}
}

impl Deref for Md {
type Target = MdRef;

#[inline]
fn deref(&self) -> &Self::Target {
unsafe {
MdRef::from_ptr(self.as_ptr())
}
}
}

impl DerefMut for Md {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
Expand All @@ -65,13 +38,35 @@ cfg_if! {
}
}
}
} else {
enum Inner {}
}
}

impl ForeignType for Md {
type CType = ffi::EVP_MD;
type Ref = MdRef;

#[inline]
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self {
Md(ptr)
}

#[inline]
fn as_ptr(&self) -> *mut Self::CType {
self.0
}
}

impl Deref for Md {
type Target = MdRef;

#[inline]
fn deref(&self) -> &Self::Target {
unsafe { MdRef::from_ptr(self.as_ptr()) }
}
}

/// A message digest algorithm.
pub struct Md(Inner);
pub struct Md(*mut ffi::EVP_MD);

unsafe impl Sync for Md {}
unsafe impl Send for Md {}
Expand Down

0 comments on commit e81f984

Please sign in to comment.