add crypto.rand_bytes for Darwin and FreeBSD

This commit is contained in:
Laytan Laats
2023-12-02 21:37:55 +01:00
parent f378367fe7
commit 3bc172c70b
3 changed files with 15 additions and 16 deletions

View File

@@ -0,0 +1,12 @@
//+build freebsd, openbsd, darwin
package crypto
foreign import libc "system:c"
foreign libc {
arc4random_buf :: proc(buf: [^]byte, nbytes: uint) ---
}
_rand_bytes :: proc(dst: []byte) {
arc4random_buf(raw_data(dst), len(dst))
}

View File

@@ -1,7 +1,6 @@
//+build !linux !windows !openbsd !freebsd !darwin !js
package crypto
when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows && ODIN_OS != .JS {
_rand_bytes :: proc(dst: []byte) {
unimplemented("crypto: rand_bytes not supported on this OS")
}
_rand_bytes :: proc(dst: []byte) {
unimplemented("crypto: rand_bytes not supported on this OS")
}

View File

@@ -1,12 +0,0 @@
package crypto
import "core:c"
foreign import libc "system:c"
foreign libc {
arc4random_buf :: proc "c" (buf: rawptr, nbytes: c.size_t) ---
}
_rand_bytes :: proc (dst: []byte) {
arc4random_buf(raw_data(dst), len(dst))
}