mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Backup more data
This commit is contained in:
parent
3db9593f49
commit
e85144997f
@ -200,6 +200,16 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
||||
state = backupState
|
||||
let dict = NSMutableDictionary()
|
||||
dict.setObject(MTDatacenterAuthInfo(authKey: backupData.masterDatacenterKey, authKeyId: backupData.masterDatacenterKeyId, saltSet: [], authKeyAttributes: [:])!, forKey: backupData.masterDatacenterId as NSNumber)
|
||||
|
||||
for (id, datacenterKey) in backupData.additionalDatacenterKeys {
|
||||
dict.setObject(MTDatacenterAuthInfo(
|
||||
authKey: datacenterKey.key,
|
||||
authKeyId: datacenterKey.keyId,
|
||||
saltSet: [],
|
||||
authKeyAttributes: [:]
|
||||
)!, forKey: id as NSNumber)
|
||||
}
|
||||
|
||||
let data = NSKeyedArchiver.archivedData(withRootObject: dict)
|
||||
transaction.setState(backupState)
|
||||
transaction.setKeychainEntry(data, forKey: "persistent:datacenterAuthInfoById")
|
||||
@ -807,6 +817,34 @@ public func accountBackupData(postbox: Postbox) -> Signal<AccountBackupData?, No
|
||||
guard let datacenterAuthInfo = authInfo.object(forKey: state.masterDatacenterId as NSNumber) as? MTDatacenterAuthInfo else {
|
||||
return nil
|
||||
}
|
||||
|
||||
var additionalDatacenterKeys: [Int32: AccountBackupData.DatacenterKey] = [:]
|
||||
for item in authInfo {
|
||||
guard let idNumber = item.key as? NSNumber else {
|
||||
continue
|
||||
}
|
||||
guard let id = idNumber as? Int32 else {
|
||||
continue
|
||||
}
|
||||
if id <= 0 || id > 10 {
|
||||
continue
|
||||
}
|
||||
if id == state.masterDatacenterId {
|
||||
continue
|
||||
}
|
||||
guard let otherDatacenterAuthInfo = authInfo.object(forKey: idNumber) as? MTDatacenterAuthInfo else {
|
||||
continue
|
||||
}
|
||||
guard let otherAuthKey = otherDatacenterAuthInfo.authKey else {
|
||||
continue
|
||||
}
|
||||
additionalDatacenterKeys[id] = AccountBackupData.DatacenterKey(
|
||||
id: id,
|
||||
keyId: otherDatacenterAuthInfo.authKeyId,
|
||||
key: otherAuthKey
|
||||
)
|
||||
}
|
||||
|
||||
guard let authKey = datacenterAuthInfo.authKey else {
|
||||
return nil
|
||||
}
|
||||
@ -817,7 +855,8 @@ public func accountBackupData(postbox: Postbox) -> Signal<AccountBackupData?, No
|
||||
masterDatacenterKey: authKey,
|
||||
masterDatacenterKeyId: datacenterAuthInfo.authKeyId,
|
||||
notificationEncryptionKeyId: notificationsKey?.id,
|
||||
notificationEncryptionKey: notificationsKey?.data
|
||||
notificationEncryptionKey: notificationsKey?.data,
|
||||
additionalDatacenterKeys: additionalDatacenterKeys
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,39 @@ import Foundation
|
||||
import Postbox
|
||||
|
||||
public struct AccountBackupData: Codable, Equatable {
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case masterDatacenterId
|
||||
case peerId
|
||||
case masterDatacenterKey
|
||||
case masterDatacenterKeyId
|
||||
case notificationEncryptionKeyId
|
||||
case notificationEncryptionKey
|
||||
case additionalDatacenterKeys
|
||||
}
|
||||
|
||||
public struct DatacenterKey: Codable, Equatable {
|
||||
public var id: Int32
|
||||
public var keyId: Int64
|
||||
public var key: Data
|
||||
|
||||
public init(
|
||||
id: Int32,
|
||||
keyId: Int64,
|
||||
key: Data
|
||||
) {
|
||||
self.id = id
|
||||
self.keyId = keyId
|
||||
self.key = key
|
||||
}
|
||||
}
|
||||
|
||||
public var masterDatacenterId: Int32
|
||||
public var peerId: Int64
|
||||
public var masterDatacenterKey: Data
|
||||
public var masterDatacenterKeyId: Int64
|
||||
public var notificationEncryptionKeyId: Data?
|
||||
public var notificationEncryptionKey: Data?
|
||||
public var additionalDatacenterKeys: [Int32: DatacenterKey]
|
||||
|
||||
public init(
|
||||
masterDatacenterId: Int32,
|
||||
@ -15,7 +42,8 @@ public struct AccountBackupData: Codable, Equatable {
|
||||
masterDatacenterKey: Data,
|
||||
masterDatacenterKeyId: Int64,
|
||||
notificationEncryptionKeyId: Data?,
|
||||
notificationEncryptionKey: Data?
|
||||
notificationEncryptionKey: Data?,
|
||||
additionalDatacenterKeys: [Int32: DatacenterKey]
|
||||
) {
|
||||
self.masterDatacenterId = masterDatacenterId
|
||||
self.peerId = peerId
|
||||
@ -23,6 +51,31 @@ public struct AccountBackupData: Codable, Equatable {
|
||||
self.masterDatacenterKeyId = masterDatacenterKeyId
|
||||
self.notificationEncryptionKeyId = notificationEncryptionKeyId
|
||||
self.notificationEncryptionKey = notificationEncryptionKey
|
||||
self.additionalDatacenterKeys = additionalDatacenterKeys
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self.masterDatacenterId = try container.decode(Int32.self, forKey: .masterDatacenterId)
|
||||
self.peerId = try container.decode(Int64.self, forKey: .peerId)
|
||||
self.masterDatacenterKey = try container.decode(Data.self, forKey: .masterDatacenterKey)
|
||||
self.masterDatacenterKeyId = try container.decode(Int64.self, forKey: .masterDatacenterKeyId)
|
||||
self.notificationEncryptionKeyId = try container.decodeIfPresent(Data.self, forKey: .notificationEncryptionKeyId)
|
||||
self.notificationEncryptionKey = try container.decodeIfPresent(Data.self, forKey: .notificationEncryptionKey)
|
||||
self.additionalDatacenterKeys = try container.decodeIfPresent([Int32: DatacenterKey].self, forKey: .additionalDatacenterKeys) ?? [:]
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encode(self.masterDatacenterId, forKey: .masterDatacenterId)
|
||||
try container.encode(self.peerId, forKey: .peerId)
|
||||
try container.encode(self.masterDatacenterKey, forKey: .masterDatacenterKey)
|
||||
try container.encode(self.masterDatacenterKeyId, forKey: .masterDatacenterKeyId)
|
||||
try container.encodeIfPresent(self.notificationEncryptionKeyId, forKey: .notificationEncryptionKeyId)
|
||||
try container.encodeIfPresent(self.notificationEncryptionKey, forKey: .notificationEncryptionKey)
|
||||
try container.encode(self.additionalDatacenterKeys, forKey: .additionalDatacenterKeys)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user