global: Add nullity annotations
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
This commit is contained in:
committed by
Jason A. Donenfeld
parent
fbaa4d9ab1
commit
67ea8b2936
@@ -6,6 +6,7 @@
|
||||
|
||||
package com.wireguard.config;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -59,13 +60,13 @@ public enum Attribute {
|
||||
return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0].toLowerCase());
|
||||
}
|
||||
|
||||
public static String[] stringToList(final String string) {
|
||||
public static String[] stringToList(@Nullable final String string) {
|
||||
if (TextUtils.isEmpty(string))
|
||||
return EMPTY_LIST;
|
||||
return LIST_SEPARATOR_PATTERN.split(string.trim());
|
||||
}
|
||||
|
||||
public String composeWith(final Object value) {
|
||||
public String composeWith(@Nullable final Object value) {
|
||||
return String.format("%s = %s%n", token, value);
|
||||
}
|
||||
|
||||
@@ -77,11 +78,13 @@ public enum Attribute {
|
||||
return String.format("%s = %s%n", token, iterableToString(value));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String parse(final CharSequence line) {
|
||||
final Matcher matcher = pattern.matcher(line);
|
||||
return matcher.matches() ? matcher.group(1) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String[] parseList(final CharSequence line) {
|
||||
final Matcher matcher = pattern.matcher(line);
|
||||
return matcher.matches() ? stringToList(matcher.group(1)) : null;
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.databinding.ObservableArrayList;
|
||||
import android.databinding.ObservableList;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.android.databinding.library.baseAdapters.BR;
|
||||
|
||||
@@ -96,13 +97,19 @@ public class Config {
|
||||
return new Observable[size];
|
||||
}
|
||||
};
|
||||
private String name;
|
||||
private Interface.Observable observableInterface;
|
||||
private ObservableList<Peer.Observable> observablePeers;
|
||||
@Nullable private String name;
|
||||
private final Interface.Observable observableInterface;
|
||||
private final ObservableList<Peer.Observable> observablePeers;
|
||||
|
||||
public Observable(final Config parent, final String name) {
|
||||
public Observable(@Nullable final Config parent, @Nullable final String name) {
|
||||
this.name = name;
|
||||
loadData(parent);
|
||||
|
||||
observableInterface = new Interface.Observable(parent == null ? null : parent.interfaceSection);
|
||||
observablePeers = new ObservableArrayList<>();
|
||||
if (parent != null) {
|
||||
for (final Peer peer : parent.getPeers())
|
||||
observablePeers.add(new Peer.Observable(peer));
|
||||
}
|
||||
}
|
||||
|
||||
private Observable(final Parcel in) {
|
||||
@@ -144,15 +151,6 @@ public class Config {
|
||||
return observablePeers;
|
||||
}
|
||||
|
||||
protected void loadData(final Config parent) {
|
||||
observableInterface = new Interface.Observable(parent == null ? null : parent.interfaceSection);
|
||||
observablePeers = new ObservableArrayList<>();
|
||||
if (parent != null) {
|
||||
for (final Peer peer : parent.getPeers())
|
||||
observablePeers.add(new Peer.Observable(peer));
|
||||
}
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
notifyPropertyChanged(BR.name);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
package com.wireguard.config;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -29,7 +28,6 @@ public final class InetAddresses {
|
||||
// Prevent instantiation.
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static InetAddress parse(@Nullable final String address) {
|
||||
if (address == null || address.isEmpty())
|
||||
throw new IllegalArgumentException("Empty address");
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
package com.wireguard.config;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Objects;
|
||||
@@ -16,7 +14,7 @@ public class InetNetwork {
|
||||
private final InetAddress address;
|
||||
private final int mask;
|
||||
|
||||
public InetNetwork(@NonNull final String input) {
|
||||
public InetNetwork(final String input) {
|
||||
final int slash = input.lastIndexOf('/');
|
||||
final int rawMask;
|
||||
final String rawAddress;
|
||||
@@ -40,7 +38,6 @@ public class InetNetwork {
|
||||
return Objects.equals(address, other.address) && mask == other.mask;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public InetAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.databinding.BaseObservable;
|
||||
import android.databinding.Bindable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.wireguard.android.BR;
|
||||
import com.wireguard.crypto.Keypair;
|
||||
@@ -27,7 +28,7 @@ public class Interface {
|
||||
private final List<InetNetwork> addressList;
|
||||
private final List<InetAddress> dnsList;
|
||||
private final List<String> excludedApplications;
|
||||
private Keypair keypair;
|
||||
@Nullable private Keypair keypair;
|
||||
private int listenPort;
|
||||
private int mtu;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class Interface {
|
||||
excludedApplications = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void addAddresses(final String[] addresses) {
|
||||
private void addAddresses(@Nullable final String[] addresses) {
|
||||
if (addresses != null && addresses.length > 0) {
|
||||
for (final String addr : addresses) {
|
||||
if (addr.isEmpty())
|
||||
@@ -47,7 +48,7 @@ public class Interface {
|
||||
}
|
||||
}
|
||||
|
||||
private void addDnses(final String[] dnses) {
|
||||
private void addDnses(@Nullable final String[] dnses) {
|
||||
if (dnses != null && dnses.length > 0) {
|
||||
for (final String dns : dnses) {
|
||||
dnsList.add(InetAddresses.parse(dns));
|
||||
@@ -55,12 +56,13 @@ public class Interface {
|
||||
}
|
||||
}
|
||||
|
||||
private void addExcludedApplications(final String[] applications) {
|
||||
private void addExcludedApplications(@Nullable final String[] applications) {
|
||||
if (applications != null && applications.length > 0) {
|
||||
excludedApplications.addAll(Arrays.asList(applications));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getAddressString() {
|
||||
if (addressList.isEmpty())
|
||||
return null;
|
||||
@@ -71,6 +73,7 @@ public class Interface {
|
||||
return addressList.toArray(new InetNetwork[addressList.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getDnsString() {
|
||||
if (dnsList.isEmpty())
|
||||
return null;
|
||||
@@ -88,6 +91,7 @@ public class Interface {
|
||||
return dnsList.toArray(new InetAddress[dnsList.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getExcludedApplicationsString() {
|
||||
if (excludedApplications.isEmpty())
|
||||
return null;
|
||||
@@ -102,6 +106,7 @@ public class Interface {
|
||||
return listenPort;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getListenPortString() {
|
||||
if (listenPort == 0)
|
||||
return null;
|
||||
@@ -112,18 +117,21 @@ public class Interface {
|
||||
return mtu;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getMtuString() {
|
||||
if (mtu == 0)
|
||||
return null;
|
||||
return Integer.toString(mtu);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getPrivateKey() {
|
||||
if (keypair == null)
|
||||
return null;
|
||||
return keypair.getPrivateKey();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getPublicKey() {
|
||||
if (keypair == null)
|
||||
return null;
|
||||
@@ -156,17 +164,17 @@ public class Interface {
|
||||
}
|
||||
}
|
||||
|
||||
private void setAddressString(final String addressString) {
|
||||
private void setAddressString(@Nullable final String addressString) {
|
||||
addressList.clear();
|
||||
addAddresses(Attribute.stringToList(addressString));
|
||||
}
|
||||
|
||||
private void setDnsString(final String dnsString) {
|
||||
private void setDnsString(@Nullable final String dnsString) {
|
||||
dnsList.clear();
|
||||
addDnses(Attribute.stringToList(dnsString));
|
||||
}
|
||||
|
||||
private void setExcludedApplicationsString(final String applicationsString) {
|
||||
private void setExcludedApplicationsString(@Nullable final String applicationsString) {
|
||||
excludedApplications.clear();
|
||||
addExcludedApplications(Attribute.stringToList(applicationsString));
|
||||
}
|
||||
@@ -175,7 +183,7 @@ public class Interface {
|
||||
this.listenPort = listenPort;
|
||||
}
|
||||
|
||||
private void setListenPortString(final String port) {
|
||||
private void setListenPortString(@Nullable final String port) {
|
||||
if (port != null && !port.isEmpty())
|
||||
setListenPort(Integer.parseInt(port, 10));
|
||||
else
|
||||
@@ -186,14 +194,14 @@ public class Interface {
|
||||
this.mtu = mtu;
|
||||
}
|
||||
|
||||
private void setMtuString(final String mtu) {
|
||||
private void setMtuString(@Nullable final String mtu) {
|
||||
if (mtu != null && !mtu.isEmpty())
|
||||
setMtu(Integer.parseInt(mtu, 10));
|
||||
else
|
||||
setMtu(0);
|
||||
}
|
||||
|
||||
private void setPrivateKey(String privateKey) {
|
||||
private void setPrivateKey(@Nullable String privateKey) {
|
||||
if (privateKey != null && privateKey.isEmpty())
|
||||
privateKey = null;
|
||||
keypair = privateKey == null ? null : new Keypair(privateKey);
|
||||
@@ -229,15 +237,15 @@ public class Interface {
|
||||
return new Observable[size];
|
||||
}
|
||||
};
|
||||
private String addresses;
|
||||
private String dnses;
|
||||
private String excludedApplications;
|
||||
private String listenPort;
|
||||
private String mtu;
|
||||
private String privateKey;
|
||||
private String publicKey;
|
||||
@Nullable private String addresses;
|
||||
@Nullable private String dnses;
|
||||
@Nullable private String excludedApplications;
|
||||
@Nullable private String listenPort;
|
||||
@Nullable private String mtu;
|
||||
@Nullable private String privateKey;
|
||||
@Nullable private String publicKey;
|
||||
|
||||
public Observable(final Interface parent) {
|
||||
public Observable(@Nullable final Interface parent) {
|
||||
if (parent != null)
|
||||
loadData(parent);
|
||||
}
|
||||
@@ -276,16 +284,19 @@ public class Interface {
|
||||
notifyPropertyChanged(BR.publicKey);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getDnses() {
|
||||
return dnses;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getExcludedApplications() {
|
||||
return excludedApplications;
|
||||
@@ -296,21 +307,25 @@ public class Interface {
|
||||
return Attribute.stringToList(excludedApplications).length;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getListenPort() {
|
||||
return listenPort;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getMtu() {
|
||||
return mtu;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Bindable
|
||||
public String getPublicKey() {
|
||||
return publicKey;
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.databinding.BaseObservable;
|
||||
import android.databinding.Bindable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.android.databinding.library.baseAdapters.BR;
|
||||
import com.wireguard.crypto.KeyEncoding;
|
||||
@@ -34,16 +35,16 @@ import java9.lang.Iterables;
|
||||
|
||||
public class Peer {
|
||||
private final List<InetNetwork> allowedIPsList;
|
||||
private InetSocketAddress endpoint;
|
||||
@Nullable private InetSocketAddress endpoint;
|
||||
private int persistentKeepalive;
|
||||
private String preSharedKey;
|
||||
private String publicKey;
|
||||
@Nullable private String preSharedKey;
|
||||
@Nullable private String publicKey;
|
||||
|
||||
public Peer() {
|
||||
allowedIPsList = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void addAllowedIPs(final String[] allowedIPs) {
|
||||
private void addAllowedIPs(@Nullable final String[] allowedIPs) {
|
||||
if (allowedIPs != null && allowedIPs.length > 0) {
|
||||
for (final String allowedIP : allowedIPs) {
|
||||
allowedIPsList.add(new InetNetwork(allowedIP));
|
||||
@@ -55,16 +56,19 @@ public class Peer {
|
||||
return allowedIPsList.toArray(new InetNetwork[allowedIPsList.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getAllowedIPsString() {
|
||||
if (allowedIPsList.isEmpty())
|
||||
return null;
|
||||
return Attribute.iterableToString(allowedIPsList);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InetSocketAddress getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getEndpointString() {
|
||||
if (endpoint == null)
|
||||
return null;
|
||||
@@ -75,16 +79,19 @@ public class Peer {
|
||||
return persistentKeepalive;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getPersistentKeepaliveString() {
|
||||
if (persistentKeepalive == 0)
|
||||
return null;
|
||||
return Integer.valueOf(persistentKeepalive).toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getPreSharedKey() {
|
||||
return preSharedKey;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
@@ -130,16 +137,16 @@ public class Peer {
|
||||
}
|
||||
}
|
||||
|
||||
private void setAllowedIPsString(final String allowedIPsString) {
|
||||
private void setAllowedIPsString(@Nullable final String allowedIPsString) {
|
||||
allowedIPsList.clear();
|
||||
addAllowedIPs(Attribute.stringToList(allowedIPsString));
|
||||
}
|
||||
|
||||
private void setEndpoint(final InetSocketAddress endpoint) {
|
||||
private void setEndpoint(@Nullable final InetSocketAddress endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
private void setEndpointString(final String endpoint) {
|
||||
private void setEndpointString(@Nullable final String endpoint) {
|
||||
if (endpoint != null && !endpoint.isEmpty()) {
|
||||
final InetSocketAddress constructedEndpoint;
|
||||
if (endpoint.indexOf('/') != -1 || endpoint.indexOf('?') != -1 || endpoint.indexOf('#') != -1)
|
||||
@@ -160,14 +167,14 @@ public class Peer {
|
||||
this.persistentKeepalive = persistentKeepalive;
|
||||
}
|
||||
|
||||
private void setPersistentKeepaliveString(final String persistentKeepalive) {
|
||||
private void setPersistentKeepaliveString(@Nullable final String persistentKeepalive) {
|
||||
if (persistentKeepalive != null && !persistentKeepalive.isEmpty())
|
||||
setPersistentKeepalive(Integer.parseInt(persistentKeepalive, 10));
|
||||
else
|
||||
setPersistentKeepalive(0);
|
||||
}
|
||||
|
||||
private void setPreSharedKey(String preSharedKey) {
|
||||
private void setPreSharedKey(@Nullable String preSharedKey) {
|
||||
if (preSharedKey != null && preSharedKey.isEmpty())
|
||||
preSharedKey = null;
|
||||
if (preSharedKey != null)
|
||||
@@ -175,7 +182,7 @@ public class Peer {
|
||||
this.preSharedKey = preSharedKey;
|
||||
}
|
||||
|
||||
private void setPublicKey(String publicKey) {
|
||||
private void setPublicKey(@Nullable String publicKey) {
|
||||
if (publicKey != null && publicKey.isEmpty())
|
||||
publicKey = null;
|
||||
if (publicKey != null)
|
||||
@@ -211,12 +218,12 @@ public class Peer {
|
||||
return new Observable[size];
|
||||
}
|
||||
};
|
||||
private String allowedIPs;
|
||||
private String endpoint;
|
||||
private String persistentKeepalive;
|
||||
private String preSharedKey;
|
||||
private String publicKey;
|
||||
private List<String> interfaceDNSRoutes;
|
||||
@Nullable private String allowedIPs;
|
||||
@Nullable private String endpoint;
|
||||
@Nullable private String persistentKeepalive;
|
||||
@Nullable private String preSharedKey;
|
||||
@Nullable private String publicKey;
|
||||
private final List<String> interfaceDNSRoutes = new ArrayList<>();
|
||||
private int numSiblings;
|
||||
|
||||
public Observable(final Peer parent) {
|
||||
@@ -230,7 +237,6 @@ public class Peer {
|
||||
preSharedKey = in.readString();
|
||||
publicKey = in.readString();
|
||||
numSiblings = in.readInt();
|
||||
interfaceDNSRoutes = new ArrayList<>();
|
||||
in.readStringList(interfaceDNSRoutes);
|
||||
}
|
||||
|
||||
@@ -284,27 +290,27 @@ public class Peer {
|
||||
return numSiblings == 0 && Arrays.asList(Attribute.stringToList(allowedIPs)).containsAll(DEFAULT_ROUTE_MOD_RFC1918_V4);
|
||||
}
|
||||
|
||||
@Bindable
|
||||
@Bindable @Nullable
|
||||
public String getAllowedIPs() {
|
||||
return allowedIPs;
|
||||
}
|
||||
|
||||
@Bindable
|
||||
@Bindable @Nullable
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
@Bindable
|
||||
@Bindable @Nullable
|
||||
public String getPersistentKeepalive() {
|
||||
return persistentKeepalive;
|
||||
}
|
||||
|
||||
@Bindable
|
||||
@Bindable @Nullable
|
||||
public String getPreSharedKey() {
|
||||
return preSharedKey;
|
||||
}
|
||||
|
||||
@Bindable
|
||||
@Bindable @Nullable
|
||||
public String getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
@@ -315,7 +321,6 @@ public class Peer {
|
||||
persistentKeepalive = parent.getPersistentKeepaliveString();
|
||||
preSharedKey = parent.getPreSharedKey();
|
||||
publicKey = parent.getPublicKey();
|
||||
interfaceDNSRoutes = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setAllowedIPs(final String allowedIPs) {
|
||||
|
||||
Reference in New Issue
Block a user