diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-09 12:01:52 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-09 12:19:15 -0600 |
commit | 8e8643122eb5783d4412c8a81fb03cc789c3f77c (patch) | |
tree | 43cc7ea98c33115a7b3bc062104deeb75c580f19 /tunnel/src/main/java/com/wireguard | |
parent | c00a0b12e4bf353a20a520c59961b21374050089 (diff) |
global: get rid of nonnull gradle hack
Hacking things up via gradle is not right, and package-info.java poses
problems with two modules, so instead we just apply it manually to every
class.
Remember to add this to new classes!
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel/src/main/java/com/wireguard')
24 files changed, 70 insertions, 0 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java index ed3a5ebd..853802d2 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/Backend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/Backend.java @@ -5,6 +5,8 @@ package com.wireguard.android.backend; +import com.wireguard.util.NonNullForAll; + import com.wireguard.config.Config; import java.util.Collection; @@ -16,6 +18,7 @@ import androidx.annotation.Nullable; * Interface for implementations of the WireGuard secure network tunnel. */ +@NonNullForAll public interface Backend { /** * Enumerate names of currently-running tunnels. diff --git a/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java b/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java index e1e8eaa9..0f60701b 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/BackendException.java @@ -5,6 +5,9 @@ package com.wireguard.android.backend; +import com.wireguard.util.NonNullForAll; + +@NonNullForAll public final class BackendException extends Exception { public enum Reason { UNKNOWN_KERNEL_MODULE_NAME, diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java index 6ad5afa4..bf434cf5 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -5,6 +5,8 @@ package com.wireguard.android.backend; +import com.wireguard.util.NonNullForAll; + import android.content.Context; import android.content.Intent; import android.os.Build; @@ -30,6 +32,7 @@ import java.util.concurrent.TimeoutException; import java9.util.concurrent.CompletableFuture; +@NonNullForAll public final class GoBackend implements Backend { private static final String TAG = "WireGuard/" + GoBackend.class.getSimpleName(); private static CompletableFuture<VpnService> vpnService = new CompletableFuture<>(); diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java b/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java index 2ca87d23..f878a1f0 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/Statistics.java @@ -5,6 +5,8 @@ package com.wireguard.android.backend; +import com.wireguard.util.NonNullForAll; + import android.os.SystemClock; import android.util.Pair; @@ -13,6 +15,7 @@ import com.wireguard.crypto.Key; import java.util.HashMap; import java.util.Map; +@NonNullForAll public class Statistics { private long lastTouched = SystemClock.elapsedRealtime(); private final Map<Key, Pair<Long, Long>> peerBytes = new HashMap<>(); diff --git a/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java b/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java index af2f59f7..fccda84f 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java @@ -5,12 +5,15 @@ package com.wireguard.android.backend; +import com.wireguard.util.NonNullForAll; + import java.util.regex.Pattern; /** * Represents a WireGuard tunnel. */ +@NonNullForAll public interface Tunnel { enum State { DOWN, diff --git a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java index 53fe3d42..c4434e4d 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/WgQuickBackend.java @@ -5,6 +5,8 @@ package com.wireguard.android.backend; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import android.content.Context; @@ -39,6 +41,7 @@ import java9.util.stream.Stream; * WireGuard backend that uses {@code wg-quick} to implement tunnel configuration. */ +@NonNullForAll public final class WgQuickBackend implements Backend { private static final String TAG = "WireGuard/" + WgQuickBackend.class.getSimpleName(); diff --git a/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java b/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java index f09d9a87..40645a43 100644 --- a/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java +++ b/tunnel/src/main/java/com/wireguard/android/util/ModuleLoader.java @@ -5,6 +5,8 @@ package com.wireguard.android.util; +import com.wireguard.util.NonNullForAll; + import android.content.Context; import android.system.OsConstants; import android.util.Base64; @@ -36,6 +38,7 @@ import java.util.Map; import androidx.annotation.Nullable; +@NonNullForAll public class ModuleLoader { private static final String MODULE_PUBLIC_KEY_BASE64 = "RWRmHuT9PSqtwfsLtEx+QS06BJtLgFYteL9WCNjH7yuyu5Y1DieSN7If"; private static final String MODULE_LIST_URL = "https://download.wireguard.com/android-module/modules.txt.sig"; diff --git a/tunnel/src/main/java/com/wireguard/android/util/RootShell.java b/tunnel/src/main/java/com/wireguard/android/util/RootShell.java index 1fc2c9f2..eccc61cb 100644 --- a/tunnel/src/main/java/com/wireguard/android/util/RootShell.java +++ b/tunnel/src/main/java/com/wireguard/android/util/RootShell.java @@ -5,6 +5,8 @@ package com.wireguard.android.util; +import com.wireguard.util.NonNullForAll; + import android.content.Context; import androidx.annotation.Nullable; import android.util.Log; @@ -24,6 +26,7 @@ import java.util.UUID; * Helper class for running commands as root. */ +@NonNullForAll public class RootShell { private static final String SU = "su"; private static final String TAG = "WireGuard/" + RootShell.class.getSimpleName(); diff --git a/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java b/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java index 93e44b64..3c2448fe 100644 --- a/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java +++ b/tunnel/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java @@ -5,6 +5,8 @@ package com.wireguard.android.util; +import com.wireguard.util.NonNullForAll; + import android.content.Context; import android.os.Build; import android.util.Log; @@ -19,6 +21,7 @@ import java.util.HashSet; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +@NonNullForAll public final class SharedLibraryLoader { private static final String TAG = "WireGuard/" + SharedLibraryLoader.class.getSimpleName(); diff --git a/tunnel/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/tunnel/src/main/java/com/wireguard/android/util/ToolsInstaller.java index ac18cabf..1ce3fe80 100644 --- a/tunnel/src/main/java/com/wireguard/android/util/ToolsInstaller.java +++ b/tunnel/src/main/java/com/wireguard/android/util/ToolsInstaller.java @@ -5,6 +5,8 @@ package com.wireguard.android.util; +import com.wireguard.util.NonNullForAll; + import android.content.Context; import androidx.annotation.Nullable; import android.system.OsConstants; @@ -22,6 +24,7 @@ import java.util.List; * Helper to install WireGuard tools to the system partition. */ +@NonNullForAll public final class ToolsInstaller { public static final int ERROR = 0x0; public static final int MAGISK = 0x4; diff --git a/tunnel/src/main/java/com/wireguard/config/Attribute.java b/tunnel/src/main/java/com/wireguard/config/Attribute.java index 1e9e25f0..659f7cf4 100644 --- a/tunnel/src/main/java/com/wireguard/config/Attribute.java +++ b/tunnel/src/main/java/com/wireguard/config/Attribute.java @@ -5,12 +5,15 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import java.util.Iterator; import java.util.regex.Matcher; import java.util.regex.Pattern; import java9.util.Optional; +@NonNullForAll public final class Attribute { private static final Pattern LINE_PATTERN = Pattern.compile("(\\w+)\\s*=\\s*([^\\s#][^#]*)"); private static final Pattern LIST_SEPARATOR = Pattern.compile("\\s*,\\s*"); diff --git a/tunnel/src/main/java/com/wireguard/config/BadConfigException.java b/tunnel/src/main/java/com/wireguard/config/BadConfigException.java index 6d41b065..89b3af2c 100644 --- a/tunnel/src/main/java/com/wireguard/config/BadConfigException.java +++ b/tunnel/src/main/java/com/wireguard/config/BadConfigException.java @@ -5,10 +5,13 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import com.wireguard.crypto.KeyFormatException; +@NonNullForAll public class BadConfigException extends Exception { private final Location location; private final Reason reason; diff --git a/tunnel/src/main/java/com/wireguard/config/Config.java b/tunnel/src/main/java/com/wireguard/config/Config.java index 62651b08..f86eb6fd 100644 --- a/tunnel/src/main/java/com/wireguard/config/Config.java +++ b/tunnel/src/main/java/com/wireguard/config/Config.java @@ -5,6 +5,8 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import com.wireguard.config.BadConfigException.Location; @@ -29,6 +31,7 @@ import java.util.Set; * <p> * Instances of this class are immutable. */ +@NonNullForAll public final class Config { private final Interface interfaze; private final List<Peer> peers; diff --git a/tunnel/src/main/java/com/wireguard/config/InetAddresses.java b/tunnel/src/main/java/com/wireguard/config/InetAddresses.java index 1479b5ff..9b0ab965 100644 --- a/tunnel/src/main/java/com/wireguard/config/InetAddresses.java +++ b/tunnel/src/main/java/com/wireguard/config/InetAddresses.java @@ -5,6 +5,8 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import java.lang.reflect.Method; import java.net.Inet4Address; import java.net.Inet6Address; @@ -17,6 +19,7 @@ import androidx.annotation.Nullable; /** * Utility methods for creating instances of {@link InetAddress}. */ +@NonNullForAll public final class InetAddresses { @Nullable private static final Method PARSER_METHOD; private static final Pattern WONT_TOUCH_RESOLVER = Pattern.compile("^(((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\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src/main/java/com/wireguard/config/InetEndpoint.java b/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java index a442258e..69c60806 100644 --- a/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java +++ b/tunnel/src/main/java/com/wireguard/config/InetEndpoint.java @@ -5,6 +5,8 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import org.threeten.bp.Duration; @@ -25,6 +27,7 @@ import java9.util.Optional; * <p> * Instances of this class are externally immutable. */ +@NonNullForAll public final class InetEndpoint { private static final Pattern BARE_IPV6 = Pattern.compile("^[^\\[\\]]*:[^\\[\\]]*"); private static final Pattern FORBIDDEN_CHARACTERS = Pattern.compile("[/?#]"); diff --git a/tunnel/src/main/java/com/wireguard/config/InetNetwork.java b/tunnel/src/main/java/com/wireguard/config/InetNetwork.java index f89322fd..0c993fc8 100644 --- a/tunnel/src/main/java/com/wireguard/config/InetNetwork.java +++ b/tunnel/src/main/java/com/wireguard/config/InetNetwork.java @@ -5,6 +5,8 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import java.net.Inet4Address; import java.net.InetAddress; @@ -13,6 +15,7 @@ import java.net.InetAddress; * <p> * Instances of this class are immutable. */ +@NonNullForAll public final class InetNetwork { private final InetAddress address; private final int mask; diff --git a/tunnel/src/main/java/com/wireguard/config/Interface.java b/tunnel/src/main/java/com/wireguard/config/Interface.java index 54944424..efe00ce7 100644 --- a/tunnel/src/main/java/com/wireguard/config/Interface.java +++ b/tunnel/src/main/java/com/wireguard/config/Interface.java @@ -5,6 +5,8 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import com.wireguard.config.BadConfigException.Location; @@ -35,6 +37,7 @@ import java9.util.stream.StreamSupport; * <p> * Instances of this class are immutable. */ +@NonNullForAll public final class Interface { private static final int MAX_UDP_PORT = 65535; private static final int MIN_UDP_PORT = 0; diff --git a/tunnel/src/main/java/com/wireguard/config/ParseException.java b/tunnel/src/main/java/com/wireguard/config/ParseException.java index c79d1fa1..f4da7ccd 100644 --- a/tunnel/src/main/java/com/wireguard/config/ParseException.java +++ b/tunnel/src/main/java/com/wireguard/config/ParseException.java @@ -5,10 +5,13 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; /** */ +@NonNullForAll public class ParseException extends Exception { private final Class<?> parsingClass; private final CharSequence text; diff --git a/tunnel/src/main/java/com/wireguard/config/Peer.java b/tunnel/src/main/java/com/wireguard/config/Peer.java index 37fcfa69..ef91a306 100644 --- a/tunnel/src/main/java/com/wireguard/config/Peer.java +++ b/tunnel/src/main/java/com/wireguard/config/Peer.java @@ -5,6 +5,8 @@ package com.wireguard.config; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import com.wireguard.config.BadConfigException.Location; @@ -28,6 +30,7 @@ import java9.util.Optional; * <p> * Instances of this class are immutable. */ +@NonNullForAll public final class Peer { private final Set<InetNetwork> allowedIps; private final Optional<InetEndpoint> endpoint; diff --git a/tunnel/src/main/java/com/wireguard/crypto/Curve25519.java b/tunnel/src/main/java/com/wireguard/crypto/Curve25519.java index 5622fc5f..7628c566 100644 --- a/tunnel/src/main/java/com/wireguard/crypto/Curve25519.java +++ b/tunnel/src/main/java/com/wireguard/crypto/Curve25519.java @@ -6,6 +6,8 @@ package com.wireguard.crypto; +import com.wireguard.util.NonNullForAll; + import androidx.annotation.Nullable; import java.util.Arrays; @@ -25,6 +27,7 @@ import java.util.Arrays; * References: http://cr.yp.to/ecdh.html, RFC 7748 */ @SuppressWarnings({"MagicNumber", "NonConstantFieldWithUpperCaseName", "SuspiciousNameCombination"}) +@NonNullForAll public final class Curve25519 { // Numbers modulo 2^255 - 19 are broken up into ten 26-bit words. private static final int NUM_LIMBS_255BIT = 10; diff --git a/tunnel/src/main/java/com/wireguard/crypto/Key.java b/tunnel/src/main/java/com/wireguard/crypto/Key.java index 6648a5f3..e46150bd 100644 --- a/tunnel/src/main/java/com/wireguard/crypto/Key.java +++ b/tunnel/src/main/java/com/wireguard/crypto/Key.java @@ -5,6 +5,8 @@ package com.wireguard.crypto; +import com.wireguard.util.NonNullForAll; + import com.wireguard.crypto.KeyFormatException.Type; import java.security.MessageDigest; @@ -18,6 +20,7 @@ import java.util.Arrays; * Instances of this class are immutable. */ @SuppressWarnings("MagicNumber") +@NonNullForAll public final class Key { private final byte[] key; diff --git a/tunnel/src/main/java/com/wireguard/crypto/KeyFormatException.java b/tunnel/src/main/java/com/wireguard/crypto/KeyFormatException.java index 5818b4d4..8608fc36 100644 --- a/tunnel/src/main/java/com/wireguard/crypto/KeyFormatException.java +++ b/tunnel/src/main/java/com/wireguard/crypto/KeyFormatException.java @@ -5,11 +5,14 @@ package com.wireguard.crypto; +import com.wireguard.util.NonNullForAll; + /** * An exception thrown when attempting to parse an invalid key (too short, too long, or byte * data inappropriate for the format). The format being parsed can be accessed with the * {@link #getFormat} method. */ +@NonNullForAll public final class KeyFormatException extends Exception { private final Key.Format format; private final Type type; diff --git a/tunnel/src/main/java/com/wireguard/crypto/KeyPair.java b/tunnel/src/main/java/com/wireguard/crypto/KeyPair.java index f8238e91..22c21734 100644 --- a/tunnel/src/main/java/com/wireguard/crypto/KeyPair.java +++ b/tunnel/src/main/java/com/wireguard/crypto/KeyPair.java @@ -5,11 +5,14 @@ package com.wireguard.crypto; +import com.wireguard.util.NonNullForAll; + /** * Represents a Curve25519 key pair as used by WireGuard. * <p> * Instances of this class are immutable. */ +@NonNullForAll public class KeyPair { private final Key privateKey; private final Key publicKey; diff --git a/tunnel/src/main/java/com/wireguard/util/NonNullForAll.java b/tunnel/src/main/java/com/wireguard/util/NonNullForAll.java index f179fa49..2c2d9400 100644 --- a/tunnel/src/main/java/com/wireguard/util/NonNullForAll.java +++ b/tunnel/src/main/java/com/wireguard/util/NonNullForAll.java @@ -22,5 +22,6 @@ import javax.annotation.meta.TypeQualifierDefault; @Nonnull @TypeQualifierDefault({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) + public @interface NonNullForAll { } |