Skip to content

Commit 28fcd0d

Browse files
committed
Merge branch 'main' into refactor2
2 parents b3ecca7 + 930bfd2 commit 28fcd0d

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extension FixedWidthInteger {
2+
public static func random() -> Self {
3+
return Self.random(in: .min ... .max)
4+
}
5+
6+
public static func random<T>(using generator: inout T) -> Self
7+
where T : RandomNumberGenerator
8+
{
9+
return Self.random(in: .min ... .max, using: &generator)
10+
}
11+
}
12+
13+
extension Array where Element: FixedWidthInteger {
14+
public static func random(count: Int) -> [Element] {
15+
var array: [Element] = .init(repeating: 0, count: count)
16+
(0..<count).forEach { array[$0] = Element.random() }
17+
return array
18+
}
19+
20+
public static func random<T>(count: Int, using generator: inout T) -> [Element]
21+
where T: RandomNumberGenerator
22+
{
23+
var array: [Element] = .init(repeating: 0, count: count)
24+
(0..<count).forEach { array[$0] = Element.random(using: &generator) }
25+
return array
26+
}
27+
}

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ extension WebAuthnManager {
106106
/// - Throws: An error if something went wrong while generating random byte
107107
/// - Returns: 32 bytes
108108
public func generateChallengeString() throws -> [UInt8] {
109-
var bytes = [UInt8](repeating: 0, count: 32)
110-
let status = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes)
111-
guard status == errSecSuccess else {
112-
throw WebAuthnManagerError.challengeGenerationFailed
113-
}
114-
return bytes
109+
[UInt8].random(count: 32)
115110
}
116111
}

0 commit comments

Comments
 (0)