File tree 4 files changed +43
-0
lines changed
4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ fuchsia-zircon = { version = "0.3.2", optional = true }
65
65
stdweb = { version = " 0.4" , optional = true }
66
66
wasm-bindgen = { version = " 0.2.12" , optional = true }
67
67
68
+ [target .'cfg(target_env = "sgx")' .dependencies ]
69
+ rdrand = " 0.4.0"
70
+
68
71
[dev-dependencies ]
69
72
# This has a histogram implementation used for testing uniformity.
70
73
average = " 0.9.2"
@@ -74,3 +77,6 @@ autocfg = "0.1"
74
77
75
78
[package .metadata .docs .rs ]
76
79
all-features = true
80
+
81
+ [patch .crates-io ]
82
+ rand_core = { path = " rand_core" , version = " 0.3" , default-features = false }
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ extern crate stdweb;
72
72
#[ cfg( all( target_arch = "wasm32" , feature = "wasm-bindgen" ) ) ]
73
73
extern crate wasm_bindgen;
74
74
75
+ #[ cfg( target_env = "sgx" ) ]
76
+ extern crate rdrand;
77
+
75
78
extern crate rand_core;
76
79
extern crate rand_isaac; // only for deprecations
77
80
extern crate rand_chacha; // only for deprecations
Original file line number Diff line number Diff line change @@ -194,6 +194,7 @@ pub use self::std::StdRng;
194
194
windows,
195
195
all( target_arch = "wasm32" , feature = "stdweb" ) ,
196
196
all( target_arch = "wasm32" , feature = "wasm-bindgen" ) ,
197
+ target_env = "sgx" ,
197
198
) ) ) ]
198
199
mod os;
199
200
Original file line number Diff line number Diff line change @@ -1191,6 +1191,39 @@ mod imp {
1191
1191
}
1192
1192
}
1193
1193
1194
+ #[ cfg( target_env = "sgx" ) ]
1195
+ mod imp {
1196
+ use super :: OsRngImpl ;
1197
+ use Error ;
1198
+ use rdrand:: RdRand ;
1199
+ use rand_core:: RngCore ;
1200
+ use std:: fmt:: { Debug , Formatter , Result as FmtResult } ;
1201
+
1202
+ #[ derive( Clone ) ]
1203
+ pub struct OsRng {
1204
+ gen : RdRand
1205
+ }
1206
+
1207
+ impl OsRngImpl for OsRng {
1208
+ fn new ( ) -> Result < OsRng , Error > {
1209
+ let rng = RdRand :: new ( ) ?;
1210
+ Ok ( OsRng { gen : rng } )
1211
+ }
1212
+
1213
+ fn fill_chunk ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
1214
+ self . gen . try_fill_bytes ( dest)
1215
+ }
1216
+
1217
+ fn method_str ( & self ) -> & ' static str { "RDRAND" }
1218
+ }
1219
+
1220
+ impl Debug for OsRng {
1221
+ fn fmt ( & self , f : & mut Formatter ) -> FmtResult {
1222
+ f. debug_struct ( "OsRng" )
1223
+ . finish ( )
1224
+ }
1225
+ }
1226
+ }
1194
1227
1195
1228
#[ cfg( test) ]
1196
1229
mod test {
You can’t perform that action at this time.
0 commit comments