Skip to content

Commit 1d9f7c3

Browse files
committed
#79 Add null checks and small improvements
1 parent 5a2bee2 commit 1d9f7c3

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/main/java/org/unicitylabs/sdk/api/InclusionCertificate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ private InclusionCertificate(byte[] bitmap, List<DataHash> siblings) {
2828

2929
public static InclusionCertificate create(SparseMerkleTreeRootNode root, byte[] key) {
3030
Objects.requireNonNull(root, "root cannot be null");
31+
Objects.requireNonNull(key, "key cannot be null");
32+
if (key.length != 32) {
33+
throw new IllegalArgumentException("Key must be 32 bytes long.");
34+
}
3135

3236
ArrayList<DataHash> siblings = new ArrayList<>();
3337
byte[] bitmap = new byte[InclusionCertificate.BITMAP_SIZE];

src/main/java/org/unicitylabs/sdk/smt/SparseMerkleTreePathUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ public static int getBitAtDepth(byte[] data, int depth) {
9090
}
9191
int byteIndex = depth / 8;
9292
int bitInByte = depth % 8;
93-
return (data[byteIndex] >> (7 - bitInByte)) & 1;
93+
return ((data[byteIndex] & 0xff) >> (7 - bitInByte)) & 1;
9494
}
9595
}

0 commit comments

Comments
 (0)