From 6f46015a01c6901a6e8e19cc8847ffd1c3785e33 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 11 Mar 2016 19:33:01 -0800 Subject: 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. --- .../java/com/trilead/ssh2/crypto/key/Ed25519Key.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); + } } -- cgit v1.2.3