Skip to content

Commit

Permalink
Inline definitions from winapi/advapi32
Browse files Browse the repository at this point in the history
For now it's probably worth the decrease in build times
  • Loading branch information
alexcrichton committed Feb 13, 2016
1 parent 8feb9df commit 63aaeef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Expand Up @@ -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"
28 changes: 23 additions & 5 deletions src/os.rs
Expand Up @@ -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
Expand Down

2 comments on commit 63aaeef

@retep998
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh how I wish rustc was faster at compiling winapi.

@alexcrichton
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.