Skip to content

Commit 0df6fe6

Browse files
authored
Merge pull request #2374 from alexcrichton/add-insecure-random-interfaces
Add missing `wasi:random/insecure{,_seed}` interfaces
2 parents 2f6dce4 + ec40fb7 commit 0df6fe6

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

crates/core/src/wasi_2023_10_18.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod bindings {
2222
path: "../../wit",
2323
interfaces: r#"
2424
include wasi:http/[email protected];
25-
25+
2626
// NB: this is handling the historical behavior where Spin supported
2727
// more than "just" this snaphsot of the proxy world but additionally
2828
// other CLI-related interfaces.
@@ -156,6 +156,8 @@ where
156156
wasi::io::poll::add_to_linker(linker, |t| t)?;
157157
wasi::io::streams::add_to_linker(linker, |t| t)?;
158158
wasi::random::random::add_to_linker(linker, |t| t)?;
159+
wasi::random::insecure::add_to_linker(linker, |t| t)?;
160+
wasi::random::insecure_seed::add_to_linker(linker, |t| t)?;
159161
wasi::cli::exit::add_to_linker(linker, |t| t)?;
160162
wasi::cli::environment::add_to_linker(linker, |t| t)?;
161163
wasi::cli::stdin::add_to_linker(linker, |t| t)?;
@@ -898,6 +900,28 @@ where
898900
}
899901
}
900902

903+
impl<T> wasi::random::insecure::Host for T
904+
where
905+
T: WasiView,
906+
{
907+
fn get_insecure_random_bytes(&mut self, len: u64) -> wasmtime::Result<Vec<u8>> {
908+
<T as latest::random::insecure::Host>::get_insecure_random_bytes(self, len)
909+
}
910+
911+
fn get_insecure_random_u64(&mut self) -> wasmtime::Result<u64> {
912+
<T as latest::random::insecure::Host>::get_insecure_random_u64(self)
913+
}
914+
}
915+
916+
impl<T> wasi::random::insecure_seed::Host for T
917+
where
918+
T: WasiView,
919+
{
920+
fn insecure_seed(&mut self) -> wasmtime::Result<(u64, u64)> {
921+
<T as latest::random::insecure_seed::Host>::insecure_seed(self)
922+
}
923+
}
924+
901925
impl<T> wasi::cli::exit::Host for T
902926
where
903927
T: WasiView,

crates/core/src/wasi_2023_11_10.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod bindings {
2121
path: "../../wit",
2222
interfaces: r#"
2323
include wasi:http/[email protected];
24-
24+
2525
// NB: this is handling the historical behavior where Spin supported
2626
// more than "just" this snapshot of the proxy world but additionally
2727
// other CLI-related interfaces.
@@ -154,6 +154,8 @@ where
154154
wasi::io::poll::add_to_linker(linker, |t| t)?;
155155
wasi::io::streams::add_to_linker(linker, |t| t)?;
156156
wasi::random::random::add_to_linker(linker, |t| t)?;
157+
wasi::random::insecure::add_to_linker(linker, |t| t)?;
158+
wasi::random::insecure_seed::add_to_linker(linker, |t| t)?;
157159
wasi::cli::exit::add_to_linker(linker, |t| t)?;
158160
wasi::cli::environment::add_to_linker(linker, |t| t)?;
159161
wasi::cli::stdin::add_to_linker(linker, |t| t)?;
@@ -843,6 +845,28 @@ where
843845
}
844846
}
845847

848+
impl<T> wasi::random::insecure::Host for T
849+
where
850+
T: WasiView,
851+
{
852+
fn get_insecure_random_bytes(&mut self, len: u64) -> wasmtime::Result<Vec<u8>> {
853+
<T as latest::random::insecure::Host>::get_insecure_random_bytes(self, len)
854+
}
855+
856+
fn get_insecure_random_u64(&mut self) -> wasmtime::Result<u64> {
857+
<T as latest::random::insecure::Host>::get_insecure_random_u64(self)
858+
}
859+
}
860+
861+
impl<T> wasi::random::insecure_seed::Host for T
862+
where
863+
T: WasiView,
864+
{
865+
fn insecure_seed(&mut self) -> wasmtime::Result<(u64, u64)> {
866+
<T as latest::random::insecure_seed::Host>::insecure_seed(self)
867+
}
868+
}
869+
846870
impl<T> wasi::cli::exit::Host for T
847871
where
848872
T: WasiView,

0 commit comments

Comments
 (0)