damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 8c91ce3e10ba6297ab94122392de24da4e44135d
parent 5fd5593595c47b8afedaa3c944c29589723eeb9a
Author: hewigovens <360470+hewigovens@users.noreply.github.com>
Date:   Tue,  3 Jan 2023 09:51:05 +0900

Always check SecRandomCopyBytes return value

Closes: #223

Diffstat:
Mdamus/Nostr/NostrEvent.swift | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -446,11 +446,13 @@ func hex_encode(_ data: Data) -> String { func random_bytes(count: Int) -> Data { - var data = Data(count: count) - _ = data.withUnsafeMutableBytes { mutableBytes in - SecRandomCopyBytes(kSecRandomDefault, count, mutableBytes.baseAddress!) + var bytes = [Int8](repeating: 0, count: count) + guard + SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes) == errSecSuccess + else { + fatalError("can't copy secure random data") } - return data + return Data(bytes: bytes, count: count) } func refid_to_tag(_ ref: ReferencedId) -> [String] {