@Override public CiphertextTuple doubleRatchetEncrypt(OmemoDevice recipient, byte[] messageKey) { CiphertextMessage ciphertextMessage; try { ciphertextMessage = getCipher(recipient).encrypt(messageKey); } catch (UntrustedIdentityException e) { throw new AssertionError("Signals trust management MUST be disabled."); } // TODO: Figure out, if this is enough... int type = (ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE ? OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE : OmemoElement.TYPE_OMEMO_MESSAGE); return new CiphertextTuple(ciphertextMessage.serialize(), type); }
@Test public void ciphertextTupleTest() { byte[] c = OmemoMessageBuilder.generateIv(); CiphertextTuple c1 = new CiphertextTuple(c, OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE); assertTrue(c1.isPreKeyMessage()); assertArrayEquals(c, c1.getCiphertext()); assertEquals(OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE, c1.getMessageType()); CiphertextTuple c2 = new CiphertextTuple(c, OmemoElement.TYPE_OMEMO_MESSAGE); assertFalse(c2.isPreKeyMessage()); assertEquals(OmemoElement.TYPE_OMEMO_MESSAGE, c2.getMessageType()); }
@Override public CiphertextTuple doubleRatchetEncrypt(OmemoDevice recipient, byte[] messageKey) { CiphertextMessage ciphertextMessage; try { ciphertextMessage = getCipher(recipient).encrypt(messageKey); } catch (UntrustedIdentityException e) { throw new AssertionError("Signals trust management MUST be disabled."); } // TODO: Figure out, if this is enough... int type = (ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE ? OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE : OmemoElement.TYPE_OMEMO_MESSAGE); return new CiphertextTuple(ciphertextMessage.serialize(), type); }