Skip to content

Commit

Permalink
Remove ALL keychain random bytes refs, update CI, try running tarpaul…
Browse files Browse the repository at this point in the history
…in without nightly.
  • Loading branch information
Sajjon committed Feb 14, 2024
1 parent f16d451 commit 850c5b2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ jobs:
- uses: radixdlt/public-iac-resuable-artifacts/fetch-secrets@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SECRET }}
app_name: 'sargon'
step_name: 'codecoverage'
secret_prefix: 'CODECOV'
app_name: "sargon"
step_name: "codecoverage"
secret_prefix: "CODECOV"
secret_name: ${{ secrets.AWS_SECRET_NAME_CODECOV }}
parse_json: true
- name: Generate code coverage
run: cargo +nightly tarpaulin
run: cargo tarpaulin
- name: Upload to codecov.io
uses: RDXWorks-actions/codecov-action@main
with:
Expand Down
8 changes: 4 additions & 4 deletions tests/uniffi/bindings/test_bag_of_bytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension Data {
}
}

func randomByteArray(byteCount count: Int) throws -> [UInt8] {
func randomByteArray(byteCount count: Int) -> [UInt8] {
#if canImport(Darwin) || os(Linux) || os(Android) || os(Windows)
var rng = SystemRandomNumberGenerator()
return (0..<count).map { _ in rng.next() }
Expand All @@ -72,8 +72,8 @@ func randomByteArray(byteCount count: Int) throws -> [UInt8] {
}

extension Data {
public static func random(byteCount: Int) throws -> Self {
Data(randomBytesArray(byteCount: byteCount))
public static func random(byteCount: Int) -> Self {
Data(randomByteArray(byteCount: byteCount))
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func test() throws {
let s = Set(
(0..<n).map {
// probability of collision is non-existing for 16 bytes
try! BagOfBytes(data: Data.random(byteCount: 16 + $0))
BagOfBytes(data: Data.random(byteCount: 16 + $0))
})
assert(s.count == n)
}
Expand Down
20 changes: 12 additions & 8 deletions tests/uniffi/bindings/test_hex32_bytes.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import Sargon
import Foundation

func randomByteArray(byteCount count: Int) -> [UInt8] {
#if canImport(Darwin) || os(Linux) || os(Android) || os(Windows)
var rng = SystemRandomNumberGenerator()
return (0..<count).map { _ in rng.next() }
#else
fatalError("No secure random number generator on this platform.")
#endif
}

extension Data {
public static func random(byteCount: Int) throws -> 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()
public static func random(byteCount: Int) -> Self {
Data(randomByteArray(byteCount: byteCount))
}
}

extension Hex32Bytes {
init(data: Data) throws {
self = try newHex32BytesFrom(bytes: data)
Expand Down
20 changes: 12 additions & 8 deletions tests/uniffi/bindings/test_radix_connect_password.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import Sargon
import Foundation

func randomByteArray(byteCount count: Int) -> [UInt8] {
#if canImport(Darwin) || os(Linux) || os(Android) || os(Windows)
var rng = SystemRandomNumberGenerator()
return (0..<count).map { _ in rng.next() }
#else
fatalError("No secure random number generator on this platform.")
#endif
}

extension Data {
public static func random(byteCount: Int) throws -> 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()
public static func random(byteCount: Int) -> Self {
Data(randomByteArray(byteCount: byteCount))
}
}

extension RadixConnectPassword {
init(bytes: Hex32Bytes) {
self = newRadixConnectPassword(bytes: bytes)
Expand Down
20 changes: 12 additions & 8 deletions tests/uniffi/bindings/test_wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,22 @@ extension AppearanceID {
static let placeholder: Self = newAppearanceIdPlaceholder()
static let placeholderOther: Self = newAppearanceIdPlaceholderOther()
}
func randomByteArray(byteCount count: Int) -> [UInt8] {
#if canImport(Darwin) || os(Linux) || os(Android) || os(Windows)
var rng = SystemRandomNumberGenerator()
return (0..<count).map { _ in rng.next() }
#else
fatalError("No secure random number generator on this platform.")
#endif
}

extension Data {
public static func random(byteCount: Int) throws -> 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()
public static func random(byteCount: Int) -> Self {
Data(randomByteArray(byteCount: byteCount))
}
}


extension Wallet {
public static let defaultIphoneName: String = "iPhone"

Expand Down

0 comments on commit 850c5b2

Please sign in to comment.