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 | a489eaf21357b9b3a7f3a06b27cf884a066c177f (patch) | |
tree | b6d9dc9ea11093730d932220978c7ee547ae25d6 | |
parent | b7e80a93280cf6837443268c3bd3692cc009f9fb (diff) |
Interface: Correctly handle setting a null or empty key
-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); } |