aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-10 19:01:34 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-10 19:01:34 +0530
commit1502bd42d3f4b6c09f1f9025b31f9cb12b2d5b3b (patch)
tree1721abac38ef78ae98b136356fee3016005cfc24 /WireGuard/Shared/Model
parentModel: Ensure that a TunnelConfiguration always has a valid array of peers (diff)
downloadwireguard-apple-1502bd42d3f4b6c09f1f9025b31f9cb12b2d5b3b.tar.xz
wireguard-apple-1502bd42d3f4b6c09f1f9025b31f9cb12b2d5b3b.zip
Model: TunnelConfiguration: Add explicit conformance to Decodable
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/Configuration.swift16
1 files changed, 15 insertions, 1 deletions
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift
index 3e661e61..45c29c11 100644
--- a/WireGuard/Shared/Model/Configuration.swift
+++ b/WireGuard/Shared/Model/Configuration.swift
@@ -4,7 +4,7 @@
import Foundation
@available(OSX 10.14, iOS 12.0, *)
-class TunnelConfiguration: Codable {
+final class TunnelConfiguration {
var interface: InterfaceConfiguration
let peers: [PeerConfiguration]
init(interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
@@ -55,3 +55,17 @@ struct PeerConfiguration: Codable {
if (publicKey.count != 32) { fatalError("Invalid public key") }
}
}
+
+extension TunnelConfiguration: Encodable { }
+extension TunnelConfiguration: Decodable {
+ enum CodingKeys: CodingKey {
+ case interface
+ case peers
+ }
+ 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)
+ }
+}