8000 Merge pull request #4 from vzsg/linux · tmthecoder/Argon2Swift@ef5d2ad · GitHub
[go: up one dir, main page]

Skip to content

Commit ef5d2ad

Browse files
authored
Merge pull request #4 from vzsg/linux
Replace SecCopyRandomBytes with Swift 4.2+ random
2 parents 22f31a6 + 9ed386c commit ef5d2ad

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

Sources/Swift/Salt.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
import Foundation
8-
import Security
98

109
/// A class to wrap around Salts in argon2. allowing cryptographically secure generation of salts as well as utilization of premade salts
1110
public class Salt {
@@ -30,15 +29,7 @@ public class Salt {
3029
- Returns: A `Salt` object containing a random byte array of the specified length
3130
*/
3231
public static func newSalt(length: Int = 16) -> Salt {
33-
// Set a byte array
34-
var bytes = [UInt8](repeating: 0, count: length)
35-
// Set random generated numbers to the byte array
36-
let status = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes)
37-
// Ensure the copy was a success
38-
if status != errSecSuccess {
39-
fatalError("SecRandomCopyBytes failed with error code: \(status)")
40-
}
41-
// Return the salt
32+
let bytes = Array((0..<length).map { _ in UInt8.random(in: 0...255) })
4233
return Salt(bytes: Data(bytes))
4334
}
4435
}

0 commit comments

Comments
 (0)
0