dummy implementation of os_get_random_bytes for windows

master
Andrew Kelley 2016-02-13 22:59:49 -07:00
parent 1d3c25e928
commit 01fda6199e
1 changed files with 19 additions and 8 deletions

View File

@ -5,13 +5,24 @@ pub error SigInterrupt;
pub error Unexpected;
pub fn os_get_random_bytes(buf: []u8) -> %void {
const amt_got = getrandom(buf.ptr, buf.len, 0);
if (amt_got < 0) {
return switch (-amt_got) {
EINVAL => unreachable{},
EFAULT => unreachable{},
EINTR => error.SigInterrupt,
else => error.Unexpected,
}
switch (@compile_var("os")) {
linux => {
const amt_got = getrandom(buf.ptr, buf.len, 0);
if (amt_got < 0) {
return switch (-amt_got) {
EINVAL => unreachable{},
EFAULT => unreachable{},
EINTR => error.SigInterrupt,
else => error.Unexpected,
}
}
},
windows => {
// TODO
for (buf) |_, i| {
buf[i] = 4;
}
},
else => unreachable{},
}
}