summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-08-19 13:25:48 +0200
committerAndrej Mihajlov <and@mullvad.net>2020-08-19 13:52:58 +0200
commita3f835548e14a0e25b8429cfbe797bcf748bfe1f (patch)
treecd8d27493cf5d0d6fd243838b71bbbf194ddb023
parentc154ceeffa26a7694ed802f4e844cb9c00909a02 (diff)
downloadmullvadvpn-a3f835548e14a0e25b8429cfbe797bcf748bfe1f.tar.xz
mullvadvpn-a3f835548e14a0e25b8429cfbe797bcf748bfe1f.zip
Wrap IPC response in container type to fix JSON encoding issue of primitive types without top level container
-rw-r--r--ios/MullvadVPN/PacketTunnelIpc.swift17
-rw-r--r--ios/MullvadVPN/SimulatorTunnelProviderHost.swift2
-rw-r--r--ios/PacketTunnel/PacketTunnelProvider.swift2
3 files changed, 13 insertions, 8 deletions
diff --git a/ios/MullvadVPN/PacketTunnelIpc.swift b/ios/MullvadVPN/PacketTunnelIpc.swift
index c4b4c6623e..4549aad813 100644
--- a/ios/MullvadVPN/PacketTunnelIpc.swift
+++ b/ios/MullvadVPN/PacketTunnelIpc.swift
@@ -42,6 +42,11 @@ enum PacketTunnelRequest: Int, Codable, RawRepresentable {
}
}
+/// A container type around Packet Tunnel response
+struct PacketTunnelResponse<T: Codable>: Codable {
+ var value: T
+}
+
/// A struct that holds the basic information regarding the tunnel connection
struct TunnelConnectionInfo: Codable, Equatable {
let ipv4Relay: IPv4Endpoint
@@ -96,10 +101,10 @@ extension PacketTunnelIpcHandler {
}
}
- static func encodeResponse<T>(response: T) -> Result<Data, Error> where T: Encodable {
+ static func encodeResponse<T>(response: T) -> Result<Data, Error> where T: Codable {
do {
let encoder = JSONEncoder()
- let value = try encoder.encode(response)
+ let value = try encoder.encode(PacketTunnelResponse(value: response))
return .success(value)
} catch {
@@ -163,12 +168,12 @@ class PacketTunnelIpc {
}
}
- private class func decodeResponse<T>(data: Data) -> Result<T, Error> where T: Decodable {
+ private class func decodeResponse<T>(data: Data) -> Result<T, Error> where T: Codable {
do {
let decoder = JSONDecoder()
- let value = try decoder.decode(T.self, from: data)
+ let response = try decoder.decode(PacketTunnelResponse<T>.self, from: data)
- return .success(value)
+ return .success(response.value)
} catch {
return .failure(.decoding(error))
}
@@ -183,7 +188,7 @@ class PacketTunnelIpc {
}
private func send<T>(message: PacketTunnelRequest, completionHandler: @escaping (Result<T, Error>) -> Void)
- where T: Decodable
+ where T: Codable
{
sendWithoutDecoding(message: message) { (result) in
let result = result.flatMap { (data) -> Result<T, Error> in
diff --git a/ios/MullvadVPN/SimulatorTunnelProviderHost.swift b/ios/MullvadVPN/SimulatorTunnelProviderHost.swift
index 1e418c2d77..0f31e5d882 100644
--- a/ios/MullvadVPN/SimulatorTunnelProviderHost.swift
+++ b/ios/MullvadVPN/SimulatorTunnelProviderHost.swift
@@ -65,7 +65,7 @@ class SimulatorTunnelProviderHost: SimulatorTunnelProviderDelegate {
}
}
- private func replyAppMessage<T: Encodable>(_ response: T, completionHandler: ((Data?) -> Void)?)
+ private func replyAppMessage<T: Codable>(_ response: T, completionHandler: ((Data?) -> Void)?)
{
switch PacketTunnelIpcHandler.encodeResponse(response: response) {
case .success(let data):
diff --git a/ios/PacketTunnel/PacketTunnelProvider.swift b/ios/PacketTunnel/PacketTunnelProvider.swift
index e5249cfb20..eb07274955 100644
--- a/ios/PacketTunnel/PacketTunnelProvider.swift
+++ b/ios/PacketTunnel/PacketTunnelProvider.swift
@@ -337,7 +337,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
// MARK: - Private
- private func replyAppMessage<T: Encodable>(
+ private func replyAppMessage<T: Codable>(
_ result: Result<T, PacketTunnelProviderError>,
completionHandler: ((Data?) -> Void)?) {
let result = result.flatMap { (response) -> Result<Data, PacketTunnelProviderError> in