@@ -8,19 +8,18 @@ use crate::error::ErrorStack;
8
8
use crate :: lib_ctx:: LibCtxRef ;
9
9
use crate :: nid:: Nid ;
10
10
use cfg_if:: cfg_if;
11
+ use foreign_types:: ForeignType ;
11
12
use foreign_types:: { ForeignTypeRef , Opaque } ;
12
13
use openssl_macros:: corresponds;
13
14
#[ cfg( ossl300) ]
14
15
use std:: ffi:: CString ;
16
+ use std:: ops:: Deref ;
15
17
#[ cfg( ossl300) ]
16
18
use std:: ptr;
17
19
18
20
cfg_if ! {
19
21
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 ;
24
23
25
24
impl Drop for Md {
26
25
#[ inline]
@@ -31,32 +30,6 @@ cfg_if! {
31
30
}
32
31
}
33
32
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
-
60
33
impl DerefMut for Md {
61
34
#[ inline]
62
35
fn deref_mut( & mut self ) -> & mut Self :: Target {
@@ -65,13 +38,35 @@ cfg_if! {
65
38
}
66
39
}
67
40
}
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 ( ) ) }
70
65
}
71
66
}
72
67
73
68
/// A message digest algorithm.
74
- pub struct Md ( Inner ) ;
69
+ pub struct Md ( * mut ffi :: EVP_MD ) ;
75
70
76
71
unsafe impl Sync for Md { }
77
72
unsafe impl Send for Md { }
0 commit comments