Use guard

This commit is contained in:
Davide De Rosa 2019-05-19 11:29:56 +02:00
parent 59e2c04aea
commit d19e029131
1 changed files with 3 additions and 3 deletions

View File

@ -48,7 +48,7 @@ class SecureRandom {
static func uint32FromBuffer() throws -> UInt32 {
var randomBuffer = [UInt8](repeating: 0, count: 4)
if (SecRandomCopyBytes(kSecRandomDefault, 4, &randomBuffer) != 0) {
guard SecRandomCopyBytes(kSecRandomDefault, 4, &randomBuffer) == 0 else {
throw SecureRandomError.randomGenerator
}
@ -65,7 +65,7 @@ class SecureRandom {
try withUnsafeMutablePointer(to: &randomNumber) {
try $0.withMemoryRebound(to: UInt8.self, capacity: 4) { (randomBytes: UnsafeMutablePointer<UInt8>) -> Void in
guard (SecRandomCopyBytes(kSecRandomDefault, 4, randomBytes) == 0) else {
guard SecRandomCopyBytes(kSecRandomDefault, 4, randomBytes) == 0 else {
throw SecureRandomError.randomGenerator
}
}
@ -95,7 +95,7 @@ class SecureRandom {
randomBytes.deallocate()
}
guard (SecRandomCopyBytes(kSecRandomDefault, length, randomBytes) == 0) else {
guard SecRandomCopyBytes(kSecRandomDefault, length, randomBytes) == 0 else {
throw SecureRandomError.randomGenerator
}