@Override public String toString() { if ((getDigester() == null) || NumberUtils.isEmpty(getSaltValue()) || NumberUtils.isEmpty(getDigestValue())) { return Objects.toString(getDigester(), null) + "-" + BufferUtils.toHex(':', getSaltValue()) + "-" + BufferUtils.toHex(':', getDigestValue()); } try { return append(new StringBuilder(Byte.MAX_VALUE), this).toString(); } catch (IOException | RuntimeException e) { // unexpected return e.getClass().getSimpleName() + ": " + e.getMessage(); } }
@Override public String toString() { if ((getDigester() == null) || NumberUtils.isEmpty(getSaltValue()) || NumberUtils.isEmpty(getDigestValue())) { return Objects.toString(getDigester(), null) + "-" + BufferUtils.toHex(':', getSaltValue()) + "-" + BufferUtils.toHex(':', getDigestValue()); } try { return append(new StringBuilder(Byte.MAX_VALUE), this).toString(); } catch (IOException | RuntimeException e) { // unexpected return e.getClass().getSimpleName() + ": " + e.getMessage(); } }
public static <A extends Appendable> A append(A sb, KnownHostHashValue hashValue) throws IOException { return (hashValue == null) ? sb : append(sb, hashValue.getDigester(), hashValue.getSaltValue(), hashValue.getDigestValue()); }
/** * Checks if the host matches the hash * * @param host The host name/address - ignored if {@code null}/empty * @return {@code true} if host matches the hash * @throws RuntimeException If entry not properly initialized */ public boolean isHostMatch(String host) { if (GenericUtils.isEmpty(host)) { return false; } try { byte[] expected = getDigestValue(); byte[] actual = calculateHashValue(host, getDigester(), getSaltValue()); return Arrays.equals(expected, actual); } catch (Throwable t) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } throw new RuntimeSshException("Failed (" + t.getClass().getSimpleName() + ")" + " to calculate hash value: " + t.getMessage(), t); } }
public static <A extends Appendable> A append(A sb, KnownHostHashValue hashValue) throws IOException { return (hashValue == null) ? sb : append(sb, hashValue.getDigester(), hashValue.getSaltValue(), hashValue.getDigestValue()); }
/** * Checks if the host matches the hash * * @param host The host name/address - ignored if {@code null}/empty * @param port The access port - ignored if non-positive or SSH default * @return {@code true} if host matches the hash * @throws RuntimeException If entry not properly initialized */ public boolean isHostMatch(String host, int port) { if (GenericUtils.isEmpty(host)) { return false; } try { byte[] expected = getDigestValue(); byte[] actual = calculateHashValue(host, port, getDigester(), getSaltValue()); return Arrays.equals(expected, actual); } catch (Throwable t) { if (t instanceof RuntimeException) { throw (RuntimeException) t; } throw new RuntimeSshException("Failed (" + t.getClass().getSimpleName() + ")" + " to calculate hash value: " + t.getMessage(), t); } }