diff --git a/Sources/OpenVPNAdapter/OpenVPNNetworkSettingsBuilder.m b/Sources/OpenVPNAdapter/OpenVPNNetworkSettingsBuilder.m index c0e8424..b305152 100644 --- a/Sources/OpenVPNAdapter/OpenVPNNetworkSettingsBuilder.m +++ b/Sources/OpenVPNAdapter/OpenVPNNetworkSettingsBuilder.m @@ -9,6 +9,9 @@ #import +#import "NSArray+Empty.h" +#import "NSSet+Empty.h" + @interface OpenVPNNetworkSettingsBuilder () // TODO: Use NSHashTable for routes to avoid duplicates @@ -35,11 +38,13 @@ #pragma mark - NEPacketTunnelNetworkSettings Generation - (NEPacketTunnelNetworkSettings *)networkSettings { - if (!self.remoteAddress.length) { return nil; } + NSAssert(self.remoteAddress != nil && self.remoteAddress.length > 0, @"Remote address is nil or empty."); NEPacketTunnelNetworkSettings *networkSettings = [[NEPacketTunnelNetworkSettings alloc] initWithTunnelRemoteAddress:self.remoteAddress]; - if (self.ipv4LocalAddresses.count && (self.ipv4LocalAddresses.count == self.ipv4SubnetMasks.count)) { + if (self.ipv4LocalAddresses.isNotEmpty) { + NSAssert(self.ipv4LocalAddresses.count == self.ipv4SubnetMasks.count, @"Number of IPv4 addresses is not equal to number of IPv4 subnet masks."); + NEIPv4Settings *ipv4Settings = [[NEIPv4Settings alloc] initWithAddresses:self.ipv4LocalAddresses subnetMasks:self.ipv4SubnetMasks]; @@ -49,7 +54,9 @@ networkSettings.IPv4Settings = ipv4Settings; } - if (self.ipv6LocalAddresses.count && (self.ipv6LocalAddresses.count == self.ipv6NetworkPrefixLengths.count)) { + if (self.ipv6LocalAddresses.isNotEmpty) { + NSAssert(self.ipv6LocalAddresses.count == self.ipv6NetworkPrefixLengths.count, @"Number of IPv6 addresses is not equal to number of IPv6 prefixes."); + NEIPv6Settings *ipv6Settings = [[NEIPv6Settings alloc] initWithAddresses:self.ipv6LocalAddresses networkPrefixLengths:self.ipv6NetworkPrefixLengths]; @@ -59,7 +66,7 @@ networkSettings.IPv6Settings = ipv6Settings; } - if (self.dnsServers.count) { + if (self.dnsServers.isNotEmpty) { NEDNSSettings *dnsSettings = [[NEDNSSettings alloc] initWithServers:self.dnsServers.allObjects]; dnsSettings.searchDomains = self.searchDomains.allObjects; networkSettings.DNSSettings = dnsSettings;