blob: b5c512054f5ee09b16c89f8ff421b099a650cf98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
use std
pkg crypto =
const getentropy : (buf : byte[:] -> void)
;;
var randfd
const __init__ = {
randfd = std.try(std.open("/dev/random", std.Ordonly))
}
const getentropy = {buf
var nread
nread = 0
while nread < buf.len
match std.read(randfd, buf)
| `std.Err e: std.die(std.fmt("unable to read from randfd: {}\n", e))
| `std.Ok 0: std.die("could not get entropy from randfd: EOF\n")
| `std.Ok n: nread += n
;;
;;
}
|