From 529e320e3fa20a70f8918fa5d7e559438d5c071e Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Wed, 9 Aug 2017 02:51:54 -0500 Subject: [PATCH] Interface: Correctly handle setting a null or empty key Signed-off-by: Jason A. Donenfeld --- .../main/java/com/wireguard/config/Interface.java | 12 ++++++++---- 1 file 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); }