From d6b80ea44953ed19e14b22d4cc284f95b0c3bd67 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 4 Sep 2018 22:18:24 +0200 Subject: [PATCH 1/2] Implement Codable in public entities Also rename CompressionFraming for being an extension of SessionProxy. --- TunnelKit.xcodeproj/project.pbxproj | 28 ++++--------------- .../AppExtension/CryptoContainer.swift | 14 ++++++++++ .../TunnelKitProvider+Configuration.swift | 16 ++++++++++- ... => SessionProxy+CompressionFraming.swift} | 4 +-- .../Core/SessionProxy+Configuration.swift | 6 ++-- 5 files changed, 40 insertions(+), 28 deletions(-) rename TunnelKit/Sources/Core/{CompressionFraming.swift => SessionProxy+CompressionFraming.swift} (94%) diff --git a/TunnelKit.xcodeproj/project.pbxproj b/TunnelKit.xcodeproj/project.pbxproj index 1b56fb6..c2ce88e 100644 --- a/TunnelKit.xcodeproj/project.pbxproj +++ b/TunnelKit.xcodeproj/project.pbxproj @@ -62,8 +62,8 @@ 0EC1BBA920D7D803007C4C7B /* ConnectionStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EC1BBA720D7D803007C4C7B /* ConnectionStrategy.swift */; }; 0ECE3528212EB7770040F253 /* CryptoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3527212EB7770040F253 /* CryptoContainer.swift */; }; 0ECE352A212EB88E0040F253 /* CryptoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ECE3527212EB7770040F253 /* CryptoContainer.swift */; }; - 0ED9C8642138139000621BA3 /* CompressionFraming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C8632138139000621BA3 /* CompressionFraming.swift */; }; - 0ED9C8652138139000621BA3 /* CompressionFraming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C8632138139000621BA3 /* CompressionFraming.swift */; }; + 0ED9C8642138139000621BA3 /* SessionProxy+CompressionFraming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */; }; + 0ED9C8652138139000621BA3 /* SessionProxy+CompressionFraming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */; }; 0EE7A79520F61EDC00B42E6A /* PacketMacros.h in Sources */ = {isa = PBXBuildFile; fileRef = 0EE7A79420F61EDC00B42E6A /* PacketMacros.h */; }; 0EE7A79620F61EDC00B42E6A /* PacketMacros.h in Sources */ = {isa = PBXBuildFile; fileRef = 0EE7A79420F61EDC00B42E6A /* PacketMacros.h */; }; 0EE7A79820F6296F00B42E6A /* PacketMacros.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EE7A79720F6296F00B42E6A /* PacketMacros.m */; }; @@ -215,7 +215,7 @@ 0EC1BBA420D71190007C4C7B /* DNSResolver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DNSResolver.swift; sourceTree = ""; }; 0EC1BBA720D7D803007C4C7B /* ConnectionStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionStrategy.swift; sourceTree = ""; }; 0ECE3527212EB7770040F253 /* CryptoContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoContainer.swift; sourceTree = ""; }; - 0ED9C8632138139000621BA3 /* CompressionFraming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompressionFraming.swift; sourceTree = ""; }; + 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+CompressionFraming.swift"; sourceTree = ""; }; 0EE7A79420F61EDC00B42E6A /* PacketMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PacketMacros.h; sourceTree = ""; }; 0EE7A79720F6296F00B42E6A /* PacketMacros.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PacketMacros.m; sourceTree = ""; }; 0EE7A79D20F6488400B42E6A /* DataPathEncryption.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataPathEncryption.h; sourceTree = ""; }; @@ -414,7 +414,6 @@ children = ( 0EFEB42E2006D3C800F81029 /* Allocation.h */, 0EFEB4462006D3C800F81029 /* Allocation.m */, - 0ED9C8632138139000621BA3 /* CompressionFraming.swift */, 0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */, 0EFEB44A2006D3C800F81029 /* CoreConfiguration.swift */, 0E07597C20F0060E00F38FD8 /* CryptoAEAD.h */, @@ -446,6 +445,7 @@ 0E0C2123212ED29D008AB282 /* SessionError.swift */, 0EFEB43C2006D3C800F81029 /* SessionProxy.swift */, 0EFEB43A2006D3C800F81029 /* SessionProxy+Authenticator.swift */, + 0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */, 0E0C2124212ED29D008AB282 /* SessionProxy+Configuration.swift */, 0EFEB42A2006D3C800F81029 /* SessionProxy+EncryptionBridge.swift */, 0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */, @@ -722,15 +722,11 @@ buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( "${PODS_PODFILE_DIR_PATH}/Podfile.lock", "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); outputPaths = ( "$(DERIVED_FILE_DIR)/Pods-TunnelKit-TunnelKit-iOS-checkManifestLockResult.txt", ); @@ -744,15 +740,11 @@ buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( "${PODS_PODFILE_DIR_PATH}/Podfile.lock", "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); outputPaths = ( "$(DERIVED_FILE_DIR)/Pods-TunnelKit-TunnelKitHost-checkManifestLockResult.txt", ); @@ -766,15 +758,11 @@ buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( "${PODS_PODFILE_DIR_PATH}/Podfile.lock", "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); outputPaths = ( "$(DERIVED_FILE_DIR)/Pods-TunnelKit-TunnelKit-macOS-checkManifestLockResult.txt", ); @@ -788,16 +776,12 @@ buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( "${SRCROOT}/Pods/Target Support Files/Pods-TunnelKit-TunnelKitHost/Pods-TunnelKit-TunnelKitHost-frameworks.sh", "${PODS_ROOT}/OpenSSL-Apple/frameworks/iPhone/openssl.framework", "${BUILT_PRODUCTS_DIR}/SwiftyBeaver-iOS/SwiftyBeaver.framework", ); name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - ); outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyBeaver.framework", @@ -877,7 +861,7 @@ 0EFEB4792006D3C800F81029 /* TunnelKitProvider+Interaction.swift in Sources */, 0EFEB4702006D3C800F81029 /* Allocation.m in Sources */, 0EFEB4672006D3C800F81029 /* SessionProxy.swift in Sources */, - 0ED9C8642138139000621BA3 /* CompressionFraming.swift in Sources */, + 0ED9C8642138139000621BA3 /* SessionProxy+CompressionFraming.swift in Sources */, 0EFEB4722006D3C800F81029 /* ReplayProtector.m in Sources */, 0EFEB4782006D3C800F81029 /* TunnelKitProvider+Configuration.swift in Sources */, 0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */, @@ -929,7 +913,7 @@ 0EFEB49E2006D7F300F81029 /* Allocation.m in Sources */, 0EFEB4B02007627700F81029 /* Keychain.swift in Sources */, 0EFEB48E2006D7F300F81029 /* SessionProxy+SessionKey.swift in Sources */, - 0ED9C8652138139000621BA3 /* CompressionFraming.swift in Sources */, + 0ED9C8652138139000621BA3 /* SessionProxy+CompressionFraming.swift in Sources */, 0EFEB4AF2007627700F81029 /* InterfaceObserver.swift in Sources */, 0EFEB4A42006D7F300F81029 /* DataPath.m in Sources */, 0EBBF2E62084FE6F00E36B40 /* GenericSocket.swift in Sources */, diff --git a/TunnelKit/Sources/AppExtension/CryptoContainer.swift b/TunnelKit/Sources/AppExtension/CryptoContainer.swift index 14acc14..f94e065 100644 --- a/TunnelKit/Sources/AppExtension/CryptoContainer.swift +++ b/TunnelKit/Sources/AppExtension/CryptoContainer.swift @@ -59,3 +59,17 @@ public struct CryptoContainer: Equatable { return lhs.pem == rhs.pem } } + +/// :nodoc: +extension CryptoContainer: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + let pem = try container.decode(String.self) + self.init(pem: pem) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(pem) + } +} diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift index ecb6e74..5991e5b 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift @@ -321,7 +321,7 @@ extension TunnelKitProvider { } /// Offers a bridge between the abstract `TunnelKitProvider.ConfigurationBuilder` and a concrete `NETunnelProviderProtocol` profile. - public struct Configuration { + public struct Configuration: Codable { struct Keys { static let appGroup = "AppGroup" @@ -566,3 +566,17 @@ extension TunnelKitProvider.Configuration: Equatable { ) } } + +/// :nodoc: +extension TunnelKitProvider.EndpointProtocol: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + let proto = try TunnelKitProvider.EndpointProtocol.deserialized(container.decode(String.self)) + self.init(proto.socketType, proto.port) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(serialized()) + } +} diff --git a/TunnelKit/Sources/Core/CompressionFraming.swift b/TunnelKit/Sources/Core/SessionProxy+CompressionFraming.swift similarity index 94% rename from TunnelKit/Sources/Core/CompressionFraming.swift rename to TunnelKit/Sources/Core/SessionProxy+CompressionFraming.swift index 33ed011..5c6ecbc 100644 --- a/TunnelKit/Sources/Core/CompressionFraming.swift +++ b/TunnelKit/Sources/Core/SessionProxy+CompressionFraming.swift @@ -1,5 +1,5 @@ // -// CompressionFraming.swift +// SessionProxy+CompressionFraming.swift // TunnelKit // // Created by Davide De Rosa on 8/30/18. @@ -29,7 +29,7 @@ import __TunnelKitNative extension SessionProxy { /// Defines the type of compression framing. - public enum CompressionFraming: Int, CustomStringConvertible { + public enum CompressionFraming: Int, Codable, CustomStringConvertible { /// No compression framing. case disabled diff --git a/TunnelKit/Sources/Core/SessionProxy+Configuration.swift b/TunnelKit/Sources/Core/SessionProxy+Configuration.swift index d647a8a..e651aac 100644 --- a/TunnelKit/Sources/Core/SessionProxy+Configuration.swift +++ b/TunnelKit/Sources/Core/SessionProxy+Configuration.swift @@ -40,7 +40,7 @@ import Foundation extension SessionProxy { /// The available encryption algorithms. - public enum Cipher: String { + public enum Cipher: String, Codable { // WARNING: must match OpenSSL algorithm names @@ -63,7 +63,7 @@ extension SessionProxy { } /// The available message digest algorithms. - public enum Digest: String { + public enum Digest: String, Codable { // WARNING: must match OpenSSL algorithm names @@ -143,7 +143,7 @@ extension SessionProxy { } /// The immutable configuration for `SessionProxy`. - public struct Configuration { + public struct Configuration: Codable { /// - Seealso: `SessionProxy.ConfigurationBuilder.username` public let username: String From 802f7dc0f8b8783f71082df520e499086ec21dc8 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 5 Sep 2018 16:17:10 +0200 Subject: [PATCH 2/2] Fix debugLogFormat not copied to builder --- .../Sources/AppExtension/TunnelKitProvider+Configuration.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift index 5991e5b..3475f86 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift @@ -548,6 +548,7 @@ extension TunnelKitProvider.Configuration: Equatable { builder.renegotiatesAfterSeconds = renegotiatesAfterSeconds builder.shouldDebug = shouldDebug builder.debugLogKey = debugLogKey + builder.debugLogFormat = debugLogFormat return builder }