Export: fix up export format

This commit is contained in:
Jason A. Donenfeld 2018-11-01 17:31:50 +01:00
parent 479f04a579
commit ae992c3deb
1 changed files with 11 additions and 13 deletions

View File

@ -7,40 +7,38 @@ class WgQuickConfigFileWriter {
static func writeConfigFile(from tc: TunnelConfiguration) -> Data? {
let interface = tc.interface
var output = "[Interface]\n"
output.append("PrivateKey=\(interface.privateKey.base64EncodedString())\n")
output.append("PrivateKey = \(interface.privateKey.base64EncodedString())\n")
if let listenPort = interface.listenPort {
output.append("ListenPort=\(listenPort)\n")
output.append("ListenPort = \(listenPort)\n")
}
if (!interface.addresses.isEmpty) {
let addressString = interface.addresses.map { $0.stringRepresentation() }.joined(separator: ", ")
output.append("Address=\(addressString)\n")
output.append("Address = \(addressString)\n")
}
if (!interface.dns.isEmpty) {
let dnsString = interface.dns.map { $0.stringRepresentation() }.joined(separator: ", ")
output.append("DNS=\(dnsString)\n")
output.append("DNS = \(dnsString)\n")
}
if let mtu = interface.mtu {
output.append("MTU=\(mtu)\n")
output.append("MTU = \(mtu)\n")
}
output.append("\n")
for peer in tc.peers {
output.append("[Peer]\n")
output.append("PublicKey=\(peer.publicKey.base64EncodedString())\n")
output.append("\n[Peer]\n")
output.append("PublicKey = \(peer.publicKey.base64EncodedString())\n")
if let preSharedKey = peer.preSharedKey {
output.append("PresharedKey=\(preSharedKey.base64EncodedString())\n")
output.append("PresharedKey = \(preSharedKey.base64EncodedString())\n")
}
if (!peer.allowedIPs.isEmpty) {
let allowedIPsString = peer.allowedIPs.map { $0.stringRepresentation() }.joined(separator: ", ")
output.append("AllowedIPs=\(allowedIPsString)\n")
output.append("AllowedIPs = \(allowedIPsString)\n")
}
if let endpoint = peer.endpoint {
output.append("Endpoint=\(endpoint.stringRepresentation())\n")
output.append("Endpoint = \(endpoint.stringRepresentation())\n")
}
if let persistentKeepAlive = peer.persistentKeepAlive {
output.append("PersistentKeepalive=\(persistentKeepAlive)\n")
output.append("PersistentKeepalive = \(persistentKeepAlive)\n")
}
output.append("\n")
}
return output.data(using: .utf8)