File tree Expand file tree Collapse file tree 1 file changed +8
-15
lines changed
Expand file tree Collapse file tree 1 file changed +8
-15
lines changed Original file line number Diff line number Diff line change @@ -13,27 +13,20 @@ use crate::Error;
1313use std:: io;
1414use core:: num:: NonZeroU32 ;
1515
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 ] ) ;
2120
2221#[ link( name = "Security" , kind = "framework" ) ]
2322extern {
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 ;
2726}
2827
2928pub 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 ( ) ) } ;
3730 if ret == -1 {
3831 error ! ( "SecRandomCopyBytes call failed" ) ;
3932 Err ( io:: Error :: last_os_error ( ) . into ( ) )
You can’t perform that action at this time.
0 commit comments