diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/data')
3 files changed, 23 insertions, 23 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt b/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt index c6a9b1f..2d0577f 100644 --- a/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt +++ b/app/src/main/java/org/pacien/tincapp/data/CidrAddress.kt | |||
@@ -25,7 +25,7 @@ import org.apache.commons.configuration2.ex.ConversionException | |||
25 | */ | 25 | */ |
26 | data class CidrAddress(val address: String, val prefix: Int) { | 26 | data class CidrAddress(val address: String, val prefix: Int) { |
27 | companion object { | 27 | companion object { |
28 | private val SEPARATOR = "/" | 28 | private const val SEPARATOR = "/" |
29 | 29 | ||
30 | fun fromSlashSeparated(s: String) = try { | 30 | fun fromSlashSeparated(s: String) = try { |
31 | CidrAddress(s.substringBefore(SEPARATOR), Integer.parseInt(s.substringAfter(SEPARATOR))) | 31 | CidrAddress(s.substringBefore(SEPARATOR), Integer.parseInt(s.substringAfter(SEPARATOR))) |
diff --git a/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt index 0eee2eb..c9339e0 100644 --- a/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/data/TincConfiguration.kt | |||
@@ -30,11 +30,11 @@ data class TincConfiguration(val ed25519PrivateKeyFile: File? = null, | |||
30 | val privateKeyFile: File? = null) { | 30 | val privateKeyFile: File? = null) { |
31 | companion object { | 31 | companion object { |
32 | 32 | ||
33 | private val KEY_ED25519_PRIVATE_KEY_FILE = "Ed25519PrivateKeyFile" | 33 | private const val KEY_ED25519_PRIVATE_KEY_FILE = "Ed25519PrivateKeyFile" |
34 | private val KEY_PRIVATE_KEY_FILE = "PrivateKeyFile" | 34 | private const val KEY_PRIVATE_KEY_FILE = "PrivateKeyFile" |
35 | 35 | ||
36 | fun fromTincConfiguration(f: File) = fromTincConfiguration(Configurations().properties(f)) | 36 | fun fromTincConfiguration(f: File) = fromTincConfiguration(Configurations().properties(f)) |
37 | fun fromTincConfiguration(c: Configuration) = TincConfiguration( | 37 | private fun fromTincConfiguration(c: Configuration) = TincConfiguration( |
38 | c.getFile(KEY_ED25519_PRIVATE_KEY_FILE), | 38 | c.getFile(KEY_ED25519_PRIVATE_KEY_FILE), |
39 | c.getFile(KEY_PRIVATE_KEY_FILE)) | 39 | c.getFile(KEY_PRIVATE_KEY_FILE)) |
40 | } | 40 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt index d903769..daf04c8 100644 --- a/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt +++ b/app/src/main/java/org/pacien/tincapp/data/VpnInterfaceConfiguration.kt | |||
@@ -44,22 +44,22 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
44 | val blocking: Boolean = false, | 44 | val blocking: Boolean = false, |
45 | val mtu: Int? = null) { | 45 | val mtu: Int? = null) { |
46 | companion object { | 46 | companion object { |
47 | private val KEY_ADDRESSES = "Address" | 47 | private const val KEY_ADDRESSES = "Address" |
48 | private val KEY_ROUTES = "Route" | 48 | private const val KEY_ROUTES = "Route" |
49 | private val KEY_DNS_SERVERS = "DNSServer" | 49 | private const val KEY_DNS_SERVERS = "DNSServer" |
50 | private val KEY_SEARCH_DOMAINS = "SearchDomain" | 50 | private const val KEY_SEARCH_DOMAINS = "SearchDomain" |
51 | private val KEY_ALLOWED_APPLICATIONS = "AllowApplication" | 51 | private const val KEY_ALLOWED_APPLICATIONS = "AllowApplication" |
52 | private val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" | 52 | private const val KEY_DISALLOWED_APPLICATIONS = "DisallowApplication" |
53 | private val KEY_ALLOWED_FAMILIES = "AllowFamily" | 53 | private const val KEY_ALLOWED_FAMILIES = "AllowFamily" |
54 | private val KEY_ALLOW_BYPASS = "AllowBypass" | 54 | private const val KEY_ALLOW_BYPASS = "AllowBypass" |
55 | private val KEY_BLOCKING = "Blocking" | 55 | private const val KEY_BLOCKING = "Blocking" |
56 | private val KEY_MTU = "MTU" | 56 | private const val KEY_MTU = "MTU" |
57 | 57 | ||
58 | private val INVITATION_KEY_ADDRESSES = "Ifconfig" | 58 | private const val INVITATION_KEY_ADDRESSES = "Ifconfig" |
59 | private val INVITATION_KEY_ROUTES = "Route" | 59 | private const val INVITATION_KEY_ROUTES = "Route" |
60 | 60 | ||
61 | fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f)) | 61 | fun fromIfaceConfiguration(f: File) = fromIfaceConfiguration(Configurations().properties(f)) |
62 | fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration( | 62 | private fun fromIfaceConfiguration(c: Configuration) = VpnInterfaceConfiguration( |
63 | c.getCidrList(KEY_ADDRESSES), | 63 | c.getCidrList(KEY_ADDRESSES), |
64 | c.getCidrList(KEY_ROUTES), | 64 | c.getCidrList(KEY_ROUTES), |
65 | c.getStringList(KEY_DNS_SERVERS), | 65 | c.getStringList(KEY_DNS_SERVERS), |
@@ -72,7 +72,7 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
72 | c.getInteger(KEY_MTU, null)) | 72 | c.getInteger(KEY_MTU, null)) |
73 | 73 | ||
74 | fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f)) | 74 | fun fromInvitation(f: File) = fromInvitation(Configurations().properties(f)) |
75 | fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration( | 75 | private fun fromInvitation(c: Configuration) = VpnInterfaceConfiguration( |
76 | c.getStringList(INVITATION_KEY_ADDRESSES) | 76 | c.getStringList(INVITATION_KEY_ADDRESSES) |
77 | .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) } | 77 | .map { applyIgnoringException(CidrAddress.Companion::fromSlashSeparated, it) } |
78 | .filterNotNull(), | 78 | .filterNotNull(), |
@@ -83,10 +83,10 @@ data class VpnInterfaceConfiguration(val addresses: List<CidrAddress> = emptyLis | |||
83 | 83 | ||
84 | fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java) | 84 | fun write(f: File) = FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration::class.java) |
85 | .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder -> | 85 | .configure(Parameters().properties().setFile(f.apply { createNewFile() })).let { builder -> |
86 | builder.configuration.let { cfg -> | 86 | builder.configuration.let { cfg -> |
87 | addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) } | 87 | addresses.forEach { cfg.addProperty(KEY_ADDRESSES, it.toSlashSeparated()) } |
88 | routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) } | 88 | routes.forEach { cfg.addProperty(KEY_ROUTES, it.toSlashSeparated()) } |
89 | } | ||
90 | builder.save() | ||
89 | } | 91 | } |
90 | builder.save() | ||
91 | } | ||
92 | } | 92 | } |