config: Minor cleanup
- Stop implicitly assuming locales in String.format - Cleanup method visibilities - Improve uses of Integer methods - Remove unused getToken method Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
ba862b166b
commit
217ab5e17f
@ -7,6 +7,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -88,17 +89,13 @@ enum Attribute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String composeWith(final int value) {
|
public String composeWith(final int value) {
|
||||||
return String.format("%s = %d%n", token, value);
|
return String.format(Locale.getDefault(), "%s = %d%n", token, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> String composeWith(final List<T> value) {
|
public <T> String composeWith(final List<T> value) {
|
||||||
return String.format("%s = %s%n", token, listToString(value));
|
return String.format("%s = %s%n", token, listToString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String parse(final CharSequence line) {
|
public String parse(final CharSequence line) {
|
||||||
final Matcher matcher = pattern.matcher(line);
|
final Matcher matcher = pattern.matcher(line);
|
||||||
return matcher.matches() ? matcher.group(1) : null;
|
return matcher.matches() ? matcher.group(1) : null;
|
||||||
|
@ -6,10 +6,11 @@ import android.os.Parcelable;
|
|||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class IPCidr implements Parcelable {
|
public class IPCidr implements Parcelable {
|
||||||
InetAddress address;
|
private InetAddress address;
|
||||||
int cidr;
|
private int cidr;
|
||||||
|
|
||||||
|
|
||||||
public static final Parcelable.Creator<IPCidr> CREATOR = new Parcelable.Creator<IPCidr>() {
|
public static final Parcelable.Creator<IPCidr> CREATOR = new Parcelable.Creator<IPCidr>() {
|
||||||
@ -24,7 +25,7 @@ public class IPCidr implements Parcelable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public IPCidr(String in) {
|
IPCidr(String in) {
|
||||||
parse(in);
|
parse(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public class IPCidr implements Parcelable {
|
|||||||
try {
|
try {
|
||||||
cidr = Integer.parseInt(in.substring(slash + 1), 10);
|
cidr = Integer.parseInt(in.substring(slash + 1), 10);
|
||||||
in = in.substring(0, slash);
|
in = in.substring(0, slash);
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
address = Attribute.parseIPString(in);
|
address = Attribute.parseIPString(in);
|
||||||
@ -55,7 +56,7 @@ public class IPCidr implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s/%d", address.getHostAddress(), cidr);
|
return String.format(Locale.getDefault(), "%s/%d", address.getHostAddress(), cidr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +72,7 @@ public class IPCidr implements Parcelable {
|
|||||||
private IPCidr(final Parcel in) {
|
private IPCidr(final Parcel in) {
|
||||||
try {
|
try {
|
||||||
parse(in.readString());
|
parse(in.readString());
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public class Interface implements Parcelable {
|
|||||||
for (int i = 0; i < dnsItems; ++i) {
|
for (int i = 0; i < dnsItems; ++i) {
|
||||||
try {
|
try {
|
||||||
dnsList.add(InetAddress.getByAddress(in.createByteArray()));
|
dnsList.add(InetAddress.getByAddress(in.createByteArray()));
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listenPort = in.readInt();
|
listenPort = in.readInt();
|
||||||
@ -198,7 +198,7 @@ public class Interface implements Parcelable {
|
|||||||
private String getListenPortString() {
|
private String getListenPortString() {
|
||||||
if (listenPort == 0)
|
if (listenPort == 0)
|
||||||
return null;
|
return null;
|
||||||
return new Integer(listenPort).toString();
|
return Integer.valueOf(listenPort).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMtu() {
|
public int getMtu() {
|
||||||
@ -208,7 +208,7 @@ public class Interface implements Parcelable {
|
|||||||
private String getMtuString() {
|
private String getMtuString() {
|
||||||
if (mtu == 0)
|
if (mtu == 0)
|
||||||
return null;
|
return null;
|
||||||
return new Integer(mtu).toString();
|
return Integer.toString(mtu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrivateKey() {
|
public String getPrivateKey() {
|
||||||
|
@ -15,6 +15,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the configuration for a WireGuard peer (a [Peer] block).
|
* Represents the configuration for a WireGuard peer (a [Peer] block).
|
||||||
@ -167,7 +168,7 @@ public class Peer implements Parcelable {
|
|||||||
private String getEndpointString() {
|
private String getEndpointString() {
|
||||||
if (endpoint == null)
|
if (endpoint == null)
|
||||||
return null;
|
return null;
|
||||||
return String.format("%s:%d", endpoint.getHostString(), endpoint.getPort());
|
return String.format(Locale.getDefault(), "%s:%d", endpoint.getHostString(), endpoint.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResolvedEndpointString() throws UnknownHostException {
|
public String getResolvedEndpointString() throws UnknownHostException {
|
||||||
@ -178,8 +179,14 @@ public class Peer implements Parcelable {
|
|||||||
if (endpoint.isUnresolved())
|
if (endpoint.isUnresolved())
|
||||||
throw new UnknownHostException(endpoint.getHostString());
|
throw new UnknownHostException(endpoint.getHostString());
|
||||||
if (endpoint.getAddress() instanceof Inet6Address)
|
if (endpoint.getAddress() instanceof Inet6Address)
|
||||||
return String.format("[%s]:%d", endpoint.getAddress().getHostAddress(), endpoint.getPort());
|
return String.format(Locale.getDefault(),
|
||||||
return String.format("%s:%d", endpoint.getAddress().getHostAddress(), endpoint.getPort());
|
"[%s]:%d",
|
||||||
|
endpoint.getAddress().getHostAddress(),
|
||||||
|
endpoint.getPort());
|
||||||
|
return String.format(Locale.getDefault(),
|
||||||
|
"%s:%d",
|
||||||
|
endpoint.getAddress().getHostAddress(),
|
||||||
|
endpoint.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPersistentKeepalive() {
|
public int getPersistentKeepalive() {
|
||||||
@ -189,7 +196,7 @@ public class Peer implements Parcelable {
|
|||||||
private String getPersistentKeepaliveString() {
|
private String getPersistentKeepaliveString() {
|
||||||
if (persistentKeepalive == 0)
|
if (persistentKeepalive == 0)
|
||||||
return null;
|
return null;
|
||||||
return new Integer(persistentKeepalive).toString();
|
return Integer.valueOf(persistentKeepalive).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPreSharedKey() {
|
public String getPreSharedKey() {
|
||||||
|
Loading…
Reference in New Issue
Block a user