Skip to content

Commit e04d469

Browse files
committed
experiment
1 parent d6dfbd2 commit e04d469

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

openssl/src/md.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +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+
use std::ops::DerefMut;
2223

2324
type Inner = *mut ffi::EVP_MD;
2425

@@ -31,32 +32,6 @@ cfg_if! {
3132
}
3233
}
3334

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-
6035
impl DerefMut for Md {
6136
#[inline]
6237
fn deref_mut(&mut self) -> &mut Self::Target {
@@ -70,6 +45,30 @@ cfg_if! {
7045
}
7146
}
7247

48+
impl ForeignType for Md {
49+
type CType = ffi::EVP_MD;
50+
type Ref = MdRef;
51+
52+
#[inline]
53+
unsafe fn from_ptr(ptr: *mut Self::CType) -> Self {
54+
Md(ptr)
55+
}
56+
57+
#[inline]
58+
fn as_ptr(&self) -> *mut Self::CType {
59+
self.0
60+
}
61+
}
62+
63+
impl Deref for Md {
64+
type Target = MdRef;
65+
66+
#[inline]
67+
fn deref(&self) -> &Self::Target {
68+
unsafe { MdRef::from_ptr(self.as_ptr()) }
69+
}
70+
}
71+
7372
/// A message digest algorithm.
7473
pub struct Md(Inner);
7574

0 commit comments

Comments
 (0)