Utility { public static @Nullable String protobufKeyToHexIfEd25519OrNull(@Nullable byte[] protobufKey) { if ((null == protobufKey) || (0 == protobufKey.length)) { return null; } try { var parsedKey = Key.parseFrom(protobufKey); if (ED25519 != parsedKey.getKeyCase()) { return null; } return Hex.encodeHexString(parsedKey.getEd25519().toByteArray(), true); } catch (InvalidProtocolBufferException protoEx) { log.error("Invalid protobuf Key, could parse key", protoEx); return null; } catch (Exception e) { log.error("Invalid ED25519 key could not be translated to hex text.", e); return null; } }  static Pair<byte[], byte[]> extractHashAndSigFromFile(File file); static String getBalanceFileHash(String fileName); static RecordFile parseRecordFile(String filePath, Consumer<RecordItem> recordItemConsumer); static int readInt(DataInputStream dis, MessageDigest md); static byte[] readBytes(DataInputStream dis, int len, MessageDigest md); static Timestamp instantToTimestamp(Instant instant); static String accountIDToString(AccountID accountID); static Instant convertToInstant(Timestamp timestamp); static String printProtoMessage(GeneratedMessageV3 message); static String bytesToHex(byte[] bytes); static Long convertToNanos(long second, long nanos); static Long convertToNanosMax(long second, long nanos); static Long timeStampInNanos(Timestamp timestamp); static Long timestampInNanosMax(Timestamp timestamp); static boolean hashIsEmpty(String hash); static void archiveFile(File source, Path destinationRoot); static void purgeDirectory(Path path); static void ensureDirectory(Path path); static File getResource(String path); static final Instant getInstantFromFilename(String filename); static final long getTimestampFromFilename(String filename); static final String getStreamFilenameFromInstant(StreamType streamType, Instant instant); static final boolean isStreamFileAfterInstant(String filename, Instant instant); static @Nullable String protobufKeyToHexIfEd25519OrNull(@Nullable byte[] protobufKey); static TransactionID getTransactionId(AccountID payerAccountId); static boolean verifyHashChain(
            String actualPrevFileHash, String expectedPrevFileHash, Instant verifyHashAfter, String fileName); static final Instant MAX_INSTANT_LONG; }
@Test @DisplayName("protobufKeyToHexIfEd25519OrNull null key") public void protobufKeyToHexIfEd25519OrNull_Null() throws InvalidProtocolBufferException, SQLException { var result = Utility.protobufKeyToHexIfEd25519OrNull(null); assertThat(result).isNull(); }
@Test @DisplayName("protobufKeyToHexIfEd25519OrNull valid ED25519 key") public void protobufKeyToHexIfEd25519OrNull_Valid() throws Exception { var instr = "0011223344556677889900aabbccddeeff0011223344556677889900aabbccddeeff"; var input = Key.newBuilder().setEd25519(ByteString.copyFrom(Hex.decodeHex(instr))).build(); var result = Utility.protobufKeyToHexIfEd25519OrNull(input.toByteArray()); assertThat(result).isEqualTo(instr); }
@Test @DisplayName("protobufKeyToHexIfEd25519OrNull threshold key") public void protobufKeyToHexIfEd25519OrNull_ThresholdKey() throws Exception { var ks = "0011223344556677889900aabbccddeeff0011223344556677889900aabbccddeeff"; var key = Key.newBuilder().setEd25519(ByteString.copyFrom(Hex.decodeHex(ks))).build(); var keyList = KeyList.newBuilder().addKeys(key).build(); var tk = ThresholdKey.newBuilder().setThreshold(1).setKeys(keyList).build(); var input = Key.newBuilder().setThresholdKey(tk).build(); var result = Utility.protobufKeyToHexIfEd25519OrNull(input.toByteArray()); assertThat(result).isNull(); }