@@ -68,7 +68,7 @@ public class DehydrationService: NSObject {
6868 // Convert it back to Data
6969 let pickleKeyData = MXBase64Tools . data ( fromBase64: base64PickleKey)
7070
71- let rehydrationResult = await rehydrateDevice ( pickleKeyData: [ UInt8 ] ( pickleKeyData) )
71+ let rehydrationResult = await rehydrateDevice ( pickleKeyData: pickleKeyData)
7272 switch rehydrationResult {
7373 case . success( ( let deviceId, let rehydratedDevice) ) :
7474 // Fetch and process the to device events available on the dehydrated device
@@ -86,14 +86,15 @@ public class DehydrationService: NSObject {
8686 }
8787
8888 // Finally, create a new dehydrated device with the same pickle key
89- try await dehydrateDevice ( pickleKeyData: [ UInt8 ] ( pickleKeyData) )
89+ try await dehydrateDevice ( pickleKeyData: pickleKeyData)
9090 } else { // Otherwise, generate a new dehydration pickle key, store it and dehydrate a device
9191 // Generate a new dehydration pickle key
92- var pickleKeyData = [ UInt8] ( repeating: 0 , count: 32 )
93- _ = SecRandomCopyBytes ( kSecRandomDefault, 32 , & pickleKeyData)
92+ var pickleKeyRaw = [ UInt8] ( repeating: 0 , count: 32 )
93+ _ = SecRandomCopyBytes ( kSecRandomDefault, 32 , & pickleKeyRaw)
94+ let pickleKeyData = Data ( bytes: pickleKeyRaw, count: 32 )
9495
9596 // Convert it to unpadded base 64
96- let base64PickleKey = MXBase64Tools . unpaddedBase64 ( from: Data ( bytes : pickleKeyData, count : 32 ) )
97+ let base64PickleKey = MXBase64Tools . unpaddedBase64 ( from: pickleKeyData)
9798
9899 // Store it on the backend
99100 try await storeSecret ( base64PickleKey, secretId: secretId, secretStorageKeys: [ secretStorageKeyId: privateKeyData] )
@@ -131,10 +132,10 @@ public class DehydrationService: NSObject {
131132
132133 // MARK: - Device dehydration
133134
134- private func dehydrateDevice( pickleKeyData: [ UInt8 ] ) async throws {
135- let dehydratedDevice = dehydratedDevices. create ( )
135+ private func dehydrateDevice( pickleKeyData: Data ) async throws {
136+ let dehydratedDevice = try dehydratedDevices. create ( )
136137
137- let requestDetails = try dehydratedDevice. keysForUpload ( deviceDisplayName: deviceDisplayName, pickleKey: [ UInt8 ] ( pickleKeyData) )
138+ let requestDetails = try dehydratedDevice. keysForUpload ( deviceDisplayName: deviceDisplayName, pickleKey: pickleKeyData)
138139
139140 let parameters = MXDehydratedDeviceCreationParameters ( )
140141 parameters. body = requestDetails. body
@@ -150,7 +151,7 @@ public class DehydrationService: NSObject {
150151 }
151152 }
152153
153- private func rehydrateDevice( pickleKeyData: [ UInt8 ] ) async -> Result < ( deviceId: String , rehydratedDevice: RehydratedDeviceProtocol ) , DehydrationServiceError > {
154+ private func rehydrateDevice( pickleKeyData: Data ) async -> Result < ( deviceId: String , rehydratedDevice: RehydratedDeviceProtocol ) , DehydrationServiceError > {
154155 await withCheckedContinuation { continuation in
155156 self . restClient. retrieveDehydratedDevice { [ weak self] dehydratedDevice in
156157 guard let self else { return }
@@ -163,7 +164,7 @@ public class DehydrationService: NSObject {
163164 }
164165
165166 do {
166- let rehydratedDevice = try self . dehydratedDevices. rehydrate ( pickleKey: [ UInt8 ] ( pickleKeyData) , deviceId: dehydratedDevice. deviceId, deviceData: deviceDataJSON)
167+ let rehydratedDevice = try self . dehydratedDevices. rehydrate ( pickleKey: pickleKeyData, deviceId: dehydratedDevice. deviceId, deviceData: deviceDataJSON)
167168 continuation. resume ( returning: . success( ( dehydratedDevice. deviceId, rehydratedDevice) ) )
168169 } catch {
169170 continuation. resume ( returning: . failure( DehydrationServiceError . failedRehydration ( error) ) )
0 commit comments