Skip to content

Commit

Permalink
chore: implement PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Jan 30, 2024
1 parent 6ba59d2 commit 7f6af85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 24 additions & 8 deletions src/main/java/com/fingerprint/Sealed.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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 All @@ -28,6 +29,14 @@ public DecryptionKey(byte[] key, DecryptionAlgorithm algorithm) {
this.key = key;
this.algorithm = algorithm;
}

@Override
public String toString() {
return "DecryptionKey{" +
"key=" + Base64.getEncoder().encodeToString(key) +
", algorithm=" + algorithm +
'}';
}
}

public static class UnsealAggregateException extends Exception {
Expand Down Expand Up @@ -59,16 +68,23 @@ public InvalidSealedDataHeaderException() {
}

public static class UnsealException extends Exception {
public final DecryptionKey decryptionKey;
public final String decryptionKeyDescription;

public final Exception exception;
public UnsealException(String message, Throwable cause, DecryptionKey decryptionKey) {
super(message, cause);
this.decryptionKeyDescription = decryptionKey.toString();
}

public UnsealException(String message, DecryptionKey decryptionKey, Exception exception) {
super(message);
this.decryptionKey = decryptionKey;
this.exception = exception;
@Override
public String toString() {
return "UnsealException{" +
"decryptionKey=" + decryptionKeyDescription +
", message=" + getMessage() +
", cause=" + getCause() +
'}';
}
}

private static final byte[] SEAL_HEADER = new byte[]{(byte) 0x9E, (byte) 0x85, (byte) 0xDC, (byte) 0xED};
private static final int NONCE_LENGTH = 12;
private static final int AUTH_TAG_LENGTH = 16;
Expand All @@ -89,8 +105,8 @@ public static byte[] unseal(byte[] sealed, DecryptionKey[] keys) throws IllegalA
aggregateException.addUnsealException(
new UnsealException(
"Failed to decrypt",
key,
exception
exception,
key
)
);
}
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 @@ -116,7 +116,7 @@ public void unsealEventResponseWithNotCompressedSealedResultTest() throws Except

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

assertEquals(unsealException.exception.getMessage(), "invalid distance too far back");
assertEquals(unsealException.getCause().getMessage(), "invalid distance too far back");
}

@Test
Expand Down Expand Up @@ -222,6 +222,6 @@ public void unsealEventResponseWithInvalidNonceTest() throws Exception {

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

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

0 comments on commit 7f6af85

Please sign in to comment.