aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-21 15:16:09 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-21 16:32:08 -0600
commit1fecd8eb6c5c2327d4bfd5044876be12876fc7e5 (patch)
tree45c7f4c552eb01bd15c54e58615c9122acc99e83 /WireGuard/Shared/Model
parentDo not require NetworkExtension to know its own name (diff)
downloadwireguard-apple-1fecd8eb6c5c2327d4bfd5044876be12876fc7e5.tar.xz
wireguard-apple-1fecd8eb6c5c2327d4bfd5044876be12876fc7e5.zip
providerConfiguration is now a WgQuickConfig
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/DNSServer.swift24
-rw-r--r--WireGuard/Shared/Model/Endpoint.swift20
-rw-r--r--WireGuard/Shared/Model/IPAddressRange.swift19
-rw-r--r--WireGuard/Shared/Model/InterfaceConfiguration.swift42
-rw-r--r--WireGuard/Shared/Model/PeerConfiguration.swift39
-rw-r--r--WireGuard/Shared/Model/TunnelConfiguration.swift20
6 files changed, 2 insertions, 162 deletions
diff --git a/WireGuard/Shared/Model/DNSServer.swift b/WireGuard/Shared/Model/DNSServer.swift
index 8703fbba..9078b598 100644
--- a/WireGuard/Shared/Model/DNSServer.swift
+++ b/WireGuard/Shared/Model/DNSServer.swift
@@ -12,30 +12,6 @@ struct DNSServer {
}
}
-extension DNSServer: Codable {
- public func encode(to encoder: Encoder) throws {
- var container = encoder.singleValueContainer()
- try container.encode(stringRepresentation)
- }
-
- public init(from decoder: Decoder) throws {
- let values = try decoder.singleValueContainer()
- let addressString = try values.decode(String.self)
-
- if let address = IPv4Address(addressString) {
- self.address = address
- } else if let address = IPv6Address(addressString) {
- self.address = address
- } else {
- throw DecodingError.invalidData
- }
- }
-
- enum DecodingError: Error {
- case invalidData
- }
-}
-
extension DNSServer {
var stringRepresentation: String {
return "\(address)"
diff --git a/WireGuard/Shared/Model/Endpoint.swift b/WireGuard/Shared/Model/Endpoint.swift
index 891c5642..b29a5a8d 100644
--- a/WireGuard/Shared/Model/Endpoint.swift
+++ b/WireGuard/Shared/Model/Endpoint.swift
@@ -14,26 +14,6 @@ struct Endpoint {
}
}
-extension Endpoint: Codable {
- init(from decoder: Decoder) throws {
- let container = try decoder.singleValueContainer()
- let endpointString = try container.decode(String.self)
- guard let endpoint = Endpoint(from: endpointString) else {
- throw DecodingError.invalidData
- }
- self = endpoint
- }
-
- func encode(to encoder: Encoder) throws {
- var container = encoder.singleValueContainer()
- try container.encode(stringRepresentation)
- }
-
- enum DecodingError: Error {
- case invalidData
- }
-}
-
extension Endpoint {
var stringRepresentation: String {
switch host {
diff --git a/WireGuard/Shared/Model/IPAddressRange.swift b/WireGuard/Shared/Model/IPAddressRange.swift
index da4cbd5e..28f3d005 100644
--- a/WireGuard/Shared/Model/IPAddressRange.swift
+++ b/WireGuard/Shared/Model/IPAddressRange.swift
@@ -52,22 +52,3 @@ extension IPAddressRange {
return (address, networkPrefixLength)
}
}
-
-extension IPAddressRange: Codable {
- public func encode(to encoder: Encoder) throws {
- var container = encoder.singleValueContainer()
- try container.encode(stringRepresentation)
- }
-
- public init(from decoder: Decoder) throws {
- let values = try decoder.singleValueContainer()
- let addressString = try values.decode(String.self)
- guard let parsed = IPAddressRange.parseAddressString(addressString) else { throw DecodingError.invalidData }
- address = parsed.0
- networkPrefixLength = parsed.1
- }
-
- enum DecodingError: Error {
- case invalidData
- }
-}
diff --git a/WireGuard/Shared/Model/InterfaceConfiguration.swift b/WireGuard/Shared/Model/InterfaceConfiguration.swift
index dfcb1fc7..9094d149 100644
--- a/WireGuard/Shared/Model/InterfaceConfiguration.swift
+++ b/WireGuard/Shared/Model/InterfaceConfiguration.swift
@@ -4,56 +4,18 @@
import Foundation
struct InterfaceConfiguration {
- var name: String
+ var name: String?
var privateKey: Data
var addresses = [IPAddressRange]()
var listenPort: UInt16?
var mtu: UInt16?
var dns = [DNSServer]()
- init(name: String, privateKey: Data) {
+ init(name: String?, privateKey: Data) {
self.name = name
self.privateKey = privateKey
- if name.isEmpty {
- fatalError("Empty name")
- }
if privateKey.count != TunnelConfiguration.keyLength {
fatalError("Invalid private key")
}
}
}
-
-extension InterfaceConfiguration: Codable {
- enum CodingKeys: String, CodingKey {
- case name = "Name"
- case privateKey = "PrivateKey"
- case addresses = "Address"
- case listenPort = "ListenPort"
- case mtu = "MTU"
- case dns = "DNS"
- }
-
- init(from decoder: Decoder) throws {
- let values = try decoder.container(keyedBy: CodingKeys.self)
- name = try values.decode(String.self, forKey: .name)
- privateKey = try Data(base64Encoded: values.decode(String.self, forKey: .privateKey))!
- addresses = try values.decode([IPAddressRange].self, forKey: .addresses)
- listenPort = try? values.decode(UInt16.self, forKey: .listenPort)
- mtu = try? values.decode(UInt16.self, forKey: .mtu)
- dns = try values.decode([DNSServer].self, forKey: .dns)
- }
-
- func encode(to encoder: Encoder) throws {
- var container = encoder.container(keyedBy: CodingKeys.self)
- try container.encode(name, forKey: .name)
- try container.encode(privateKey.base64EncodedString(), forKey: .privateKey)
- try container.encode(addresses, forKey: .addresses)
- if let listenPort = listenPort {
- try container.encode(listenPort, forKey: .listenPort)
- }
- if let mtu = mtu {
- try container.encode(mtu, forKey: .mtu)
- }
- try container.encode(dns, forKey: .dns)
- }
-}
diff --git a/WireGuard/Shared/Model/PeerConfiguration.swift b/WireGuard/Shared/Model/PeerConfiguration.swift
index 0fad842a..a113821d 100644
--- a/WireGuard/Shared/Model/PeerConfiguration.swift
+++ b/WireGuard/Shared/Model/PeerConfiguration.swift
@@ -25,42 +25,3 @@ struct PeerConfiguration {
}
}
}
-
-extension PeerConfiguration: Codable {
- enum CodingKeys: String, CodingKey {
- case publicKey = "PublicKey"
- case preSharedKey = "PreSharedKey"
- case allowedIPs = "AllowedIPs"
- case endpoint = "Endpoint"
- case persistentKeepAlive = "PersistentKeepAlive"
- }
-
- init(from decoder: Decoder) throws {
- let values = try decoder.container(keyedBy: CodingKeys.self)
- publicKey = try Data(base64Encoded: values.decode(String.self, forKey: .publicKey))!
- if let base64PreSharedKey = try? values.decode(Data.self, forKey: .preSharedKey) {
- preSharedKey = Data(base64Encoded: base64PreSharedKey)
- } else {
- preSharedKey = nil
- }
- allowedIPs = try values.decode([IPAddressRange].self, forKey: .allowedIPs)
- endpoint = try? values.decode(Endpoint.self, forKey: .endpoint)
- persistentKeepAlive = try? values.decode(UInt16.self, forKey: .persistentKeepAlive)
- }
-
- func encode(to encoder: Encoder) throws {
- var container = encoder.container(keyedBy: CodingKeys.self)
- try container.encode(publicKey.base64EncodedString(), forKey: .publicKey)
- if let preSharedKey = preSharedKey {
- try container.encode(preSharedKey.base64EncodedString(), forKey: .preSharedKey)
- }
-
- try container.encode(allowedIPs, forKey: .allowedIPs)
- if let endpoint = endpoint {
- try container.encode(endpoint, forKey: .endpoint)
- }
- if let persistentKeepAlive = persistentKeepAlive {
- try container.encode(persistentKeepAlive, forKey: .persistentKeepAlive)
- }
- }
-}
diff --git a/WireGuard/Shared/Model/TunnelConfiguration.swift b/WireGuard/Shared/Model/TunnelConfiguration.swift
index 87812cde..2e394eed 100644
--- a/WireGuard/Shared/Model/TunnelConfiguration.swift
+++ b/WireGuard/Shared/Model/TunnelConfiguration.swift
@@ -20,23 +20,3 @@ final class TunnelConfiguration {
}
}
}
-
-extension TunnelConfiguration: Codable {
- enum CodingKeys: String, CodingKey {
- case interface = "Interface"
- case peers = "Peer"
- }
-
- convenience init(from decoder: Decoder) throws {
- let values = try decoder.container(keyedBy: CodingKeys.self)
- let interface = try values.decode(InterfaceConfiguration.self, forKey: .interface)
- let peers = try values.decode([PeerConfiguration].self, forKey: .peers)
- self.init(interface: interface, peers: peers)
- }
-
- func encode(to encoder: Encoder) throws {
- var container = encoder.container(keyedBy: CodingKeys.self)
- try container.encode(interface, forKey: .interface)
- try container.encode(peers, forKey: .peers)
- }
-}