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

Use configuration flags to switch between backends #504

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

newpavlov
Copy link
Member

Closes #498

#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
compile_error!("`rdrand` backend can be enabled only for x86 and x86-64 targets!");
#[path = "rdrand.rs"] mod imp;
} else if #[cfg(getrandom_backend = "wasm_js")] {
Copy link
Member Author

@newpavlov newpavlov Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could split wasm_js feature further into wasm_node and wasm_web parts. But I don't know whether people need WASM files which can run both on Node and Web.

Alternatively, we could make the JS backend enabled by default and require users targeting non-JS WASM to enable the custom backend. But personally I dislike such approach since it's technically wrong and we play into the poor handling of the wasm32-unknown-unknown target by the Rust ecosystem.

// `len`).
let dest = uninit_slice_fill_zero(dest);
let ret = unsafe { __getrandom_custom(dest.as_mut_ptr(), dest.len()) };
let ret = unsafe { __getrandom_custom(dest.as_mut_ptr().cast(), dest.len()) };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in v0.3 we no longer need to zeroize the destination buffer since we can specify that uninitialized buffers may be passed to __getrandom_custom.

We also probably could use NonZeroUsize for len to improve code generation for __getrandom_custom provider.

@newpavlov newpavlov marked this pull request as ready for review October 4, 2024 18:33
#[path = "js.rs"] mod imp;
} else if #[cfg(getrandom_backend = "esp_idf")] {
#[cfg(not(target_os = "espidf"))]
compile_error!("`esp_idf` backend can be enabled only for ESP-IDF targets!");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESP-IDF support is now optional because of the concerns raised in #397.

@newpavlov
Copy link
Member Author

cc @briansmith

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

Successfully merging this pull request may close these issues.

Allow to change default entropy source with configuration flags
1 participant