From 3bc172c70bc48c88110476b3a8f076f36671ea51 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sat, 2 Dec 2023 21:37:55 +0100 Subject: [PATCH] add crypto.rand_bytes for Darwin and FreeBSD --- core/crypto/rand_darwin_and_bsd.odin | 12 ++++++++++++ core/crypto/rand_generic.odin | 7 +++---- core/crypto/rand_openbsd.odin | 12 ------------ 3 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 core/crypto/rand_darwin_and_bsd.odin delete mode 100644 core/crypto/rand_openbsd.odin diff --git a/core/crypto/rand_darwin_and_bsd.odin b/core/crypto/rand_darwin_and_bsd.odin new file mode 100644 index 000000000..aea7e2953 --- /dev/null +++ b/core/crypto/rand_darwin_and_bsd.odin @@ -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)) +} diff --git a/core/crypto/rand_generic.odin b/core/crypto/rand_generic.odin index fde91f85a..b8bf900cd 100644 --- a/core/crypto/rand_generic.odin +++ b/core/crypto/rand_generic.odin @@ -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") } diff --git a/core/crypto/rand_openbsd.odin b/core/crypto/rand_openbsd.odin deleted file mode 100644 index bae97e8f0..000000000 --- a/core/crypto/rand_openbsd.odin +++ /dev/null @@ -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)) -}