File tree 1 file changed +8
-15
lines changed
1 file changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -13,27 +13,20 @@ use crate::Error;
13
13
use std:: io;
14
14
use core:: num:: NonZeroU32 ;
15
15
16
- enum SecRandom { }
17
-
18
- /// Essentially a null pointer (type `SecRandomRef`)
19
- #[ allow( non_upper_case_globals) ]
20
- const kSecRandomDefault: * const SecRandom = 0 as * const SecRandom ;
16
+ // TODO: Make extern once extern_types feature is stabilized. See:
17
+ // https://github.com/rust-lang/rust/issues/43467
18
+ #[ repr( C ) ]
19
+ struct SecRandom ( [ u8 ; 0 ] ) ;
21
20
22
21
#[ link( name = "Security" , kind = "framework" ) ]
23
22
extern {
24
- fn SecRandomCopyBytes (
25
- rnd : * const SecRandom , count : libc :: size_t , bytes : * mut u8 ,
26
- ) -> libc:: c_int ;
23
+ static kSecRandomDefault : * const SecRandom ;
24
+
25
+ fn SecRandomCopyBytes ( rnd : * const SecRandom , count : usize , bytes : * mut u8 ) -> libc:: c_int ;
27
26
}
28
27
29
28
pub fn getrandom_inner ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
30
- let ret = unsafe {
31
- SecRandomCopyBytes (
32
- kSecRandomDefault,
33
- dest. len ( ) as libc:: size_t ,
34
- dest. as_mut_ptr ( ) ,
35
- )
36
- } ;
29
+ let ret = unsafe { SecRandomCopyBytes ( kSecRandomDefault, dest. len ( ) , dest. as_mut_ptr ( ) ) } ;
37
30
if ret == -1 {
38
31
error ! ( "SecRandomCopyBytes call failed" ) ;
39
32
Err ( io:: Error :: last_os_error ( ) . into ( ) )
You can’t perform that action at this time.
0 commit comments