@@ -68,7 +68,7 @@ public class DehydrationService: NSObject {
68
68
// Convert it back to Data
69
69
let pickleKeyData = MXBase64Tools . data ( fromBase64: base64PickleKey)
70
70
71
- let rehydrationResult = await rehydrateDevice ( pickleKeyData: [ UInt8 ] ( pickleKeyData) )
71
+ let rehydrationResult = await rehydrateDevice ( pickleKeyData: pickleKeyData)
72
72
switch rehydrationResult {
73
73
case . success( ( let deviceId, let rehydratedDevice) ) :
74
74
// Fetch and process the to device events available on the dehydrated device
@@ -86,14 +86,14 @@ public class DehydrationService: NSObject {
86
86
}
87
87
88
88
// Finally, create a new dehydrated device with the same pickle key
89
- try await dehydrateDevice ( pickleKeyData: [ UInt8 ] ( pickleKeyData) )
89
+ try await dehydrateDevice ( pickleKeyData: pickleKeyData)
90
90
} else { // Otherwise, generate a new dehydration pickle key, store it and dehydrate a device
91
91
// Generate a new dehydration pickle key
92
- var pickleKeyData = [ UInt8 ] ( repeating : 0 , count: 32 )
92
+ var pickleKeyData = Data ( count: 32 )
93
93
_ = SecRandomCopyBytes ( kSecRandomDefault, 32 , & pickleKeyData)
94
94
95
95
// Convert it to unpadded base 64
96
- let base64PickleKey = MXBase64Tools . unpaddedBase64 ( from: Data ( bytes : pickleKeyData, count : 32 ) )
96
+ let base64PickleKey = MXBase64Tools . unpaddedBase64 ( from: pickleKeyData)
97
97
98
98
// Store it on the backend
99
99
try await storeSecret ( base64PickleKey, secretId: secretId, secretStorageKeys: [ secretStorageKeyId: privateKeyData] )
@@ -131,10 +131,10 @@ public class DehydrationService: NSObject {
131
131
132
132
// MARK: - Device dehydration
133
133
134
- private func dehydrateDevice( pickleKeyData: [ UInt8 ] ) async throws {
135
- let dehydratedDevice = dehydratedDevices. create ( )
134
+ private func dehydrateDevice( pickleKeyData: Data ) async throws {
135
+ let dehydratedDevice = try dehydratedDevices. create ( )
136
136
137
- let requestDetails = try dehydratedDevice. keysForUpload ( deviceDisplayName: deviceDisplayName, pickleKey: [ UInt8 ] ( pickleKeyData) )
137
+ let requestDetails = try dehydratedDevice. keysForUpload ( deviceDisplayName: deviceDisplayName, pickleKey: pickleKeyData)
138
138
139
139
let parameters = MXDehydratedDeviceCreationParameters ( )
140
140
parameters. body = requestDetails. body
@@ -150,7 +150,7 @@ public class DehydrationService: NSObject {
150
150
}
151
151
}
152
152
153
- private func rehydrateDevice( pickleKeyData: [ UInt8 ] ) async -> Result < ( deviceId: String , rehydratedDevice: RehydratedDeviceProtocol ) , DehydrationServiceError > {
153
+ private func rehydrateDevice( pickleKeyData: Data ) async -> Result < ( deviceId: String , rehydratedDevice: RehydratedDeviceProtocol ) , DehydrationServiceError > {
154
154
await withCheckedContinuation { continuation in
155
155
self . restClient. retrieveDehydratedDevice { [ weak self] dehydratedDevice in
156
156
guard let self else { return }
@@ -163,7 +163,7 @@ public class DehydrationService: NSObject {
163
163
}
164
164
165
165
do {
166
- let rehydratedDevice = try self . dehydratedDevices. rehydrate ( pickleKey: [ UInt8 ] ( pickleKeyData) , deviceId: dehydratedDevice. deviceId, deviceData: deviceDataJSON)
166
+ let rehydratedDevice = try self . dehydratedDevices. rehydrate ( pickleKey: pickleKeyData, deviceId: dehydratedDevice. deviceId, deviceData: deviceDataJSON)
167
167
continuation. resume ( returning: . success( ( dehydratedDevice. deviceId, rehydratedDevice) ) )
168
168
} catch {
169
169
continuation. resume ( returning: . failure( DehydrationServiceError . failedRehydration ( error) ) )
0 commit comments