Browse Source

add crypto.rand_bytes for Darwin and FreeBSD

Laytan Laats 1 year ago
parent
commit
3bc172c70b
3 changed files with 15 additions and 16 deletions
  1. 12 0
      core/crypto/rand_darwin_and_bsd.odin
  2. 3 4
      core/crypto/rand_generic.odin
  3. 0 12
      core/crypto/rand_openbsd.odin

+ 12 - 0
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))
+}

+ 3 - 4
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")
 }

+ 0 - 12
core/crypto/rand_openbsd.odin

@@ -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))
-}