Search in sources :

Example 11 with OmemoCachedDeviceList

use of org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList in project Smack by igniterealtime.

the class OmemoStore method isAvailableDeviceId.

/**
 * Check, if our freshly generated deviceId is available (unique) in our deviceList.
 *
 * @param userDevice    our current device.
 * @param id            deviceId to check for.
 * @return true if list did not contain our id, else false
 *
 * @throws IOException if an I/O error occurred.
 */
boolean isAvailableDeviceId(OmemoDevice userDevice, int id) throws IOException {
    LOGGER.log(Level.INFO, "Check if id " + id + " is available...");
    // Lookup local cached device list
    BareJid ownJid = userDevice.getJid();
    OmemoCachedDeviceList cachedDeviceList;
    cachedDeviceList = loadCachedDeviceList(userDevice, ownJid);
    if (cachedDeviceList == null) {
        cachedDeviceList = new OmemoCachedDeviceList();
    }
    // Does the list already contain that id?
    return !cachedDeviceList.contains(id);
}
Also used : BareJid(org.jxmpp.jid.BareJid) OmemoCachedDeviceList(org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList)

Example 12 with OmemoCachedDeviceList

use of org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList in project Smack by igniterealtime.

the class DeviceListTest method mergeDeviceListsTest.

/**
 * Test, whether deviceList updates are correctly merged into the cached device list.
 * IDs in the update become active devices, active IDs that were not in the update become inactive.
 * Inactive IDs that were not in the update stay inactive.
 */
@Test
public void mergeDeviceListsTest() {
    OmemoCachedDeviceList cached = new OmemoCachedDeviceList();
    assertNotNull(cached.getActiveDevices());
    assertNotNull(cached.getInactiveDevices());
    cached.getInactiveDevices().add(1);
    cached.getInactiveDevices().add(2);
    cached.getActiveDevices().add(3);
    Set<Integer> update = new HashSet<>();
    update.add(4);
    update.add(1);
    cached.merge(update);
    assertTrue(cached.getActiveDevices().contains(1) && !cached.getActiveDevices().contains(2) && !cached.getActiveDevices().contains(3) && cached.getActiveDevices().contains(4));
    assertTrue(!cached.getInactiveDevices().contains(1) && cached.getInactiveDevices().contains(2) && cached.getInactiveDevices().contains(3) && !cached.getInactiveDevices().contains(4));
    assertTrue(cached.getAllDevices().size() == 4);
    assertFalse(cached.contains(17));
    cached.addDevice(17);
    assertTrue(cached.getActiveDevices().contains(17));
    assertNotNull(cached.toString());
}
Also used : OmemoCachedDeviceList(org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

OmemoCachedDeviceList (org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList)12 OmemoFingerprint (org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)6 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)4 StoreHint (org.jivesoftware.smackx.hints.element.StoreHint)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 XMPPException (org.jivesoftware.smack.XMPPException)2 PubSubException (org.jivesoftware.smackx.pubsub.PubSubException)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 WeakHashMap (java.util.WeakHashMap)1 SmackException (org.jivesoftware.smack.SmackException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 OmemoDeviceListElement (org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement)1 OmemoDeviceListElement_VAxolotl (org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement_VAxolotl)1 CannotEstablishOmemoSessionException (org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException)1