mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 12:48:14 +00:00
core/crypto: Add has_rand_bytes
This allows runtime detection as to if `rand_bytes` is supported or not, and lets us enable the test-case on all of the supported targets.
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
package crypto implements a selection of cryptography algorithms and useful
|
||||||
|
helper routines.
|
||||||
|
*/
|
||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
@@ -51,3 +55,9 @@ rand_bytes :: proc (dst: []byte) {
|
|||||||
|
|
||||||
_rand_bytes(dst)
|
_rand_bytes(dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// has_rand_bytes returns true iff the target has support for accessing the
|
||||||
|
// system entropty source.
|
||||||
|
has_rand_bytes :: proc () -> bool {
|
||||||
|
return _has_rand_bytes()
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,3 +10,7 @@ foreign libc {
|
|||||||
_rand_bytes :: proc(dst: []byte) {
|
_rand_bytes :: proc(dst: []byte) {
|
||||||
arc4random_buf(raw_data(dst), len(dst))
|
arc4random_buf(raw_data(dst), len(dst))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_rand_bytes :: proc () -> bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,3 +10,7 @@ _rand_bytes :: proc(dst: []byte) {
|
|||||||
panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", res, msg))
|
panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", res, msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_rand_bytes :: proc () -> bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,3 +9,7 @@ package crypto
|
|||||||
_rand_bytes :: proc(dst: []byte) {
|
_rand_bytes :: proc(dst: []byte) {
|
||||||
unimplemented("crypto: rand_bytes not supported on this OS")
|
unimplemented("crypto: rand_bytes not supported on this OS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_rand_bytes :: proc () -> bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,3 +18,7 @@ _rand_bytes :: proc(dst: []byte) {
|
|||||||
dst = dst[to_read:]
|
dst = dst[to_read:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_rand_bytes :: proc () -> bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,3 +34,7 @@ _rand_bytes :: proc (dst: []byte) {
|
|||||||
dst = dst[n_read:]
|
dst = dst[n_read:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_rand_bytes :: proc () -> bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,3 +21,7 @@ _rand_bytes :: proc(dst: []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_has_rand_bytes :: proc () -> bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ test_x25519 :: proc(t: ^testing.T) {
|
|||||||
test_rand_bytes :: proc(t: ^testing.T) {
|
test_rand_bytes :: proc(t: ^testing.T) {
|
||||||
tc.log(t, "Testing rand_bytes")
|
tc.log(t, "Testing rand_bytes")
|
||||||
|
|
||||||
if ODIN_OS != .Linux {
|
if !crypto.has_rand_bytes() {
|
||||||
tc.log(t, "rand_bytes not supported - skipping")
|
tc.log(t, "rand_bytes not supported - skipping")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user