Skip to content

Commit

Permalink
emscripten: use getentropy from libc (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Jun 6, 2023
1 parent 5aa4105 commit e57fcac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
with:
targets: ${{ matrix.target }}
- name: Install multilib
run: sudo apt-get install gcc-multilib
run: sudo apt-get update && sudo apt-get install gcc-multilib
- uses: Swatinem/rust-cache@v2
- run: cargo test --target=${{ matrix.target }} --features=std

Expand Down
7 changes: 1 addition & 6 deletions src/emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
use crate::{util_libc::last_os_error, Error};
use core::mem::MaybeUninit;

// Not yet defined in libc crate.
extern "C" {
fn getentropy(buffer: *mut libc::c_void, length: usize) -> libc::c_int;
}

pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// Emscripten 2.0.5 added getentropy, so we can use it unconditionally.
// Unlike other getentropy implementations, there is no max buffer length.
let ret = unsafe { getentropy(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) };
let ret = unsafe { libc::getentropy(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) };
if ret < 0 {
return Err(last_os_error());
}
Expand Down

0 comments on commit e57fcac

Please sign in to comment.