Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change JKey methods to throw InvalidKeyException and add equals and hashCode #7143

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
import com.swirlds.common.system.transaction.ConsensusTransaction;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.security.InvalidKeyException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.codec.DecoderException;

@Singleton
public class AdaptedMonoProcessLogic implements ProcessLogic {
Expand Down Expand Up @@ -120,7 +120,7 @@ private List<TransactionSignature> extract(@Nullable final Collection<SignatureV
private JKey mapToJKey(@NonNull final Key key) {
try {
return JKey.mapKey(key);
} catch (DecoderException e) {
} catch (InvalidKeyException e) {
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalArgumentException("Unable to map key", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.hedera.pbj.runtime.io.buffer.Bytes;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import org.apache.commons.codec.DecoderException;
import java.security.InvalidKeyException;

/**
* The class is used to convert a {@link com.hedera.node.app.service.mono.files.HFileMeta} content and metadata to a {@link File} and vice versa during the migration process
Expand Down Expand Up @@ -82,7 +82,7 @@ public static File stateToPbj(
*/
@NonNull
public static FileMetadataAndContent pbjToState(
@NonNull FileID fileID, @NonNull ReadableFileStoreImpl readableFileStore) throws DecoderException {
@NonNull FileID fileID, @NonNull ReadableFileStoreImpl readableFileStore) throws InvalidKeyException {
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
requireNonNull(fileID);
requireNonNull(readableFileStore);
final var optionalFile = readableFileStore.getFileLeaf(fileID);
Expand All @@ -95,7 +95,7 @@ public static FileMetadataAndContent pbjToState(
* @return File and metadata pair object
*/
@NonNull
public static FileMetadataAndContent pbjToState(@NonNull File file) throws DecoderException {
public static FileMetadataAndContent pbjToState(@NonNull File file) throws InvalidKeyException {
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
requireNonNull(file);
var keys = (file.hasKeys())
? com.hedera.node.app.service.mono.legacy.core.jproto.JKey.convertKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.hedera.node.app.service.file.impl.test.FileTestBase;
import com.hedera.node.app.service.mono.files.HFileMeta;
import com.hedera.node.app.service.mono.utils.MiscUtils;
import org.apache.commons.codec.DecoderException;
import java.security.InvalidKeyException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -45,7 +45,7 @@ public class FileServiceStateTranslatorTest extends FileTestBase {
void setUp() {}

@Test
void createFileMetadataAndContentFromFile() throws DecoderException {
void createFileMetadataAndContentFromFile() throws InvalidKeyException {
final var existingFile = readableStore.getFileMetadata(fileId);
assertFalse(existingFile.deleted());

Expand All @@ -69,7 +69,7 @@ void createFileMetadataAndContentFromFile() throws DecoderException {
}

@Test
void createFileMetadataAndContentFromFileWithEmptyKeysAndMemo() throws DecoderException {
void createFileMetadataAndContentFromFileWithEmptyKeysAndMemo() throws InvalidKeyException {
final var existingFile = readableStore.getFileMetadata(fileId);
assertFalse(existingFile.deleted());

Expand Down Expand Up @@ -101,7 +101,7 @@ void createFileMetadataAndContentFromFileWithEmptyKeysAndMemo() throws DecoderEx
}

@Test
void createFileMetadataAndContentFromFileWithEmptyConentForDeletedFile() throws DecoderException {
void createFileMetadataAndContentFromFileWithEmptyConentForDeletedFile() throws InvalidKeyException {

final FileMetadataAndContent convertedFile = FileServiceStateTranslator.pbjToState(fileWithNoContent);

Expand All @@ -125,7 +125,7 @@ void createFileMetadataAndContentFromFileWithEmptyConentForDeletedFile() throws
}

@Test
void createFileMetadataAndContentFromReadableFileStore() throws DecoderException {
void createFileMetadataAndContentFromReadableFileStore() throws InvalidKeyException {
final var existingFile = readableStore.getFileMetadata(fileId);
assertFalse(existingFile.deleted());

Expand Down Expand Up @@ -200,7 +200,7 @@ void createFileFromFileIDAndHederaFs() {
assertEquals(createFile(), convertedFile);
}

private FileMetadataAndContent getExpectedMonoFileMetaAndContent() throws DecoderException {
private FileMetadataAndContent getExpectedMonoFileMetaAndContent() throws InvalidKeyException {
var keys = com.hedera.node.app.service.mono.legacy.core.jproto.JKey.convertKey(
Key.newBuilder().keyList(file.keys()).build(), 1);
com.hedera.node.app.service.mono.files.HFileMeta hFileMeta =
Expand All @@ -214,7 +214,7 @@ private FileMetadataAndContent getExpectedMonoFileMetaAndContentWithEmptyMemoAnd
return new FileMetadataAndContent(file.contents().toByteArray(), hFileMeta);
}

private FileMetadataAndContent getExpectedMonoFileMetaAndContentEmptyContent() throws DecoderException {
private FileMetadataAndContent getExpectedMonoFileMetaAndContentEmptyContent() throws InvalidKeyException {
var keys = com.hedera.node.app.service.mono.legacy.core.jproto.JKey.convertKey(
Key.newBuilder().keyList(file.keys()).build(), 1);
com.hedera.node.app.service.mono.files.HFileMeta hFileMeta =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.hedera.node.app.spi.key.HederaKey;
import com.hederahashgraph.api.proto.java.Key;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.security.InvalidKeyException;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.codec.DecoderException;

// This class should not exist. Right now we have code that needs to map from a JKey to a
// HederaKey, but that should be an implementation detail handled somewhere in the token
Expand All @@ -45,7 +45,7 @@ public static Optional<HederaKey> asHederaKey(final Key key) {
return Optional.empty();
}
return Optional.of(fcKey);
} catch (DecoderException ignore) {
} catch (InvalidKeyException ignore) {
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
return Optional.empty();
}
}
Expand All @@ -61,10 +61,11 @@ public static Optional<HederaKey> asHederaKey(@Nullable final com.hedera.hapi.no
return Optional.empty();
}
return Optional.of(fcKey);
} catch (DecoderException ignore) {
} catch (InvalidKeyException ignore) {
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
return Optional.empty();
}
}

/**
* Converts a set of {@link com.hedera.hapi.node.base.Key} to a set of {@link HederaKey}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import com.hederahashgraph.api.proto.java.TransactionBody;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.security.InvalidKeyException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.codec.DecoderException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -86,7 +86,7 @@ public FeeData usageGivenExplicit(
merkleTopic.hasAutoRenewAccountId(),
expiry,
txnBody.getConsensusUpdateTopic());
} catch (final DecoderException illegal) {
} catch (final InvalidKeyException illegal) {
log.warn("Usage estimation unexpectedly failed for {}!", txnBody, illegal);
throw new InvalidTxBodyException(illegal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.hederahashgraph.api.proto.java.Key;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.security.InvalidKeyException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
Expand All @@ -45,7 +46,6 @@
import java.util.function.UnaryOperator;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.codec.DecoderException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -183,7 +183,7 @@ public void rebuildAliasesMap(
numEOAliases.incrementAndGet();
}
} catch (final InvalidProtocolBufferException
| DecoderException
| InvalidKeyException
| IllegalArgumentException ignore) {
// any expected exception means no eth mapping
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public static byte[] keyAliasToEVMAddress(final ByteString alias) {
final Key key = Key.parseFrom(alias);
final JKey jKey = JKey.mapKey(key);
return tryAddressRecovery(jKey, ADDRESS_RECOVERY_FN);
} catch (InvalidProtocolBufferException | DecoderException | IllegalArgumentException ignore) {
} catch (InvalidProtocolBufferException | InvalidKeyException | IllegalArgumentException ignore) {
// any expected exception means no eth mapping
return null;
}
Expand All @@ -274,7 +274,7 @@ public static byte[] keyAliasToEVMAddress(@NonNull final Bytes alias) {
final Key key = Key.parseFrom(ret);
final JKey jKey = JKey.mapKey(key);
return tryAddressRecovery(jKey, ADDRESS_RECOVERY_FN);
} catch (InvalidProtocolBufferException | DecoderException | IllegalArgumentException ignore) {
} catch (InvalidProtocolBufferException | InvalidKeyException | IllegalArgumentException ignore) {
// any expected exception means no eth mapping
return null;
}
Expand Down
Loading