Core Foundation and Security vendor libraries.

This commit is contained in:
Vitalii Kravchenko
2024-04-13 00:11:42 +01:00
parent 97db075e45
commit befb0f7868
15 changed files with 664 additions and 147 deletions
+1 -1
View File
@@ -11,6 +11,6 @@ _rand_bytes :: proc(dst: []byte) {
arc4random_buf(raw_data(dst), len(dst))
}
_has_rand_bytes :: proc () -> bool {
_has_rand_bytes :: proc() -> bool {
return true
}
+8 -6
View File
@@ -1,16 +1,18 @@
package crypto
import "core:fmt"
import "core:sys/darwin"
import CF "core:sys/darwin/CoreFoundation"
import Sec "core:sys/darwin/Security"
_rand_bytes :: proc(dst: []byte) {
res := darwin.SecRandomCopyBytes(count=len(dst), bytes=raw_data(dst))
if res != .Success {
msg := darwin.CFStringCopyToOdinString(darwin.SecCopyErrorMessageString(res))
panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", res, msg))
err := Sec.RandomCopyBytes(count=len(dst), bytes=raw_data(dst))
if err != .Success {
msg := CF.StringCopyToOdinString(Sec.CopyErrorMessageString(err))
panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", err, msg))
}
}
_has_rand_bytes :: proc () -> bool {
_has_rand_bytes :: proc() -> bool {
return true
}
+1 -1
View File
@@ -10,6 +10,6 @@ _rand_bytes :: proc(dst: []byte) {
unimplemented("crypto: rand_bytes not supported on this OS")
}
_has_rand_bytes :: proc () -> bool {
_has_rand_bytes :: proc() -> bool {
return false
}
+1 -1
View File
@@ -19,6 +19,6 @@ _rand_bytes :: proc(dst: []byte) {
}
}
_has_rand_bytes :: proc () -> bool {
_has_rand_bytes :: proc() -> bool {
return true
}
+1 -1
View File
@@ -35,6 +35,6 @@ _rand_bytes :: proc (dst: []byte) {
}
}
_has_rand_bytes :: proc () -> bool {
_has_rand_bytes :: proc() -> bool {
return true
}
+1 -1
View File
@@ -22,6 +22,6 @@ _rand_bytes :: proc(dst: []byte) {
}
}
_has_rand_bytes :: proc () -> bool {
_has_rand_bytes :: proc() -> bool {
return true
}