use Security.framework with SecRandomCopyBytes for rand_bytes on darwin

This commit is contained in:
Laytan Laats
2024-02-13 17:34:40 +01:00
parent 3bc172c70b
commit 91cf0826c1
3 changed files with 36 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
//+build darwin
package darwin
foreign import security "system:Security.framework"
// A reference to a random number generator.
SecRandomRef :: distinct rawptr
OSStatus :: distinct i32
errSec :: enum OSStatus {
Success = 0, // No error.
Unimplemented = -4, // Function or operation not implemented.
// Many more...
}
foreign security {
// Synonym for nil, uses a cryptographically secure random number generator.
kSecRandomDefault: SecRandomRef
// Generates an array of cryptographically secure random bytes.
SecRandomCopyBytes :: proc(rnd: SecRandomRef = kSecRandomDefault, count: uint, bytes: [^]byte) -> errSec ---
}