@@ -8,17 +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
+ use std:: ops:: DerefMut ;
22
23
23
24
type Inner = * mut ffi:: EVP_MD ;
24
25
@@ -31,32 +32,6 @@ cfg_if! {
31
32
}
32
33
}
33
34
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
35
impl DerefMut for Md {
61
36
#[ inline]
62
37
fn deref_mut( & mut self ) -> & mut Self :: Target {
@@ -70,6 +45,30 @@ cfg_if! {
70
45
}
71
46
}
72
47
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
+
73
72
/// A message digest algorithm.
74
73
pub struct Md ( Inner ) ;
75
74
0 commit comments