From 2db68dc4f5249051eb1989a0130fdf6bc39b24ad Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 22 Jul 2025 18:21:08 +0200 Subject: [PATCH] remove unused file BinaryMessageHandler.swift --- bitchat.xcodeproj/project.pbxproj | 6 - bitchat/Protocols/BinaryMessageHandler.swift | 124 ------------------- bitchat/Protocols/BinaryProtocol.swift | 2 +- 3 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 bitchat/Protocols/BinaryMessageHandler.swift diff --git a/bitchat.xcodeproj/project.pbxproj b/bitchat.xcodeproj/project.pbxproj index 5485d760..b8ed8204 100644 --- a/bitchat.xcodeproj/project.pbxproj +++ b/bitchat.xcodeproj/project.pbxproj @@ -9,9 +9,7 @@ /* Begin PBXBuildFile section */ 0245710AEAA58AD0A1425234 /* OptimizedBloomFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB043CA5EEB9AC8B07D61E97 /* OptimizedBloomFilter.swift */; }; 04636BBA2E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04636BB82E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift */; }; - 04636BBB2E2FAA1700FBCFA8 /* BinaryMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04636BB92E2FAA1700FBCFA8 /* BinaryMessageHandler.swift */; }; 04636BBC2E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04636BB82E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift */; }; - 04636BBD2E2FAA1700FBCFA8 /* BinaryMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04636BB92E2FAA1700FBCFA8 /* BinaryMessageHandler.swift */; }; 04636BBF2E2FCA8A00FBCFA8 /* SecureLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04636BBE2E2FCA8A00FBCFA8 /* SecureLogger.swift */; }; 04636BC02E2FCA8A00FBCFA8 /* SecureLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04636BBE2E2FCA8A00FBCFA8 /* SecureLogger.swift */; }; 04891CA92E22971E0064A111 /* LRUCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04891CA82E22971E0064A111 /* LRUCache.swift */; }; @@ -154,7 +152,6 @@ 036A1A705AAF9EC21F4354BE /* PasswordProtectedChannelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordProtectedChannelTests.swift; sourceTree = ""; }; 03C57F452B55FD0FD8F51421 /* bitchatTests_macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = bitchatTests_macOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 04636BB82E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryEncodingUtils.swift; sourceTree = ""; }; - 04636BB92E2FAA1700FBCFA8 /* BinaryMessageHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryMessageHandler.swift; sourceTree = ""; }; 04636BBE2E2FCA8A00FBCFA8 /* SecureLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureLogger.swift; sourceTree = ""; }; 04891CA82E22971E0064A111 /* LRUCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LRUCache.swift; sourceTree = ""; }; 04AD0B502E2678220002A40A /* BinaryProtocolVersionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocolVersionTests.swift; sourceTree = ""; }; @@ -327,7 +324,6 @@ isa = PBXGroup; children = ( 04636BB82E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift */, - 04636BB92E2FAA1700FBCFA8 /* BinaryMessageHandler.swift */, A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */, 229F17B68CFF7AB1BC91C847 /* BitchatProtocol.swift */, ); @@ -574,7 +570,6 @@ 04B6BA792E2166A50090FE39 /* NoiseTestingHelper.swift in Sources */, FB8819B4C84FAFEF5C36B216 /* KeychainManager.swift in Sources */, 04636BBA2E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift in Sources */, - 04636BBB2E2FAA1700FBCFA8 /* BinaryMessageHandler.swift in Sources */, 04AD0B4E2E25B9580002A40A /* IdentityModels.swift in Sources */, 04AD0B4F2E25B9580002A40A /* SecureIdentityStateManager.swift in Sources */, 31D147471B9F4E2815352DDA /* LinkPreviewView.swift in Sources */, @@ -611,7 +606,6 @@ 04B6BA7B2E2166A50090FE39 /* NoiseTestingHelper.swift in Sources */, 8F737CE0435792CC2AD65FCB /* KeychainManager.swift in Sources */, 04636BBC2E2FAA1700FBCFA8 /* BinaryEncodingUtils.swift in Sources */, - 04636BBD2E2FAA1700FBCFA8 /* BinaryMessageHandler.swift in Sources */, 0FBC81FF78CF4711B78E092A /* IdentityModels.swift in Sources */, 1AF9F9036DEE42408D557A87 /* SecureIdentityStateManager.swift in Sources */, 7A5B1AB5642FEC168E917949 /* LinkPreviewView.swift in Sources */, diff --git a/bitchat/Protocols/BinaryMessageHandler.swift b/bitchat/Protocols/BinaryMessageHandler.swift deleted file mode 100644 index 8c5241fa..00000000 --- a/bitchat/Protocols/BinaryMessageHandler.swift +++ /dev/null @@ -1,124 +0,0 @@ -// -// BinaryMessageHandler.swift -// bitchat -// -// Unified binary message encoding/decoding handler -// - -import Foundation - -struct BinaryMessageHandler { - - // MARK: - Encoding - - static func encode(message: Any, type: MessageType) -> Data? { - switch type { - case .deliveryAck: - return (message as? DeliveryAck)?.toBinaryData() - case .readReceipt: - return (message as? ReadReceipt)?.toBinaryData() - case .channelKeyVerifyRequest: - return (message as? ChannelKeyVerifyRequest)?.toBinaryData() - case .channelKeyVerifyResponse: - return (message as? ChannelKeyVerifyResponse)?.toBinaryData() - case .channelPasswordUpdate: - return (message as? ChannelPasswordUpdate)?.toBinaryData() - case .channelMetadata: - return (message as? ChannelMetadata)?.toBinaryData() - case .versionHello: - return (message as? VersionHello)?.toBinaryData() - case .versionAck: - return (message as? VersionAck)?.toBinaryData() - case .noiseIdentityAnnounce: - return (message as? NoiseIdentityAnnouncement)?.toBinaryData() - case .noiseHandshakeInit, .noiseHandshakeResp: - // Noise handshake messages are already binary - return message as? Data - case .noiseEncrypted: - return (message as? NoiseMessage)?.toBinaryData() - default: - return nil - } - } - - // MARK: - Decoding - - static func decode(data: Data, type: MessageType) -> Any? { - switch type { - case .deliveryAck: - return DeliveryAck.fromBinaryData(data) - case .readReceipt: - return ReadReceipt.fromBinaryData(data) - case .channelKeyVerifyRequest: - return ChannelKeyVerifyRequest.fromBinaryData(data) - case .channelKeyVerifyResponse: - return ChannelKeyVerifyResponse.fromBinaryData(data) - case .channelPasswordUpdate: - return ChannelPasswordUpdate.fromBinaryData(data) - case .channelMetadata: - return ChannelMetadata.fromBinaryData(data) - case .versionHello: - return VersionHello.fromBinaryData(data) - case .versionAck: - return VersionAck.fromBinaryData(data) - case .noiseIdentityAnnounce: - return NoiseIdentityAnnouncement.fromBinaryData(data) - case .noiseHandshakeInit, .noiseHandshakeResp: - // Noise handshake messages are already binary - return data - case .noiseEncrypted: - return NoiseMessage.fromBinaryData(data) - default: - return nil - } - } - - // MARK: - Legacy JSON Support (for migration) - - static func decodeJSON(data: Data, type: MessageType) -> Any? { - switch type { - case .deliveryAck: - return DeliveryAck.decode(from: data) - case .readReceipt: - return ReadReceipt.decode(from: data) - case .channelKeyVerifyRequest: - return ChannelKeyVerifyRequest.decode(from: data) - case .channelKeyVerifyResponse: - return ChannelKeyVerifyResponse.decode(from: data) - case .channelPasswordUpdate: - return ChannelPasswordUpdate.decode(from: data) - case .channelMetadata: - return ChannelMetadata.decode(from: data) - case .versionHello: - return VersionHello.decode(from: data) - case .versionAck: - return VersionAck.decode(from: data) - case .noiseIdentityAnnounce: - return NoiseIdentityAnnouncement.decode(from: data) - case .noiseEncrypted: - return NoiseMessage.decode(from: data) - default: - return nil - } - } - - // MARK: - Format Detection - - static func isBinaryFormat(_ data: Data) -> Bool { - // Simple heuristic: JSON always starts with { or [ - guard let firstByte = data.first else { return false } - return firstByte != 0x7B && firstByte != 0x5B // { and [ - } - - // MARK: - Unified Decode (with fallback) - - static func decodeWithFallback(data: Data, type: MessageType) -> Any? { - // Try binary first - if let result = decode(data: data, type: type) { - return result - } - - // Fallback to JSON for backward compatibility - return decodeJSON(data: data, type: type) - } -} \ No newline at end of file diff --git a/bitchat/Protocols/BinaryProtocol.swift b/bitchat/Protocols/BinaryProtocol.swift index 571e9b70..d0447d9f 100644 --- a/bitchat/Protocols/BinaryProtocol.swift +++ b/bitchat/Protocols/BinaryProtocol.swift @@ -516,4 +516,4 @@ extension BitchatMessage { ) return message } -} \ No newline at end of file +}