aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2016-03-11 19:33:01 -0800
committerKenny Root <kenny@the-b.org>2016-03-11 19:34:42 -0800
commit6f46015a01c6901a6e8e19cc8847ffd1c3785e33 (patch)
treeb2ae24bfab53cbc3e3a839e2a20adf780e6be87d
parentdfb607ffeb77dfea843c5db93d28d035c2188ef4 (diff)
downloadsshlib-6f46015a01c6901a6e8e19cc8847ffd1c3785e33.tar.gz
sshlib-6f46015a01c6901a6e8e19cc8847ffd1c3785e33.tar.bz2
sshlib-6f46015a01c6901a6e8e19cc8847ffd1c3785e33.zip
ed25519: implement equality and hashCode
The KnownHosts code uses .equals() to figure out if keys are the same, so implement these in Ed25519Key so that type of key works in that case.
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/crypto/key/Ed25519Key.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/sshlib/src/main/java/com/trilead/ssh2/crypto/key/Ed25519Key.java b/sshlib/src/main/java/com/trilead/ssh2/crypto/key/Ed25519Key.java
index 5c9e549..2c49350 100644
--- a/sshlib/src/main/java/com/trilead/ssh2/crypto/key/Ed25519Key.java
+++ b/sshlib/src/main/java/com/trilead/ssh2/crypto/key/Ed25519Key.java
@@ -18,6 +18,7 @@
package com.trilead.ssh2.crypto.key;
import java.security.Key;
+import java.util.Arrays;
/**
* Java representation of a native Ed25519 key.
@@ -42,4 +43,19 @@ public class Ed25519Key implements Key {
public byte[] getEncoded() {
return keyBytes;
}
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(keyBytes);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof Ed25519Key)) {
+ return false;
+ }
+
+ Ed25519Key otherKey = (Ed25519Key) other;
+ return Arrays.equals(keyBytes, otherKey.keyBytes);
+ }
}