Skip to content

Commit e81f984

Browse files
committed
experiment
1 parent d6dfbd2 commit e81f984

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

openssl/src/md.rs

+28-33
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ use crate::error::ErrorStack;
88
use crate::lib_ctx::LibCtxRef;
99
use crate::nid::Nid;
1010
use cfg_if::cfg_if;
11+
use foreign_types::ForeignType;
1112
use foreign_types::{ForeignTypeRef, Opaque};
1213
use openssl_macros::corresponds;
1314
#[cfg(ossl300)]
1415
use std::ffi::CString;
16+
use std::ops::Deref;
1517
#[cfg(ossl300)]
1618
use std::ptr;
1719

1820
cfg_if! {
1921
if #[cfg(ossl300)] {
20-
use foreign_types::ForeignType;
21-
use std::ops::{Deref, DerefMut};
22-
23-
type Inner = *mut ffi::EVP_MD;
22+
use std::ops::DerefMut;
2423

2524
impl Drop for Md {
2625
#[inline]
@@ -31,32 +30,6 @@ cfg_if! {
3130
}
3231
}
3332

34-
impl ForeignType for Md {
35-
type CType = ffi::EVP_MD;
36-
type Ref = MdRef;
37-
38-
#[inline]
39-
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self {
40-
Md(ptr)
41-
}
42-
43-
#[inline]
44-
fn as_ptr(&self) -> *mut Self::CType {
45-
self.0
46-
}
47-
}
48-
49-
impl Deref for Md {
50-
type Target = MdRef;
51-
52-
#[inline]
53-
fn deref(&self) -> &Self::Target {
54-
unsafe {
55-
MdRef::from_ptr(self.as_ptr())
56-
}
57-
}
58-
}
59-
6033
impl DerefMut for Md {
6134
#[inline]
6235
fn deref_mut(&mut self) -> &mut Self::Target {
@@ -65,13 +38,35 @@ cfg_if! {
6538
}
6639
}
6740
}
68-
} else {
69-
enum Inner {}
41+
}
42+
}
43+
44+
impl ForeignType for Md {
45+
type CType = ffi::EVP_MD;
46+
type Ref = MdRef;
47+
48+
#[inline]
49+
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self {
50+
Md(ptr)
51+
}
52+
53+
#[inline]
54+
fn as_ptr(&self) -> *mut Self::CType {
55+
self.0
56+
}
57+
}
58+
59+
impl Deref for Md {
60+
type Target = MdRef;
61+
62+
#[inline]
63+
fn deref(&self) -> &Self::Target {
64+
unsafe { MdRef::from_ptr(self.as_ptr()) }
7065
}
7166
}
7267

7368
/// A message digest algorithm.
74-
pub struct Md(Inner);
69+
pub struct Md(*mut ffi::EVP_MD);
7570

7671
unsafe impl Sync for Md {}
7772
unsafe impl Send for Md {}

0 commit comments

Comments
 (0)