File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
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 @@ -106,11 +106,6 @@ extension WebAuthnManager {
106
106
/// - Throws: An error if something went wrong while generating random byte
107
107
/// - Returns: 32 bytes
108
108
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 )
115
110
}
116
111
}
You can’t perform that action at this time.
0 commit comments