From 81892e714e5e3f99e3dc03aab1dfdc76ec78da45 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 22 Aug 2018 15:44:18 +0300 Subject: [PATCH] no message --- TelegramCore.xcodeproj/project.pbxproj | 130 ++++++++++++++++++ TelegramCore/Account.swift | 2 +- TelegramCore/GrantSecureIdAccess.swift | 99 ++++++++++++- TelegramCore/Holes.swift | 2 +- TelegramCore/LoggingSettings.swift | 2 +- TelegramCore/Namespaces.swift | 4 +- TelegramCore/Reachability.m | 2 +- TelegramCore/RequestSecureIdForm.swift | 8 +- TelegramCore/SecretChatEncryptionConfig.swift | 8 +- TelegramCore/SecretChatKeychain.swift | 28 ++-- .../SecretChatOutgoingOperation.swift | 2 +- TelegramCore/SecretChatState.swift | 82 +++++------ 12 files changed, 295 insertions(+), 74 deletions(-) diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index 4571de527a..f533d19fdb 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -3308,6 +3308,132 @@ }; name = "Debug AppStore"; }; + D0ADF934212B3ADA00310BBC /* Debug AppStore LLC */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = "Debug AppStore LLC"; + }; + D0ADF935212B3ADA00310BBC /* Debug AppStore LLC */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + COPY_PHASE_STRIP = NO; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = X834Q8SBVP; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = 0; + INFOPLIST_FILE = TelegramCore/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/third-party/FFmpeg-iOS/lib", + "$(PROJECT_DIR)/third-party/libwebp/lib", + ); + MODULEMAP_PRIVATE_FILE = "$(SRCROOT)/TelegramCore/module.private.modulemap"; + OTHER_LDFLAGS = "-Wl,-dead_strip"; + OTHER_SWIFT_FLAGS = "-DDEBUG"; + PRODUCT_BUNDLE_IDENTIFIER = org.telegram.TelegramCore; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_REFLECTION_METADATA_LEVEL = none; + SWIFT_VERSION = 4.0; + USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; + }; + name = "Debug AppStore LLC"; + }; + D0ADF936212B3ADA00310BBC /* Debug AppStore LLC */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; + buildSettings = { + INFOPLIST_FILE = TelegramCoreTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = "Debug AppStore LLC"; + }; + D0ADF937212B3ADA00310BBC /* Debug AppStore LLC */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = TelegramCoreMac/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MODULEMAP_PRIVATE_FILE = "$(SRCROOT)/TelegramCore/module.private-mac.modulemap"; + OTHER_SWIFT_FLAGS = "-DDEBUG"; + PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreMac; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; + }; + name = "Debug AppStore LLC"; + }; D0B4186D1D7E03D5004562A4 /* Debug Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; @@ -3409,6 +3535,7 @@ buildConfigurations = ( D09D8C131D4FAB1D0081DBEC /* Debug Hockeyapp */, D09D8C141D4FAB1D0081DBEC /* Debug AppStore */, + D0ADF934212B3ADA00310BBC /* Debug AppStore LLC */, C22069BE1E8EB4A200E82730 /* Release Hockeyapp */, D0924FE81FE52C12003F693F /* Release Hockeyapp Internal */, D06706551D51162400DED3E3 /* Release AppStore */, @@ -3421,6 +3548,7 @@ buildConfigurations = ( D09D8C161D4FAB1D0081DBEC /* Debug Hockeyapp */, D09D8C171D4FAB1D0081DBEC /* Debug AppStore */, + D0ADF935212B3ADA00310BBC /* Debug AppStore LLC */, C22069BF1E8EB4A200E82730 /* Release Hockeyapp */, D0924FE91FE52C12003F693F /* Release Hockeyapp Internal */, D06706561D51162400DED3E3 /* Release AppStore */, @@ -3433,6 +3561,7 @@ buildConfigurations = ( D09D8C191D4FAB1D0081DBEC /* Debug Hockeyapp */, D09D8C1A1D4FAB1D0081DBEC /* Debug AppStore */, + D0ADF936212B3ADA00310BBC /* Debug AppStore LLC */, C22069C01E8EB4A200E82730 /* Release Hockeyapp */, D0924FEA1FE52C12003F693F /* Release Hockeyapp Internal */, D06706571D51162400DED3E3 /* Release AppStore */, @@ -3445,6 +3574,7 @@ buildConfigurations = ( D0B4186D1D7E03D5004562A4 /* Debug Hockeyapp */, D0B4186E1D7E03D5004562A4 /* Debug AppStore */, + D0ADF937212B3ADA00310BBC /* Debug AppStore LLC */, C22069C11E8EB4A200E82730 /* Release Hockeyapp */, D0924FEB1FE52C12003F693F /* Release Hockeyapp Internal */, D0B4186F1D7E03D5004562A4 /* Release AppStore */, diff --git a/TelegramCore/Account.swift b/TelegramCore/Account.swift index 1a3a2fa61d..412b33d9ef 100644 --- a/TelegramCore/Account.swift +++ b/TelegramCore/Account.swift @@ -288,7 +288,7 @@ let telegramPostboxSeedConfiguration: SeedConfiguration = { initializeMessageNamespacesWithHoles.append((peerNamespace, Namespaces.Message.Cloud)) } - return SeedConfiguration(initializeChatListWithHoles: [ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: 1))], initializeMessageNamespacesWithHoles: initializeMessageNamespacesWithHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: MessageTags.unseenPersonalMessage, existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat]) + return SeedConfiguration(initializeChatListWithHole: (topLevel: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1)), groups: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: 1))), initializeMessageNamespacesWithHoles: initializeMessageNamespacesWithHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: MessageTags.unseenPersonalMessage, existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat]) }() public func accountWithId(networkArguments: NetworkInitializationArguments, id: AccountRecordId, supplementary: Bool, rootPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods, shouldKeepAutoConnection: Bool = true) -> Signal { diff --git a/TelegramCore/GrantSecureIdAccess.swift b/TelegramCore/GrantSecureIdAccess.swift index 0980d3559a..12906e76f2 100644 --- a/TelegramCore/GrantSecureIdAccess.swift +++ b/TelegramCore/GrantSecureIdAccess.swift @@ -139,9 +139,98 @@ private func credentialsValueTypeName(value: SecureIdValue) -> String { } } -private func generateCredentials(values: [SecureIdValueWithContext], opaquePayload: Data) -> Data? { +private func generateCredentials(values: [SecureIdValueWithContext], requestedFields: [SecureIdRequestedFormField], opaquePayload: Data) -> Data? { var secureData: [String: Any] = [:] + + let requestedFieldValues = requestedFields.flatMap({ field -> [SecureIdRequestedFormFieldValue] in + switch field { + case let .just(value): + return [value] + case let .oneOf(values): + return values + } + }) + + let valueTypeToSkipFields: [SecureIdValueKey: (SecureIdRequestedFormFieldValue) -> (skipSelfie: Bool, skipTranslations: Bool)?] = [ + .idCard: { + if case let .idCard(selfie, translations) = $0 { + return (selfie, translations) + } else { + return nil + } + }, + .passport: { + if case let .passport(selfie, translations) = $0 { + return (selfie, translations) + } else { + return nil + } + }, + .driversLicense: { + if case let .driversLicense(selfie, translations) = $0 { + return (selfie, translations) + } else { + return nil + } + }, + .internalPassport: { + if case let .internalPassport(selfie, translations) = $0 { + return (selfie, translations) + } else { + return nil + } + }, + .passportRegistration: { + if case let .passportRegistration(translations) = $0 { + return (false, translations) + } else { + return nil + } + }, + .temporaryRegistration: { + if case let .temporaryRegistration(translations) = $0 { + return (false, translations) + } else { + return nil + } + }, + .utilityBill: { + if case let .utilityBill(translations) = $0 { + return (false, translations) + } else { + return nil + } + }, + .bankStatement: { + if case let .bankStatement(translations) = $0 { + return (false, translations) + } else { + return nil + } + }, + .rentalAgreement: { + if case let .rentalAgreement(translations) = $0 { + return (false, translations) + } else { + return nil + } + } + ] + + for value in values { + var skipSelfie = false + var skipTranslations = false + if let skipFilter = valueTypeToSkipFields[value.value.key] { + inner: for field in requestedFieldValues { + if let result = skipFilter(field) { + skipSelfie = result.skipSelfie + skipTranslations = result.skipTranslations + break inner + } + } + } + var valueDict: [String: Any] = [:] if let encryptedMetadata = value.encryptedMetadata { valueDict["data"] = [ @@ -159,7 +248,7 @@ private func generateCredentials(values: [SecureIdValueWithContext], opaquePaylo } } - if !value.translations.isEmpty { + if !skipTranslations && !value.translations.isEmpty { valueDict["translation"] = value.translations.map { file -> [String: Any] in return [ "file_hash": file.hash.base64EncodedString(), @@ -168,7 +257,7 @@ private func generateCredentials(values: [SecureIdValueWithContext], opaquePaylo } } - if let selfie = value.selfie { + if !skipSelfie, let selfie = value.selfie { valueDict["selfie"] = [ "file_hash": selfie.hash.base64EncodedString(), "secret": selfie.secret.base64EncodedString() @@ -221,14 +310,14 @@ public enum GrantSecureIdAccessError { case generic } -public func grantSecureIdAccess(network: Network, peerId: PeerId, publicKey: String, scope: String, opaquePayload: Data, values: [SecureIdValueWithContext]) -> Signal { +public func grantSecureIdAccess(network: Network, peerId: PeerId, publicKey: String, scope: String, opaquePayload: Data, values: [SecureIdValueWithContext], requestedFields: [SecureIdRequestedFormField]) -> Signal { guard peerId.namespace == Namespaces.Peer.CloudUser else { return .fail(.generic) } guard let credentialsSecretData = generateSecureSecretData() else { return .fail(.generic) } - guard let credentialsData = generateCredentials(values: values, opaquePayload: opaquePayload) else { + guard let credentialsData = generateCredentials(values: values, requestedFields: requestedFields, opaquePayload: opaquePayload) else { return .fail(.generic) } guard let (encryptedCredentialsData, decryptedCredentialsHash) = encryptedCredentialsData(data: credentialsData, secretData: credentialsSecretData) else { diff --git a/TelegramCore/Holes.swift b/TelegramCore/Holes.swift index fb0b9d7e69..12a4763ff7 100644 --- a/TelegramCore/Holes.swift +++ b/TelegramCore/Holes.swift @@ -482,7 +482,7 @@ func fetchChatListHole(postbox: Postbox, network: Network, groupId: PeerGroupId? transaction.replaceChatListHole(groupId: groupId, index: hole.index, hole: fetchedChats.lowerNonPinnedIndex.flatMap(ChatListHole.init)) for (feedGroupId, lowerIndex) in fetchedChats.feeds { - if let hole = postbox.seedConfiguration.initializeChatListWithHoles.first { + if let hole = postbox.seedConfiguration.initializeChatListWithHole.groups { transaction.replaceChatListHole(groupId: feedGroupId, index: hole.index, hole: lowerIndex.flatMap(ChatListHole.init)) } } diff --git a/TelegramCore/LoggingSettings.swift b/TelegramCore/LoggingSettings.swift index b9d7676454..32095bd886 100644 --- a/TelegramCore/LoggingSettings.swift +++ b/TelegramCore/LoggingSettings.swift @@ -15,7 +15,7 @@ public final class LoggingSettings: PreferencesEntry, Equatable { public let redactSensitiveData: Bool #if DEBUG - public static var defaultSettings = LoggingSettings(logToFile: true, logToConsole: true, redactSensitiveData: true) + public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true) #else public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true) #endif diff --git a/TelegramCore/Namespaces.swift b/TelegramCore/Namespaces.swift index 595991dcd1..ce31494050 100644 --- a/TelegramCore/Namespaces.swift +++ b/TelegramCore/Namespaces.swift @@ -107,8 +107,8 @@ public extension PendingMessageActionType { let peerIdNamespacesWithInitialCloudMessageHoles = [Namespaces.Peer.CloudUser, Namespaces.Peer.CloudGroup, Namespaces.Peer.CloudChannel] -struct OperationLogTags { - static let SecretOutgoing = PeerOperationLogTag(value: 0) +public struct OperationLogTags { + public static let SecretOutgoing = PeerOperationLogTag(value: 0) static let SecretIncomingEncrypted = PeerOperationLogTag(value: 1) static let SecretIncomingDecrypted = PeerOperationLogTag(value: 2) static let CloudChatRemoveMessages = PeerOperationLogTag(value: 3) diff --git a/TelegramCore/Reachability.m b/TelegramCore/Reachability.m index a347082c68..be67002fa3 100644 --- a/TelegramCore/Reachability.m +++ b/TelegramCore/Reachability.m @@ -28,7 +28,7 @@ NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotifi #pragma mark - Supporting functions -#define kShouldPrintReachabilityFlags 1 +#define kShouldPrintReachabilityFlags 0 static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) { diff --git a/TelegramCore/RequestSecureIdForm.swift b/TelegramCore/RequestSecureIdForm.swift index af66edc321..988d763d03 100644 --- a/TelegramCore/RequestSecureIdForm.swift +++ b/TelegramCore/RequestSecureIdForm.swift @@ -229,8 +229,10 @@ func parseSecureValue(context: SecureIdAccessContext, value: Api.SecureValue, er } } -private func parseSecureValues(context: SecureIdAccessContext, values: [Api.SecureValue], errors: [Api.SecureValueError]) -> [SecureIdValueWithContext] { - return values.map({ parseSecureValue(context: context, value: $0, errors: errors) }).compactMap({ $0?.valueWithContext }) +private func parseSecureValues(context: SecureIdAccessContext, values: [Api.SecureValue], errors: [Api.SecureValueError], requestedFields: [SecureIdRequestedFormField]) -> [SecureIdValueWithContext] { + return values.map({ apiValue in + return parseSecureValue(context: context, value: apiValue, errors: errors) + }).compactMap({ $0?.valueWithContext }) } public struct EncryptedSecureIdForm { @@ -291,5 +293,5 @@ public func requestSecureIdForm(postbox: Postbox, network: Network, peerId: Peer } public func decryptedSecureIdForm(context: SecureIdAccessContext, form: EncryptedSecureIdForm) -> SecureIdForm? { - return SecureIdForm(peerId: form.peerId, requestedFields: form.requestedFields, values: parseSecureValues(context: context, values: form.encryptedValues, errors: form.errors)) + return SecureIdForm(peerId: form.peerId, requestedFields: form.requestedFields, values: parseSecureValues(context: context, values: form.encryptedValues, errors: form.errors, requestedFields: form.requestedFields)) } diff --git a/TelegramCore/SecretChatEncryptionConfig.swift b/TelegramCore/SecretChatEncryptionConfig.swift index 160a69e8b4..ca751986e3 100644 --- a/TelegramCore/SecretChatEncryptionConfig.swift +++ b/TelegramCore/SecretChatEncryptionConfig.swift @@ -9,24 +9,24 @@ import Foundation import MtProtoKitDynamic #endif -final class SecretChatEncryptionConfig: PostboxCoding { +public final class SecretChatEncryptionConfig: PostboxCoding { let g: Int32 let p: MemoryBuffer let version: Int32 - init(g: Int32, p: MemoryBuffer, version: Int32) { + public init(g: Int32, p: MemoryBuffer, version: Int32) { self.g = g self.p = p self.version = version } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.g = decoder.decodeInt32ForKey("g", orElse: 0) self.p = decoder.decodeBytesForKey("p")! self.version = decoder.decodeInt32ForKey("v", orElse: 0) } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt32(self.g, forKey: "g") encoder.encodeBytes(self.p, forKey: "p") encoder.encodeInt32(self.version, forKey: "v") diff --git a/TelegramCore/SecretChatKeychain.swift b/TelegramCore/SecretChatKeychain.swift index 563624e714..90959dfe61 100644 --- a/TelegramCore/SecretChatKeychain.swift +++ b/TelegramCore/SecretChatKeychain.swift @@ -5,11 +5,11 @@ import Foundation import Postbox #endif -enum SecretChatKeyValidity: PostboxCoding, Equatable { +public enum SecretChatKeyValidity: PostboxCoding, Equatable { case indefinite case sequenceBasedIndexRange(fromCanonicalIndex: Int32) - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("r", orElse: 0) { case 0: self = .indefinite @@ -21,7 +21,7 @@ enum SecretChatKeyValidity: PostboxCoding, Equatable { } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { switch self { case .indefinite: encoder.encodeInt32(0, forKey: "r") @@ -31,7 +31,7 @@ enum SecretChatKeyValidity: PostboxCoding, Equatable { } } - static func ==(lhs: SecretChatKeyValidity, rhs: SecretChatKeyValidity) -> Bool { + public static func ==(lhs: SecretChatKeyValidity, rhs: SecretChatKeyValidity) -> Bool { switch lhs { case .indefinite: if case .indefinite = rhs { @@ -49,27 +49,27 @@ enum SecretChatKeyValidity: PostboxCoding, Equatable { } } -final class SecretChatKey: PostboxCoding, Equatable { +public final class SecretChatKey: PostboxCoding, Equatable { let fingerprint: Int64 let key: MemoryBuffer let validity: SecretChatKeyValidity let useCount: Int32 - init(fingerprint: Int64, key: MemoryBuffer, validity: SecretChatKeyValidity, useCount: Int32) { + public init(fingerprint: Int64, key: MemoryBuffer, validity: SecretChatKeyValidity, useCount: Int32) { self.fingerprint = fingerprint self.key = key self.validity = validity self.useCount = useCount } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.fingerprint = decoder.decodeInt64ForKey("f", orElse: 0) self.key = decoder.decodeBytesForKey("k")! self.validity = decoder.decodeObjectForKey("v", decoder: { SecretChatKeyValidity(decoder: $0) }) as! SecretChatKeyValidity self.useCount = decoder.decodeInt32ForKey("u", orElse: 0) } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt64(self.fingerprint, forKey: "f") encoder.encodeBytes(self.key, forKey: "k") encoder.encodeObject(self.validity, forKey: "v") @@ -80,7 +80,7 @@ final class SecretChatKey: PostboxCoding, Equatable { return SecretChatKey(fingerprint: self.fingerprint, key: self.key, validity: self.validity, useCount: self.useCount + 1) } - static func ==(lhs: SecretChatKey, rhs: SecretChatKey) -> Bool { + public static func ==(lhs: SecretChatKey, rhs: SecretChatKey) -> Bool { if lhs.fingerprint != rhs.fingerprint { return false } @@ -94,18 +94,18 @@ final class SecretChatKey: PostboxCoding, Equatable { } } -final class SecretChatKeychain: PostboxCoding, Equatable { +public final class SecretChatKeychain: PostboxCoding, Equatable { let keys: [SecretChatKey] - init(keys: [SecretChatKey]) { + public init(keys: [SecretChatKey]) { self.keys = keys } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.keys = decoder.decodeObjectArrayWithDecoderForKey("k") } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeObjectArray(self.keys, forKey: "k") } @@ -182,7 +182,7 @@ final class SecretChatKeychain: PostboxCoding, Equatable { return SecretChatKeychain(keys: keys) } - static func ==(lhs: SecretChatKeychain, rhs: SecretChatKeychain) -> Bool { + public static func ==(lhs: SecretChatKeychain, rhs: SecretChatKeychain) -> Bool { return lhs.keys == rhs.keys } } diff --git a/TelegramCore/SecretChatOutgoingOperation.swift b/TelegramCore/SecretChatOutgoingOperation.swift index f3c22df360..9077e8be15 100644 --- a/TelegramCore/SecretChatOutgoingOperation.swift +++ b/TelegramCore/SecretChatOutgoingOperation.swift @@ -76,7 +76,7 @@ struct SecretChatOutgoingFile: PostboxCoding { } } -enum SecretChatSequenceBasedLayer: Int32 { +public enum SecretChatSequenceBasedLayer: Int32 { case layer46 = 46 case layer73 = 73 diff --git a/TelegramCore/SecretChatState.swift b/TelegramCore/SecretChatState.swift index 695ea0d74c..4fca04dae7 100644 --- a/TelegramCore/SecretChatState.swift +++ b/TelegramCore/SecretChatState.swift @@ -21,7 +21,7 @@ public struct SecretChatKeySha1Fingerprint: PostboxCoding, Equatable { public let k1: Int64 public let k2: Int32 - init(digest: Data) { + public init(digest: Data) { assert(digest.count == 20) var k0: Int64 = 0 var k1: Int64 = 0 @@ -89,7 +89,7 @@ public struct SecretChatKeySha256Fingerprint: PostboxCoding, Equatable { public let k2: Int64 public let k3: Int64 - init(digest: Data) { + public init(digest: Data) { assert(digest.count == 32) var k0: Int64 = 0 var k1: Int64 = 0 @@ -161,7 +161,7 @@ public struct SecretChatKeyFingerprint: PostboxCoding, Equatable { public let sha1: SecretChatKeySha1Fingerprint public let sha256: SecretChatKeySha256Fingerprint - init(sha1: SecretChatKeySha1Fingerprint, sha256: SecretChatKeySha256Fingerprint) { + public init(sha1: SecretChatKeySha1Fingerprint, sha256: SecretChatKeySha256Fingerprint) { self.sha1 = sha1 self.sha256 = sha256 } @@ -194,11 +194,11 @@ private enum SecretChatEmbeddedStateValue: Int32 { case sequenceBasedLayer = 3 } -enum SecretChatHandshakeState: PostboxCoding, Equatable { +public enum SecretChatHandshakeState: PostboxCoding, Equatable { case accepting case requested(g: Int32, p: MemoryBuffer, a: MemoryBuffer) - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("r", orElse: 0) { case 0: self = .accepting @@ -210,7 +210,7 @@ enum SecretChatHandshakeState: PostboxCoding, Equatable { } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { switch self { case .accepting: encoder.encodeInt32(0, forKey: "r") @@ -222,7 +222,7 @@ enum SecretChatHandshakeState: PostboxCoding, Equatable { } } - static func ==(lhs: SecretChatHandshakeState, rhs: SecretChatHandshakeState) -> Bool { + public static func ==(lhs: SecretChatHandshakeState, rhs: SecretChatHandshakeState) -> Bool { switch lhs { case .accepting: if case .accepting = rhs { @@ -240,24 +240,24 @@ enum SecretChatHandshakeState: PostboxCoding, Equatable { } } -struct SecretChatLayerNegotiationState: PostboxCoding, Equatable { +public struct SecretChatLayerNegotiationState: PostboxCoding, Equatable { let activeLayer: SecretChatSequenceBasedLayer let locallyRequestedLayer: Int32? let remotelyRequestedLayer: Int32? - init(activeLayer: SecretChatSequenceBasedLayer, locallyRequestedLayer: Int32?, remotelyRequestedLayer: Int32?) { + public init(activeLayer: SecretChatSequenceBasedLayer, locallyRequestedLayer: Int32?, remotelyRequestedLayer: Int32?) { self.activeLayer = activeLayer self.locallyRequestedLayer = locallyRequestedLayer self.remotelyRequestedLayer = remotelyRequestedLayer } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.activeLayer = SecretChatSequenceBasedLayer(rawValue: decoder.decodeInt32ForKey("a", orElse: 0)) ?? .layer46 self.locallyRequestedLayer = decoder.decodeOptionalInt32ForKey("lr") self.remotelyRequestedLayer = decoder.decodeOptionalInt32ForKey("rr") } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt32(self.activeLayer.rawValue, forKey: "a") if let locallyRequestedLayer = self.locallyRequestedLayer { encoder.encodeInt32(locallyRequestedLayer, forKey: "lr") @@ -271,7 +271,7 @@ struct SecretChatLayerNegotiationState: PostboxCoding, Equatable { } } - static func ==(lhs: SecretChatLayerNegotiationState, rhs: SecretChatLayerNegotiationState) -> Bool { + public static func ==(lhs: SecretChatLayerNegotiationState, rhs: SecretChatLayerNegotiationState) -> Bool { if lhs.activeLayer != rhs.activeLayer { return false } @@ -304,13 +304,13 @@ private enum SecretChatRekeySessionDataValue: Int32 { case accepted = 3 } -enum SecretChatRekeySessionData: PostboxCoding, Equatable { +public enum SecretChatRekeySessionData: PostboxCoding, Equatable { case requesting case requested(a: MemoryBuffer, config: SecretChatEncryptionConfig) case accepting case accepted(key: MemoryBuffer, keyFingerprint: Int64) - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("r", orElse: 0) { case SecretChatRekeySessionDataValue.requesting.rawValue: self = .requesting @@ -325,7 +325,7 @@ enum SecretChatRekeySessionData: PostboxCoding, Equatable { } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { switch self { case .requesting: encoder.encodeInt32(SecretChatRekeySessionDataValue.requesting.rawValue, forKey: "r") @@ -342,7 +342,7 @@ enum SecretChatRekeySessionData: PostboxCoding, Equatable { } } - static func ==(lhs: SecretChatRekeySessionData, rhs: SecretChatRekeySessionData) -> Bool { + public static func ==(lhs: SecretChatRekeySessionData, rhs: SecretChatRekeySessionData) -> Bool { switch lhs { case .requesting: if case .requesting = rhs { @@ -372,26 +372,26 @@ enum SecretChatRekeySessionData: PostboxCoding, Equatable { } } -struct SecretChatRekeySessionState: PostboxCoding, Equatable { +public struct SecretChatRekeySessionState: PostboxCoding, Equatable { let id: Int64 let data: SecretChatRekeySessionData - init(id: Int64, data: SecretChatRekeySessionData) { + public init(id: Int64, data: SecretChatRekeySessionData) { self.id = id self.data = data } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.id = decoder.decodeInt64ForKey("i", orElse: 0) self.data = decoder.decodeObjectForKey("d", decoder: { SecretChatRekeySessionData(decoder: $0) }) as! SecretChatRekeySessionData } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt64(self.id, forKey: "i") encoder.encodeObject(self.data, forKey: "d") } - static func ==(lhs: SecretChatRekeySessionState, rhs: SecretChatRekeySessionState) -> Bool { + public static func ==(lhs: SecretChatRekeySessionState, rhs: SecretChatRekeySessionState) -> Bool { if lhs.id != rhs.id { return false } @@ -402,14 +402,14 @@ struct SecretChatRekeySessionState: PostboxCoding, Equatable { } } -struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { +public struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { let layerNegotiationState: SecretChatLayerNegotiationState let rekeyState: SecretChatRekeySessionState? - let baseIncomingOperationIndex: Int32 - let baseOutgoingOperationIndex: Int32 + public let baseIncomingOperationIndex: Int32 + public let baseOutgoingOperationIndex: Int32 let topProcessedCanonicalIncomingOperationIndex: Int32? - init(layerNegotiationState: SecretChatLayerNegotiationState, rekeyState: SecretChatRekeySessionState?, baseIncomingOperationIndex: Int32, baseOutgoingOperationIndex: Int32, topProcessedCanonicalIncomingOperationIndex: Int32?) { + public init(layerNegotiationState: SecretChatLayerNegotiationState, rekeyState: SecretChatRekeySessionState?, baseIncomingOperationIndex: Int32, baseOutgoingOperationIndex: Int32, topProcessedCanonicalIncomingOperationIndex: Int32?) { self.layerNegotiationState = layerNegotiationState self.rekeyState = rekeyState self.baseIncomingOperationIndex = baseIncomingOperationIndex @@ -417,7 +417,7 @@ struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { self.topProcessedCanonicalIncomingOperationIndex = topProcessedCanonicalIncomingOperationIndex } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.layerNegotiationState = decoder.decodeObjectForKey("ln", decoder: { SecretChatLayerNegotiationState(decoder: $0) }) as! SecretChatLayerNegotiationState self.rekeyState = decoder.decodeObjectForKey("rs", decoder: { SecretChatRekeySessionState(decoder: $0) }) as? SecretChatRekeySessionState self.baseIncomingOperationIndex = decoder.decodeInt32ForKey("bi", orElse: 0) @@ -429,7 +429,7 @@ struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeObject(self.layerNegotiationState, forKey: "ln") if let rekeyState = self.rekeyState { encoder.encodeObject(rekeyState, forKey: "rs") @@ -469,7 +469,7 @@ struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { return SecretChatSequenceBasedLayerState(layerNegotiationState: self.layerNegotiationState, rekeyState: self.rekeyState, baseIncomingOperationIndex: self.baseIncomingOperationIndex, baseOutgoingOperationIndex: self.baseOutgoingOperationIndex, topProcessedCanonicalIncomingOperationIndex: topProcessedCanonicalIncomingOperationIndex) } - static func ==(lhs: SecretChatSequenceBasedLayerState, rhs: SecretChatSequenceBasedLayerState) -> Bool { + public static func ==(lhs: SecretChatSequenceBasedLayerState, rhs: SecretChatSequenceBasedLayerState) -> Bool { if lhs.layerNegotiationState != rhs.layerNegotiationState { return false } @@ -486,13 +486,13 @@ struct SecretChatSequenceBasedLayerState: PostboxCoding, Equatable { } } -enum SecretChatEmbeddedState: PostboxCoding, Equatable { +public enum SecretChatEmbeddedState: PostboxCoding, Equatable { case terminated case handshake(SecretChatHandshakeState) case basicLayer case sequenceBasedLayer(SecretChatSequenceBasedLayerState) - var peerState: SecretChatEmbeddedPeerState { + public var peerState: SecretChatEmbeddedPeerState { switch self { case .terminated: return .terminated @@ -503,7 +503,7 @@ enum SecretChatEmbeddedState: PostboxCoding, Equatable { } } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("r", orElse: 0) { case SecretChatEmbeddedStateValue.terminated.rawValue: self = .terminated @@ -519,7 +519,7 @@ enum SecretChatEmbeddedState: PostboxCoding, Equatable { } } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { switch self { case .terminated: encoder.encodeInt32(SecretChatEmbeddedStateValue.terminated.rawValue, forKey: "r") @@ -534,7 +534,7 @@ enum SecretChatEmbeddedState: PostboxCoding, Equatable { } } - static func ==(lhs: SecretChatEmbeddedState, rhs: SecretChatEmbeddedState) -> Bool { + public static func ==(lhs: SecretChatEmbeddedState, rhs: SecretChatEmbeddedState) -> Bool { switch lhs { case .terminated: if case .terminated = rhs { @@ -568,14 +568,14 @@ public protocol SecretChatKeyState { var keyFingerprint: SecretChatKeyFingerprint? { get } } -final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable { +public final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable { let role: SecretChatRole - let embeddedState: SecretChatEmbeddedState + public let embeddedState: SecretChatEmbeddedState let keychain: SecretChatKeychain - let keyFingerprint: SecretChatKeyFingerprint? + public let keyFingerprint: SecretChatKeyFingerprint? let messageAutoremoveTimeout: Int32? - init(role: SecretChatRole, embeddedState: SecretChatEmbeddedState, keychain: SecretChatKeychain, keyFingerprint: SecretChatKeyFingerprint?, messageAutoremoveTimeout: Int32?) { + public init(role: SecretChatRole, embeddedState: SecretChatEmbeddedState, keychain: SecretChatKeychain, keyFingerprint: SecretChatKeyFingerprint?, messageAutoremoveTimeout: Int32?) { self.role = role self.embeddedState = embeddedState self.keychain = keychain @@ -583,7 +583,7 @@ final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable { self.messageAutoremoveTimeout = messageAutoremoveTimeout } - init(decoder: PostboxDecoder) { + public init(decoder: PostboxDecoder) { self.role = SecretChatRole(rawValue: decoder.decodeInt32ForKey("r", orElse: 0))! self.embeddedState = decoder.decodeObjectForKey("s", decoder: { return SecretChatEmbeddedState(decoder: $0) }) as! SecretChatEmbeddedState self.keychain = decoder.decodeObjectForKey("k", decoder: { return SecretChatKeychain(decoder: $0) }) as! SecretChatKeychain @@ -591,7 +591,7 @@ final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable { self.messageAutoremoveTimeout = decoder.decodeOptionalInt32ForKey("a") } - func encode(_ encoder: PostboxEncoder) { + public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt32(self.role.rawValue, forKey: "r") encoder.encodeObject(self.embeddedState, forKey: "s") encoder.encodeObject(self.keychain, forKey: "k") @@ -607,14 +607,14 @@ final class SecretChatState: PeerChatState, SecretChatKeyState, Equatable { } } - func equals(_ other: PeerChatState) -> Bool { + public func equals(_ other: PeerChatState) -> Bool { if let other = other as? SecretChatState, other == self { return true } return false } - static func ==(lhs: SecretChatState, rhs: SecretChatState) -> Bool { + public static func ==(lhs: SecretChatState, rhs: SecretChatState) -> Bool { return lhs.role == rhs.role && lhs.embeddedState == rhs.embeddedState && lhs.keychain == rhs.keychain && lhs.messageAutoremoveTimeout == rhs.messageAutoremoveTimeout }