File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -242,9 +242,6 @@ extension WebAuthnManager {
242
242
/// - Throws: An error if something went wrong while generating random byte
243
243
/// - Returns: 32 bytes
244
244
public func generateChallengeString( ) throws -> [ UInt8 ] {
245
- var bytes = [ UInt8] ( repeating: 0 , count: 32 )
246
- let status = SecRandomCopyBytes ( kSecRandomDefault, bytes. count, & bytes)
247
- guard status == errSecSuccess else { throw WebAuthnManagerError . challengeGenerationFailed }
248
- return bytes
245
+ [ UInt8 ] . random ( count: 32 )
249
246
}
250
247
}
You can’t perform that action at this time.
0 commit comments