File tree 4 files changed +40
-0
lines changed
4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -75,3 +75,6 @@ autocfg = "0.1"
75
75
76
76
[package .metadata .docs .rs ]
77
77
all-features = true
78
+
79
+ [patch .crates-io ]
80
+ rand_core = { path = " rand_core" , version = " 0.3" , default-features = false }
Original file line number Diff line number Diff line change @@ -34,3 +34,6 @@ fuchsia-zircon = "0.3.2"
34
34
[target .wasm32-unknown-unknown .dependencies ]
35
35
wasm-bindgen = { version = " 0.2.12" , optional = true }
36
36
stdweb = { version = " 0.4" , optional = true }
37
+
38
+ [target .'cfg(target_env = "sgx")' .dependencies ]
39
+ rdrand = " 0.4.0"
Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ extern crate wasm_bindgen;
142
142
feature = "stdweb" ) ) ]
143
143
#[ macro_use] extern crate stdweb;
144
144
145
+ #[ cfg( target_env = "sgx" ) ]
146
+ extern crate rdrand;
145
147
146
148
#[ cfg( not( feature = "log" ) ) ]
147
149
#[ macro_use]
@@ -310,6 +312,7 @@ mod_use!(cfg(target_os = "openbsd"), openbsd_bitrig);
310
312
mod_use ! ( cfg( target_os = "redox" ) , redox) ;
311
313
mod_use ! ( cfg( target_os = "solaris" ) , solaris) ;
312
314
mod_use ! ( cfg( windows) , windows) ;
315
+ mod_use ! ( cfg( target_env = "sgx" ) , sgx) ;
313
316
314
317
mod_use ! (
315
318
cfg( all(
@@ -356,5 +359,6 @@ compile_error!("enable either wasm_bindgen or stdweb feature");
356
359
target_os = "solaris" ,
357
360
windows,
358
361
target_arch = "wasm32" ,
362
+ target_env = "sgx"
359
363
) ) ) ]
360
364
compile_error ! ( "OS RNG support is not available for this platform" ) ;
Original file line number Diff line number Diff line change
1
+ use super :: OsRngImpl ;
2
+ use Error ;
3
+ use rdrand:: RdRand ;
4
+ use rand_core:: RngCore ;
5
+ use std:: fmt:: { Debug , Formatter , Result as FmtResult } ;
6
+
7
+ #[ derive( Clone ) ]
8
+ pub struct OsRng {
9
+ gen : RdRand
10
+ }
11
+
12
+ impl OsRngImpl for OsRng {
13
+ fn new ( ) -> Result < OsRng , Error > {
14
+ let rng = RdRand :: new ( ) ?;
15
+ Ok ( OsRng { gen : rng } )
16
+ }
17
+
18
+ fn fill_chunk ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
19
+ self . gen . try_fill_bytes ( dest)
20
+ }
21
+
22
+ fn method_str ( & self ) -> & ' static str { "RDRAND" }
23
+ }
24
+
25
+ impl Debug for OsRng {
26
+ fn fmt ( & self , f : & mut Formatter ) -> FmtResult {
27
+ f. debug_struct ( "OsRng" )
28
+ . finish ( )
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments