Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random numbers #97

Closed
sonhal opened this issue Mar 25, 2021 · 4 comments
Closed

Random numbers #97

sonhal opened this issue Mar 25, 2021 · 4 comments

Comments

@sonhal
Copy link

sonhal commented Mar 25, 2021

I am building a module that needs random numbers, preferably CSPRNG. Is there a good way of getting a hold of this?

@PiotrSikora
Copy link
Member

Use getrandom crate, see example:

getrandom(&mut buf).unwrap();

@sonhal
Copy link
Author

sonhal commented Mar 25, 2021

Do I then need use the wasm32-wasi target? with cargo build --target wasm32-unknown-unknown --release I get: error[E0425]: cannot find function getrandom in this scope

Cargo.toml:

[package]
name = "authn-filter"
version = "0.1.0"
authors = ["Sondre"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
path = "src/filter.rs"
crate-type = ["cdylib"]

[dependencies]
log = "0.4.14"
proxy-wasm = "0.1.3" # The Rust SDK for proxy-wasm
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
url = "2.2.1"
oauth2 = { version = "3.0",  default-features = false }
base64 = "0.13.0"

[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
getrandom = "0.2"

@PiotrSikora
Copy link
Member

Yes, you need to use wasm32-wasi target. There is no random function defined in plain Wasm.

@sonhal
Copy link
Author

sonhal commented Apr 10, 2021

Thank you, that worked great! Is there any docs you can point to regarding WASI support in Envoy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants