Skip to content
Permalink
Browse files

Inline definitions from winapi/advapi32

For now it's probably worth the decrease in build times
  • Loading branch information...
alexcrichton committed Feb 13, 2016
1 parent 8feb9df commit 63aaeef028ca4d12f44f0978beb834d90a721f1b
Showing with 23 additions and 7 deletions.
  1. +0 −2 Cargo.toml
  2. +23 −5 src/os.rs
@@ -15,8 +15,6 @@ keywords = ["random", "rng"]

[dependencies]
libc = "0.2"
winapi = "0.2"
advapi32-sys = "0.1.2"

[dev-dependencies]
log = "0.3.0"
@@ -250,15 +250,33 @@ mod imp {

#[cfg(windows)]
mod imp {
extern crate winapi;
extern crate advapi32;

use std::io;
use std::mem;
use std::ptr;
use Rng;
use self::winapi::{CRYPT_SILENT, CRYPT_VERIFYCONTEXT, DWORD, HCRYPTPROV, PROV_RSA_FULL};
use self::advapi32::{CryptAcquireContextA, CryptGenRandom, CryptReleaseContext};

type BOOL = i32;
type LPCSTR = *const i8;
type DWORD = u32;
type HCRYPTPROV = usize;
type BYTE = u8;

const PROV_RSA_FULL: DWORD = 1;
const CRYPT_SILENT: DWORD = 0x00000040;
const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;

#[link(name = "advapi32")]
extern "system" {
fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
szContainer: LPCSTR,
szProvider: LPCSTR,
dwProvType: DWORD,
dwFlags: DWORD) -> BOOL;
fn CryptGenRandom(hProv: HCRYPTPROV,
dwLen: DWORD,
pbBuffer: *mut BYTE) -> BOOL;
fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
}

pub struct OsRng {
hcryptprov: HCRYPTPROV

2 comments on commit 63aaeef

@retep998

This comment has been minimized.

Copy link
Contributor

retep998 replied Feb 23, 2016

Oh how I wish rustc was faster at compiling winapi.

@alexcrichton

This comment has been minimized.

Copy link
Collaborator Author

alexcrichton replied Feb 23, 2016

I think that's the wrong way to approach the problem. Over four months ago I posted an issue about how to make compile times 4x faster, and since then very little of that has been implemented. The compiler will never magically get 2x faster, this is also just indicative that the design of winapi may be wrong in terms of scalability.

Please sign in to comment.
You can’t perform that action at this time.