aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMoxie Marlinspike <moxie@thoughtcrime.org>2015-02-11 13:39:10 -0800
committerMoxie Marlinspike <moxie@thoughtcrime.org>2015-02-11 13:39:10 -0800
commit752f2dcf69eb1c47a58bfea3ee5afcca847ab692 (patch)
tree330d5693caf0bea99eeca39b33f2a61522c36815 /tests
parent81e91efb3a07bbacffd258c1fb19be12eea4f68b (diff)
Update GroupSessionBuilder and GroupSessionCipher interfaces.
Diffstat (limited to 'tests')
-rw-r--r--tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java44
-rw-r--r--tests/src/test/java/org/whispersystems/libaxolotl/groups/InMemorySenderKeyStore.java10
2 files changed, 20 insertions, 34 deletions
diff --git a/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java b/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java
index 7c9892b0..b41adb58 100644
--- a/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java
+++ b/tests/src/test/java/org/whispersystems/libaxolotl/groups/GroupCipherTest.java
@@ -6,9 +6,7 @@ import org.whispersystems.libaxolotl.DuplicateMessageException;
import org.whispersystems.libaxolotl.InvalidMessageException;
import org.whispersystems.libaxolotl.LegacyMessageException;
import org.whispersystems.libaxolotl.NoSessionException;
-import org.whispersystems.libaxolotl.ecc.ECKeyPair;
import org.whispersystems.libaxolotl.protocol.SenderKeyDistributionMessage;
-import org.whispersystems.libaxolotl.util.KeyHelper;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -25,18 +23,13 @@ public class GroupCipherTest extends TestCase {
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
- GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
- GroupCipher bobGroupCipher = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");
-
- byte[] aliceSenderKey = KeyHelper.generateSenderKey();
- ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
- int aliceSenderKeyId = KeyHelper.generateSenderKeyId();
+ GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, new SenderKeyName("cool group", 1111, 0));
+ GroupCipher bobGroupCipher = new GroupCipher(bobStore, new SenderKeyName("cool group", 1111, 0));
SenderKeyDistributionMessage aliceDistributionMessage =
- aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
- aliceSenderKey, aliceSenderSigningKey);
+ aliceSessionBuilder.create(new SenderKeyName("cool group", 1111, 0));
- bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);
+ bobSessionBuilder.process(new SenderKeyName("cool group", 1111, 0), aliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
byte[] plaintextFromAlice = bobGroupCipher.decrypt(ciphertextFromAlice);
@@ -53,18 +46,15 @@ public class GroupCipherTest extends TestCase {
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
- GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
- GroupCipher bobGroupCipher = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");
+ SenderKeyName aliceName = new SenderKeyName("cool group", 1111, 0);
- byte[] aliceSenderKey = KeyHelper.generateSenderKey();
- ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
- int aliceSenderKeyId = KeyHelper.generateSenderKeyId();
+ GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, aliceName);
+ GroupCipher bobGroupCipher = new GroupCipher(bobStore, aliceName);
SenderKeyDistributionMessage aliceDistributionMessage =
- aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
- aliceSenderKey, aliceSenderSigningKey);
+ aliceSessionBuilder.create(aliceName);
- bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);
+ bobSessionBuilder.process(aliceName, aliceDistributionMessage);
byte[] ciphertextFromAlice = aliceGroupCipher.encrypt("smert ze smert".getBytes());
byte[] ciphertextFromAlice2 = aliceGroupCipher.encrypt("smert ze smert2".getBytes());
@@ -96,19 +86,15 @@ public class GroupCipherTest extends TestCase {
GroupSessionBuilder aliceSessionBuilder = new GroupSessionBuilder(aliceStore);
GroupSessionBuilder bobSessionBuilder = new GroupSessionBuilder(bobStore);
- GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
- GroupCipher bobGroupCipher = new GroupCipher(bobStore, "groupWithBobInIt::aliceUserName");
+ SenderKeyName aliceName = new SenderKeyName("cool group", 1111, 0);
- byte[] aliceSenderKey = KeyHelper.generateSenderKey();
- ECKeyPair aliceSenderSigningKey = KeyHelper.generateSenderSigningKey();
- int aliceSenderKeyId = KeyHelper.generateSenderKeyId();
+ GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, aliceName);
+ GroupCipher bobGroupCipher = new GroupCipher(bobStore, aliceName);
SenderKeyDistributionMessage aliceDistributionMessage =
- aliceSessionBuilder.process("groupWithBobInIt", aliceSenderKeyId, 0,
- aliceSenderKey, aliceSenderSigningKey);
-
- bobSessionBuilder.process("groupWithBobInIt::aliceUserName", aliceDistributionMessage);
+ aliceSessionBuilder.create(aliceName);
+ bobSessionBuilder.process(aliceName, aliceDistributionMessage);
ArrayList<byte[]> ciphertexts = new ArrayList<>(100);
@@ -127,7 +113,7 @@ public class GroupCipherTest extends TestCase {
public void testEncryptNoSession() {
InMemorySenderKeyStore aliceStore = new InMemorySenderKeyStore();
- GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, "groupWithBobInIt");
+ GroupCipher aliceGroupCipher = new GroupCipher(aliceStore, new SenderKeyName("coolio groupio", 1111, 0));
try {
aliceGroupCipher.encrypt("up the punks".getBytes());
throw new AssertionError("Should have failed!");
diff --git a/tests/src/test/java/org/whispersystems/libaxolotl/groups/InMemorySenderKeyStore.java b/tests/src/test/java/org/whispersystems/libaxolotl/groups/InMemorySenderKeyStore.java
index c012566a..fe445398 100644
--- a/tests/src/test/java/org/whispersystems/libaxolotl/groups/InMemorySenderKeyStore.java
+++ b/tests/src/test/java/org/whispersystems/libaxolotl/groups/InMemorySenderKeyStore.java
@@ -9,17 +9,17 @@ import java.util.Map;
public class InMemorySenderKeyStore implements SenderKeyStore {
- private final Map<String, SenderKeyRecord> store = new HashMap<>();
+ private final Map<SenderKeyName, SenderKeyRecord> store = new HashMap<>();
@Override
- public void storeSenderKey(String senderKeyId, SenderKeyRecord record) {
- store.put(senderKeyId, record);
+ public void storeSenderKey(SenderKeyName senderKeyName, SenderKeyRecord record) {
+ store.put(senderKeyName, record);
}
@Override
- public SenderKeyRecord loadSenderKey(String senderKeyId) {
+ public SenderKeyRecord loadSenderKey(SenderKeyName senderKeyName) {
try {
- SenderKeyRecord record = store.get(senderKeyId);
+ SenderKeyRecord record = store.get(senderKeyName);
if (record == null) {
return new SenderKeyRecord();