mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 11:25:38 +00:00
Fix NSKeyedUnarchiver usage
This commit is contained in:
parent
b7fbcbf118
commit
2091b47bb0
@ -10,3 +10,9 @@
|
||||
- (void)removeObjectForKey:(NSString *)aKey group:(NSString *)group;
|
||||
|
||||
@end
|
||||
|
||||
@interface MTDeprecated : NSObject
|
||||
|
||||
+ (id)unarchiveDeprecatedWithData:(NSData *)data;
|
||||
|
||||
@end
|
||||
|
||||
@ -82,6 +82,10 @@
|
||||
[bindRequestData appendInt32:expiresAt];
|
||||
[bindRequestData appendTLBytes:encryptedMessage];
|
||||
|
||||
if (MTLogEnabled()) {
|
||||
MTLog(@"[MTBindKeyMessageService#%p binding temp %" PRId64 " to persistent %" PRId64 "]", self, _ephemeralKey.authKeyId, _persistentKey.authKeyId);
|
||||
}
|
||||
|
||||
MTOutgoingMessage *outgoingMessage = [[MTOutgoingMessage alloc] initWithData:bindRequestData.data metadata:[NSString stringWithFormat:@"auth.bindTempAuthKey"] additionalDebugDescription:nil shortMetadata:@"auth.bindTempAuthKey" messageId:bindingMessageId messageSeqNo:bindingSeqNo];
|
||||
|
||||
return [[MTMessageTransaction alloc] initWithMessagePayload:@[outgoingMessage] prepared:nil failed:nil completion:^(NSDictionary *messageInternalIdToTransactionId, NSDictionary *messageInternalIdToPreparedMessage, __unused NSDictionary *messageInternalIdToQuickAckId) {
|
||||
|
||||
@ -1 +1,18 @@
|
||||
#import <MtProtoKit/MTKeychain.h>
|
||||
|
||||
@implementation MTDeprecated
|
||||
|
||||
+ (id)unarchiveDeprecatedWithData:(NSData *)data {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
@try {
|
||||
return [NSKeyedUnarchiver unarchiveObjectWithData:data];
|
||||
} @catch(NSException *e) {
|
||||
return nil;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@ -865,9 +865,9 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)outgoingMessageDescription:(MTOutgoingMessage *)message messageId:(int64_t)messageId messageSeqNo:(int32_t)messageSeqNo
|
||||
- (NSString *)outgoingMessageDescription:(MTOutgoingMessage *)message messageId:(int64_t)messageId messageSeqNo:(int32_t)messageSeqNo authKeyId:(int64_t)authKeyId
|
||||
{
|
||||
return [[NSString alloc] initWithFormat:@"%@%@ (%" PRId64 "/%" PRId32 ")", message.metadata, message.additionalDebugDescription != nil ? message.additionalDebugDescription : @"", message.messageId == 0 ? messageId : message.messageId, message.messageSeqNo == 0 ? message.messageSeqNo : messageSeqNo];
|
||||
return [[NSString alloc] initWithFormat:@"%@%@ (%" PRId64 "/%" PRId32 " %" PRId64 ")", message.metadata, message.additionalDebugDescription != nil ? message.additionalDebugDescription : @"", message.messageId == 0 ? messageId : message.messageId, message.messageSeqNo == 0 ? message.messageSeqNo : messageSeqNo, authKeyId];
|
||||
}
|
||||
|
||||
- (NSString *)outgoingShortMessageDescription:(MTOutgoingMessage *)message messageId:(int64_t)messageId messageSeqNo:(int32_t)messageSeqNo
|
||||
@ -1100,7 +1100,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
|
||||
NSData *data = messageData;
|
||||
|
||||
if (MTLogEnabled()) {
|
||||
NSString *messageDescription = [self outgoingMessageDescription:outgoingMessage messageId:messageId messageSeqNo:messageSeqNo];
|
||||
NSString *messageDescription = [self outgoingMessageDescription:outgoingMessage messageId:messageId messageSeqNo:messageSeqNo authKeyId:authKey.authKeyId];
|
||||
MTLogWithPrefix(_getLogPrefix, @"[MTProto#%p@%p preparing %@]", self, _context, messageDescription);
|
||||
}
|
||||
NSString *shortMessageDescription = [self outgoingShortMessageDescription:outgoingMessage messageId:messageId messageSeqNo:messageSeqNo];
|
||||
|
||||
@ -838,7 +838,7 @@ public func accountBackupData(postbox: Postbox) -> Signal<AccountBackupData?, No
|
||||
guard let authInfoData = transaction.keychainEntryForKey("persistent:datacenterAuthInfoById") else {
|
||||
return nil
|
||||
}
|
||||
guard let authInfo = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: authInfoData) else {
|
||||
guard let authInfo = MTDeprecated.unarchiveDeprecated(with: authInfoData) as? NSDictionary else {
|
||||
return nil
|
||||
}
|
||||
guard let datacenterAuthInfo = authInfo.object(forKey: state.masterDatacenterId as NSNumber) as? MTDatacenterAuthInfo else {
|
||||
|
||||
@ -18,6 +18,10 @@ public enum ConnectionStatus: Equatable {
|
||||
case online(proxyAddress: String?)
|
||||
}
|
||||
|
||||
public func legacy_unarchiveDeprecated(data: Data) -> Any? {
|
||||
return MTDeprecated.unarchiveDeprecated(with: data)
|
||||
}
|
||||
|
||||
private struct MTProtoConnectionFlags: OptionSet {
|
||||
let rawValue: Int
|
||||
|
||||
@ -1138,12 +1142,11 @@ class Keychain: NSObject, MTKeychain {
|
||||
}
|
||||
if let data = self.get(group + ":" + aKey) {
|
||||
var result: NSDictionary?
|
||||
MTContext.perform(objCTry: {
|
||||
result = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: data as Data)
|
||||
})
|
||||
result = MTDeprecated.unarchiveDeprecated(with: data as Data) as? NSDictionary
|
||||
if let result = result {
|
||||
return result as? [AnyHashable : Any]
|
||||
}
|
||||
assertionFailure("Unexpected keychain entry type")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -1154,10 +1157,11 @@ class Keychain: NSObject, MTKeychain {
|
||||
}
|
||||
if let data = self.get(group + ":" + aKey) {
|
||||
var result: NSNumber?
|
||||
MTContext.perform(objCTry: {
|
||||
result = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSNumber.self, from: data as Data)
|
||||
})
|
||||
return result
|
||||
result = MTDeprecated.unarchiveDeprecated(with: data as Data) as? NSNumber
|
||||
if let result = result {
|
||||
return result
|
||||
}
|
||||
assertionFailure("Unexpected keychain entry type")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ public func fetchVideoLibraryMediaResource(postbox: Postbox, resource: VideoLibr
|
||||
if let values = try? JSONDecoder().decode(MediaEditorValues.self, from: adjustmentsValue.data.makeData()) {
|
||||
mediaEditorValues = values
|
||||
}
|
||||
} else if let dict = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: adjustmentsValue.data.makeData()) as? [AnyHashable : Any], let legacyAdjustments = TGVideoEditAdjustments(dictionary: dict) {
|
||||
} else if let dict = legacy_unarchiveDeprecated(data: adjustmentsValue.data.makeData()) as? [AnyHashable : Any], let legacyAdjustments = TGVideoEditAdjustments(dictionary: dict) {
|
||||
if alwaysUseModernPipeline {
|
||||
mediaEditorValues = MediaEditorValues(legacyAdjustments: legacyAdjustments, defaultPreset: qualityPreset)
|
||||
} else {
|
||||
@ -500,7 +500,7 @@ public func fetchLocalFileVideoMediaResource(postbox: Postbox, resource: LocalFi
|
||||
if let values = try? JSONDecoder().decode(MediaEditorValues.self, from: videoAdjustments.data.makeData()) {
|
||||
mediaEditorValues = values
|
||||
}
|
||||
} else if let dict = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: videoAdjustments.data.makeData()) as? [AnyHashable : Any], let legacyAdjustments = TGVideoEditAdjustments(dictionary: dict) {
|
||||
} else if let dict = legacy_unarchiveDeprecated(data: videoAdjustments.data.makeData()) as? [AnyHashable : Any], let legacyAdjustments = TGVideoEditAdjustments(dictionary: dict) {
|
||||
if alwaysUseModernPipeline && !isImage {
|
||||
mediaEditorValues = MediaEditorValues(legacyAdjustments: legacyAdjustments, defaultPreset: qualityPreset)
|
||||
} else {
|
||||
@ -710,7 +710,7 @@ public func fetchVideoLibraryMediaResourceHash(resource: VideoLibraryMediaResour
|
||||
adjustments = nil
|
||||
case let .compress(adjustmentsValue):
|
||||
if let adjustmentsValue = adjustmentsValue {
|
||||
if let dict = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: adjustmentsValue.data.makeData()) as? [AnyHashable : Any], let legacyAdjustments = TGVideoEditAdjustments(dictionary: dict) {
|
||||
if let dict = legacy_unarchiveDeprecated(data: adjustmentsValue.data.makeData()) as? [AnyHashable : Any], let legacyAdjustments = TGVideoEditAdjustments(dictionary: dict) {
|
||||
adjustments = legacyAdjustments
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user