aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model/IPAddressRange.swift
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/Shared/Model/IPAddressRange.swift')
-rw-r--r--WireGuard/Shared/Model/IPAddressRange.swift10
1 files changed, 5 insertions, 5 deletions
diff --git a/WireGuard/Shared/Model/IPAddressRange.swift b/WireGuard/Shared/Model/IPAddressRange.swift
index 28f3d005..7d3e5eca 100644
--- a/WireGuard/Shared/Model/IPAddressRange.swift
+++ b/WireGuard/Shared/Model/IPAddressRange.swift
@@ -7,7 +7,7 @@ import Network
struct IPAddressRange {
let address: IPAddress
var networkPrefixLength: UInt8
-
+
init(address: IPAddress, networkPrefixLength: UInt8) {
self.address = address
self.networkPrefixLength = networkPrefixLength
@@ -18,13 +18,13 @@ extension IPAddressRange {
var stringRepresentation: String {
return "\(address)/\(networkPrefixLength)"
}
-
+
init?(from string: String) {
guard let parsed = IPAddressRange.parseAddressString(string) else { return nil }
address = parsed.0
networkPrefixLength = parsed.1
}
-
+
private static func parseAddressString(_ string: String) -> (IPAddress, UInt8)? {
let endOfIPAddress = string.lastIndex(of: "/") ?? string.endIndex
let addressString = String(string[string.startIndex ..< endOfIPAddress])
@@ -36,7 +36,7 @@ extension IPAddressRange {
} else {
return nil
}
-
+
let maxNetworkPrefixLength: UInt8 = address is IPv4Address ? 32 : 128
var networkPrefixLength: UInt8
if endOfIPAddress < string.endIndex { // "/" was located
@@ -48,7 +48,7 @@ extension IPAddressRange {
} else {
networkPrefixLength = maxNetworkPrefixLength
}
-
+
return (address, networkPrefixLength)
}
}