You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/Web3Core/Utility/Data+Extension.swift
+39-15Lines changed: 39 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -41,27 +41,51 @@ extension Data {
41
41
}
42
42
}
43
43
44
+
@available(*, deprecated, message:"Please, use throwing `randomBytes(count)` function instead to get information instead of `nil` value on why the function call failed.")
45
+
/// Runs `SecRandomCopyBytes` for Apple platforms and `openssl rand -hex` for other platforms
46
+
/// to generate cryptographically secure random bytes.
47
+
/// - Parameter count: how many bytes to generate. Value below or equal to 0 will return `nil`.
/// Runs `SecRandomCopyBytes` for Apple platforms and `openssl rand -hex` for other platforms
54
+
/// to generate cryptographically secure random bytes.
55
+
/// - Parameter count: how many bytes to generate. Value below or equal to 0 will throw an error.
56
+
/// - Parameter useOpenSSL: **has no effect on Linux and Windows**. When set to `true` forces the use of external executable `openssl`. It's your responsibility to make sure openssl is installed on this machine. By default set to `false`. To install follow [the official guide](https://www.openssl.org/source/ ).
throwWeb3Error.processingError(desc:"Address of the buffer is nil (\(body.baseAddress ==nil)) or the count of bytes in the buffer is not equal to the count requested by the user (\(body.count < count)).")
throwWeb3Error.processingError(desc:"Random bytes generated by the openssl are in an invalid hex representation: \(randomBytesHex)")
82
+
}
83
+
84
+
guard bytes.count == count else{
85
+
throwWeb3Error.processingError(desc:"Count of generated by the openssl random bytes is not equal to the count requested by the user: expected \(count), given \(bytes.count).")
86
+
}
87
+
88
+
return bytes
65
89
}
66
90
67
91
publicfunc bitsInRange(_ startingBit:Int, _ length:Int)->UInt64?{ // return max of 8 bytes for simplicity, non-public
0 commit comments