From f16d45172834f5e231d74ce4719f7e5151aa5c4a Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Wed, 14 Feb 2024 09:43:06 +0100 Subject: [PATCH] Remove macOS specific random bytes impl, with one that might work on Linux --- tests/uniffi/bindings/test_bag_of_bytes.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/uniffi/bindings/test_bag_of_bytes.swift b/tests/uniffi/bindings/test_bag_of_bytes.swift index 204471867..57da5418e 100644 --- a/tests/uniffi/bindings/test_bag_of_bytes.swift +++ b/tests/uniffi/bindings/test_bag_of_bytes.swift @@ -62,15 +62,18 @@ extension Data { } } +func randomByteArray(byteCount count: Int) throws -> [UInt8] { + #if canImport(Darwin) || os(Linux) || os(Android) || os(Windows) + var rng = SystemRandomNumberGenerator() + return (0.. Self { - var bytes = [UInt8](repeating: 0, count: byteCount) - let status = SecRandomCopyBytes(kSecRandomDefault, byteCount, &bytes) - if status == errSecSuccess { - return Self(bytes) - } - struct UnableToGenerateBytes: Swift.Error {} - throw UnableToGenerateBytes() + Data(randomBytesArray(byteCount: byteCount)) } }