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 e04d469
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions openssl/src/md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +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};
use std::ops::DerefMut;

type Inner = *mut ffi::EVP_MD;

Expand All @@ -31,32 +32,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 @@ -70,6 +45,30 @@ 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()) }
}
}

/// A message digest algorithm.
pub struct Md(Inner);

Expand Down

0 comments on commit e04d469

Please sign in to comment.