Skip to content

Commit 6825ae5

Browse files
committed
Use windows-targets bumping MSRV to 1.56
Signed-off-by: Joe Richey <[email protected]>
1 parent 1549270 commit 6825ae5

File tree

4 files changed

+7
-55
lines changed

4 files changed

+7
-55
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
matrix:
4646
# os: [ubuntu-22.04, windows-2022]
4747
os: [windows-2022]
48-
toolchain: [nightly, beta, stable, 1.36]
48+
toolchain: [nightly, beta, stable, 1.56]
4949
# # Only Test macOS on stable to reduce macOS CI jobs
5050
# include:
5151
# # x86_64-apple-darwin.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "getrandom"
33
version = "0.2.15" # Also update html_root_url in lib.rs when bumping this
44
edition = "2018"
5+
rust-version = "1.56"
56
authors = ["The Rand Project Developers"]
67
license = "MIT OR Apache-2.0"
78
description = "A small cross-platform library for retrieving random data from system source"
@@ -23,6 +24,9 @@ libc = { version = "0.2.154", default-features = false }
2324
[target.'cfg(target_os = "wasi")'.dependencies]
2425
wasi = { version = "0.11", default-features = false }
2526

27+
[target.'cfg(all(windows, not(target_vendor = "win7")))'.dependencies]
28+
windows-targets = "0.52"
29+
2630
[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
2731
wasm-bindgen = { version = "0.2.62", default-features = false, optional = true }
2832
js-sys = { version = "0.3", optional = true }

src/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ impl Error {
5353
/// Called from an ES module on Node.js. This is unsupported, see:
5454
/// <https://docs.rs/getrandom#nodejs-es-module-support>.
5555
pub const NODE_ES_MODULE: Error = internal_error(14);
56-
/// Unable to load Windows function from DLL.
57-
pub const WINDOWS_LOAD_DLL: Error = internal_error(15);
5856
/// Calling Windows ProcessPrng failed.
59-
pub const WINDOWS_PROCESS_PRNG: Error = internal_error(16);
57+
pub const WINDOWS_PROCESS_PRNG: Error = internal_error(15);
6058

6159
/// Codes below this point represent OS Errors (i.e. positive i32 values).
6260
/// Codes at or above this point, but below [`Error::CUSTOM_START`] are
@@ -176,7 +174,6 @@ fn internal_desc(error: Error) -> Option<&'static str> {
176174
Error::NODE_CRYPTO => Some("Node.js crypto CommonJS module is unavailable"),
177175
Error::NODE_RANDOM_FILL_SYNC => Some("Calling Node.js API crypto.randomFillSync failed"),
178176
Error::NODE_ES_MODULE => Some("Node.js ES modules are not directly supported, see https://docs.rs/getrandom#nodejs-es-module-support"),
179-
Error::WINDOWS_LOAD_DLL => Some("Unable to load function from Windows DLL"),
180177
Error::WINDOWS_PROCESS_PRNG => Some("ProcessPrng: Windows system function failure"),
181178
_ => None,
182179
}

src/windows.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,13 @@
11
//! Implementation for Windows
22
use crate::Error;
33
use core::mem::MaybeUninit;
4-
// use core::{
5-
// ffi::c_void,
6-
// mem, ptr,
7-
// sync::atomic::{fence, AtomicPtr, Ordering},
8-
// };
94

105
type BOOL = i32;
116
const TRUE: BOOL = 1;
12-
// type HMODULE = isize;
137

14-
// #[link(name = "kernel32")]
15-
// extern "system" {
16-
// fn LoadLibraryA(libfilename: *const u8) -> HMODULE;
17-
// fn GetProcAddress(hmodule: HMODULE, procname: *const u8) -> *mut c_void;
18-
// }
19-
20-
// type ProcessPrng = unsafe extern "system" fn(*mut u8, usize) -> BOOL;
21-
22-
// static PROCESS_PRNG_PTR: AtomicPtr<c_void> = AtomicPtr::new(ptr::null_mut());
23-
24-
// fn get_process_prng() -> Result<ProcessPrng, Error> {
25-
// let mut p = PROCESS_PRNG_PTR.load(Ordering::Relaxed);
26-
// if p.is_null() {
27-
// let dll = unsafe { LoadLibraryA(b"bcryptprimitives.dll\0".as_ptr()) };
28-
// if dll == 0 {
29-
// return Err(Error::WINDOWS_LOAD_DLL);
30-
// }
31-
// p = unsafe { GetProcAddress(dll, b"ProcessPrng\0".as_ptr()) };
32-
// if p.is_null() {
33-
// return Err(Error::WINDOWS_LOAD_DLL);
34-
// }
35-
// PROCESS_PRNG_PTR.store(p, Ordering::Release);
36-
// } else {
37-
// fence(Ordering::Acquire);
38-
// }
39-
// Ok(unsafe { mem::transmute(p) })
40-
// }
41-
42-
#[cfg_attr(
43-
target_arch = "x86",
44-
link(
45-
name = "bcryptprimitives",
46-
kind = "raw-dylib",
47-
import_name_type = "undecorated"
48-
)
49-
)]
50-
#[cfg_attr(
51-
not(target_arch = "x86"),
52-
link(name = "bcryptprimitives", kind = "raw-dylib")
53-
)]
54-
extern "system" {
55-
fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
56-
}
8+
windows_targets::link!("bcryptprimitives.dll" "system" fn ProcessPrng(pbdata : *mut u8, cbdata : usize) -> BOOL);
579

5810
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
59-
// let process_prng = get_process_prng()?;
6011
match unsafe { ProcessPrng(dest.as_mut_ptr() as *mut u8, dest.len()) } {
6112
TRUE => Ok(()),
6213
_ => Err(Error::WINDOWS_PROCESS_PRNG),

0 commit comments

Comments
 (0)