Skip to content
This repository was archived by the owner on Jul 25, 2019. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Example {
final Scheme scheme = new Scheme(new SecureRandom(), 5, 3);
final byte[] secret = "hello there".getBytes(StandardCharsets.UTF_8);
final Map<Integer, byte[]> parts = scheme.split(secret);
final byte[] recovered = scheme.join(parts);
final byte[] recovered = Scheme.join(parts);
System.out.println(new String(recovered, StandardCharsets.UTF_8));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/codahale/shamir/Scheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Map<Integer, byte[]> split(byte[] secret) {
* @throws IllegalArgumentException if {@code parts} is empty or contains values of varying
* lengths
*/
public byte[] join(Map<Integer, byte[]> parts) {
public static byte[] join(Map<Integer, byte[]> parts) {
checkArgument(parts.size() > 0, "No parts provided");
final int[] lengths = parts.values().stream().mapToInt(v -> v.length).distinct().toArray();
checkArgument(lengths.length == 1, "Varying lengths of part values");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public Map<Integer, byte[]> split() {

@Benchmark
public byte[] join() {
return scheme.join(parts);
return Scheme.join(parts);
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/codahale/shamir/perf/LoadHarness.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void main(String[] args) {
final byte[] secret = new byte[10 * 1024];
final Scheme scheme = new Scheme(new SecureRandom(), 200, 20);
for (int i = 0; i < 100_000_000; i++) {
scheme.join(scheme.split(secret));
Scheme.join(scheme.split(secret));
}
}
}
11 changes: 5 additions & 6 deletions src/test/java/com/codahale/shamir/tests/SchemeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void thresholdTooHigh() {

@Test
void joinEmptyParts() {
assertThatThrownBy(() -> new Scheme(new SecureRandom(), 3, 2).join(Collections.emptyMap()))
assertThatThrownBy(() -> Scheme.join(Collections.emptyMap()))
.isInstanceOf(IllegalArgumentException.class);
}

Expand All @@ -71,8 +71,7 @@ void joinIrregularParts() {
final byte[] one = new byte[] {1};
final byte[] two = new byte[] {1, 2};

assertThatThrownBy(
() -> new Scheme(new SecureRandom(), 3, 2).join(ImmutableMap.of(1, one, 2, two)))
assertThatThrownBy(() -> Scheme.join(ImmutableMap.of(1, one, 2, two)))
.isInstanceOf(IllegalArgumentException.class);
}

Expand All @@ -81,15 +80,15 @@ void splitAndJoinSingleByteSecret() {
final Scheme scheme = new Scheme(new SecureRandom(), 8, 3);
final byte[] secret = "x".getBytes(StandardCharsets.UTF_8);

assertThat(scheme.join(scheme.split(secret))).containsExactly(secret);
assertThat(Scheme.join(scheme.split(secret))).containsExactly(secret);
}

@Test
void splitAndJoinMoreThanByteMaxValueParts() {
final Scheme scheme = new Scheme(new SecureRandom(), 200, 3);
final byte[] secret = "x".getBytes(StandardCharsets.UTF_8);

assertThat(scheme.join(scheme.split(secret))).containsExactly(secret);
assertThat(Scheme.join(scheme.split(secret))).containsExactly(secret);
}

@Test
Expand Down Expand Up @@ -129,6 +128,6 @@ void splitAndJoinInquorate() {
private byte[] join(Scheme scheme, Set<Map.Entry<Integer, byte[]>> entries) {
final Map<Integer, byte[]> m = new HashMap<>();
entries.forEach(v -> m.put(v.getKey(), v.getValue()));
return scheme.join(m);
return Scheme.join(m);
}
}