mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-12 02:01:46 +00:00
Javadocs, and some minor refactoring.
This commit is contained in:
@@ -16,7 +16,7 @@ public class InMemorySessionStore implements SessionStore {
|
||||
public InMemorySessionStore() {}
|
||||
|
||||
@Override
|
||||
public synchronized SessionRecord get(long recipientId, int deviceId) {
|
||||
public synchronized SessionRecord load(long recipientId, int deviceId) {
|
||||
if (contains(recipientId, deviceId)) {
|
||||
return new InMemorySessionRecord(sessions.get(new Pair<>(recipientId, deviceId)));
|
||||
} else {
|
||||
@@ -38,7 +38,7 @@ public class InMemorySessionStore implements SessionStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void put(long recipientId, int deviceId, SessionRecord record) {
|
||||
public synchronized void store(long recipientId, int deviceId, SessionRecord record) {
|
||||
sessions.put(new Pair<>(recipientId, deviceId), record);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.whispersystems.test;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import org.whispersystems.libaxolotl.DuplicateMessageException;
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
@@ -57,7 +56,7 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
aliceSessionBuilder.process(bobPreKey);
|
||||
|
||||
assertTrue(aliceSessionStore.contains(BOB_RECIPIENT_ID, 1));
|
||||
assertTrue(!aliceSessionStore.get(BOB_RECIPIENT_ID, 1).getSessionState().getNeedsRefresh());
|
||||
assertTrue(!aliceSessionStore.load(BOB_RECIPIENT_ID, 1).getSessionState().getNeedsRefresh());
|
||||
|
||||
String originalMessage = "L'homme est condamné à être libre";
|
||||
SessionCipher aliceSessionCipher = new SessionCipher(aliceSessionStore, BOB_RECIPIENT_ID, 1);
|
||||
@@ -95,15 +94,11 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
KeyExchangeMessage aliceKeyExchangeMessage = aliceSessionBuilder.process();
|
||||
KeyExchangeMessage bobKeyExchangeMessage = bobSessionBuilder.process(aliceKeyExchangeMessage);
|
||||
|
||||
Log.w("SessionBuilderTest", "Record from test: " + bobSessionStore.get(ALICE_RECIPIENT_ID, 1));
|
||||
|
||||
assertTrue(bobKeyExchangeMessage != null);
|
||||
assertTrue(aliceKeyExchangeMessage != null);
|
||||
|
||||
KeyExchangeMessage response = aliceSessionBuilder.process(bobKeyExchangeMessage);
|
||||
|
||||
Log.w("SessionBuilderTest", "Record from test 2: " + bobSessionStore.get(ALICE_RECIPIENT_ID, 1));
|
||||
|
||||
assertTrue(response == null);
|
||||
assertTrue(aliceSessionStore.contains(BOB_RECIPIENT_ID, 1));
|
||||
assertTrue(bobSessionStore.contains(ALICE_RECIPIENT_ID, 1));
|
||||
@@ -171,7 +166,9 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
assertTrue(new String(plaintext).equals(originalMessage));
|
||||
|
||||
for (int i=0;i<10;i++) {
|
||||
String loopingMessage = ("You can only desire based on what you know: " + i);
|
||||
String loopingMessage = ("What do we mean by saying that existence precedes essence? " +
|
||||
"We mean that man first of all exists, encounters himself, " +
|
||||
"surges up in the world--and defines himself aftward. " + i);
|
||||
CiphertextMessage aliceLoopingMessage = aliceSessionCipher.encrypt(loopingMessage.getBytes());
|
||||
|
||||
byte[] loopingPlaintext = bobSessionCipher.decrypt(aliceLoopingMessage.serialize());
|
||||
@@ -179,7 +176,9 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
for (int i=0;i<10;i++) {
|
||||
String loopingMessage = ("You can only desire based on what you know: " + i);
|
||||
String loopingMessage = ("What do we mean by saying that existence precedes essence? " +
|
||||
"We mean that man first of all exists, encounters himself, " +
|
||||
"surges up in the world--and defines himself aftward. " + i);
|
||||
CiphertextMessage bobLoopingMessage = bobSessionCipher.encrypt(loopingMessage.getBytes());
|
||||
|
||||
byte[] loopingPlaintext = aliceSessionCipher.decrypt(bobLoopingMessage.serialize());
|
||||
@@ -189,14 +188,18 @@ public class SessionBuilderTest extends AndroidTestCase {
|
||||
Set<Pair<String, CiphertextMessage>> aliceOutOfOrderMessages = new HashSet<>();
|
||||
|
||||
for (int i=0;i<10;i++) {
|
||||
String loopingMessage = ("You can only desire based on what you know: " + i);
|
||||
String loopingMessage = ("What do we mean by saying that existence precedes essence? " +
|
||||
"We mean that man first of all exists, encounters himself, " +
|
||||
"surges up in the world--and defines himself aftward. " + i);
|
||||
CiphertextMessage aliceLoopingMessage = aliceSessionCipher.encrypt(loopingMessage.getBytes());
|
||||
|
||||
aliceOutOfOrderMessages.add(new Pair<>(loopingMessage, aliceLoopingMessage));
|
||||
}
|
||||
|
||||
for (int i=0;i<10;i++) {
|
||||
String loopingMessage = ("You can only desire based on what you know: " + i);
|
||||
String loopingMessage = ("What do we mean by saying that existence precedes essence? " +
|
||||
"We mean that man first of all exists, encounters himself, " +
|
||||
"surges up in the world--and defines himself aftward. " + i);
|
||||
CiphertextMessage aliceLoopingMessage = aliceSessionCipher.encrypt(loopingMessage.getBytes());
|
||||
|
||||
byte[] loopingPlaintext = bobSessionCipher.decrypt(aliceLoopingMessage.serialize());
|
||||
|
||||
@@ -33,8 +33,8 @@ public class SessionCipherTest extends AndroidTestCase {
|
||||
SessionStore aliceSessionStore = new InMemorySessionStore();
|
||||
SessionStore bobSessionStore = new InMemorySessionStore();
|
||||
|
||||
aliceSessionStore.put(2L, 1, aliceSessionRecord);
|
||||
bobSessionStore.put(3L, 1, bobSessionRecord);
|
||||
aliceSessionStore.store(2L, 1, aliceSessionRecord);
|
||||
bobSessionStore.store(3L, 1, bobSessionRecord);
|
||||
|
||||
SessionCipher aliceCipher = new SessionCipher(aliceSessionStore, 2L, 1);
|
||||
SessionCipher bobCipher = new SessionCipher(bobSessionStore, 3L, 1);
|
||||
|
||||
Reference in New Issue
Block a user