aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/crypto/Key.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/wireguard/crypto/Key.java')
-rw-r--r--app/src/main/java/com/wireguard/crypto/Key.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/crypto/Key.java b/app/src/main/java/com/wireguard/crypto/Key.java
index f743ddd2..6648a5f3 100644
--- a/app/src/main/java/com/wireguard/crypto/Key.java
+++ b/app/src/main/java/com/wireguard/crypto/Key.java
@@ -7,6 +7,7 @@ package com.wireguard.crypto;
import com.wireguard.crypto.KeyFormatException.Type;
+import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Arrays;
@@ -247,6 +248,24 @@ public final class Key {
return new String(output);
}
+ @Override
+ public int hashCode() {
+ int ret = 0;
+ for (int i = 0; i < key.length / 4; ++i)
+ ret ^= (key[i * 4 + 0] >> 0) + (key[i * 4 + 1] >> 8) + (key[i * 4 + 2] >> 16) + (key[i * 4 + 3] >> 24);
+ return ret;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this)
+ return true;
+ if (obj == null || obj.getClass() != getClass())
+ return false;
+ final Key other = (Key) obj;
+ return MessageDigest.isEqual(key, other.key);
+ }
+
/**
* The supported formats for encoding a WireGuard key.
*/