Skip to content

Commit

Permalink
refactor: use addSuppressed
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Jan 31, 2024
1 parent 7f6af85 commit bf784fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
14 changes: 1 addition & 13 deletions src/main/java/com/fingerprint/Sealed.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;

Expand Down Expand Up @@ -40,19 +38,9 @@ public String toString() {
}

public static class UnsealAggregateException extends Exception {
private final List<UnsealException> unsealExceptions = new ArrayList<>();

public UnsealAggregateException() {
super("Failed to unseal with all decryption keys");
}

public void addUnsealException(UnsealException exception) {
unsealExceptions.add(exception);
}

public List<UnsealException> getUnsealExceptions() {
return unsealExceptions;
}
}

public static class InvalidSealedDataException extends IllegalArgumentException {
Expand Down Expand Up @@ -102,7 +90,7 @@ public static byte[] unseal(byte[] sealed, DecryptionKey[] keys) throws IllegalA
try {
return decryptAes256Gcm(Arrays.copyOfRange(sealed, SEAL_HEADER.length, sealed.length), key.key);
} catch (Exception exception) {
aggregateException.addUnsealException(
aggregateException.addSuppressed(
new UnsealException(
"Failed to decrypt",
exception,
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/fingerprint/SealedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void unsealEventResponseWithNotCompressedSealedResultTest() throws Except
}
));

Sealed.UnsealException unsealException = exception.getUnsealExceptions().get(2);
Sealed.UnsealException unsealException = (Sealed.UnsealException) exception.getSuppressed()[2];

assertEquals(unsealException.getCause().getMessage(), "invalid distance too far back");
}
Expand Down Expand Up @@ -220,7 +220,7 @@ public void unsealEventResponseWithInvalidNonceTest() throws Exception {
}
));

Sealed.UnsealException unsealException = exception.getUnsealExceptions().get(2);
Sealed.UnsealException unsealException = (Sealed.UnsealException) exception.getSuppressed()[2];

assertEquals(unsealException.getCause().getMessage(), "12 > 3");
}
Expand Down

0 comments on commit bf784fe

Please sign in to comment.