diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-09 02:51:54 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-09 02:51:54 -0500 |
commit | 529e320e3fa20a70f8918fa5d7e559438d5c071e (patch) | |
tree | b6d9dc9ea11093730d932220978c7ee547ae25d6 | |
parent | f0f9192aedaa4bef9ceb42dfb7b11cc1c9baf39a (diff) |
Interface: Correctly handle setting a null or empty key
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | app/src/main/java/com/wireguard/config/Interface.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index d583f37b..6116a4a7 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -90,10 +90,14 @@ public class Interface extends BaseObservable implements Observable { } public void setPrivateKey(String privateKey) { - // Avoid exceptions from Keypair while the user is typing. - if (privateKey.length() != KeyEncoding.KEY_LENGTH_BASE64) - return; - keypair = new Keypair(privateKey); + if (privateKey != null && !privateKey.isEmpty()) { + // Avoid exceptions from Keypair while the user is typing. + if (privateKey.length() != KeyEncoding.KEY_LENGTH_BASE64) + return; + keypair = new Keypair(privateKey); + } else { + keypair = null; + } notifyPropertyChanged(BR.privateKey); notifyPropertyChanged(BR.publicKey); } |