Search in sources :

Example 11 with UnencryptedEmailPacket

use of i2p.bote.packet.dht.UnencryptedEmailPacket in project i2p.i2p-bote by i2p.

the class EmailTest method testCreateEmailPackets.

@Test
public void testCreateEmailPackets() throws MessagingException, IOException, GeneralSecurityException, SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, PasswordException {
    // convert an email to a byte array, convert back, and compare with the original email
    for (Email email : emails) {
        EmailIdentity identity = identities.get(email);
        KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
        Collection<UnencryptedEmailPacket> packets = email.createEmailPackets(identity, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE);
        // the emails are somewhat compressible, but definitely not by 50%
        assertTrue("Expected more email packets. #packets = " + packets.size(), packets.size() > email.getText().length() / I2PBotePacket.MAX_DATAGRAM_SIZE / 2);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        for (UnencryptedEmailPacket packet : packets) outputStream.write(packet.getContent());
        Email newEmail = new Email(outputStream.toByteArray());
        assertEquals(email.getContent(), newEmail.getContent());
        // check packet sizes against size limit
        for (UnencryptedEmailPacket packet : packets) assertTrue("Email packet exceeds max size!", packet.toByteArray().length <= I2PBotePacket.MAX_DATAGRAM_SIZE);
    }
}
Also used : KeyUpdateHandler(i2p.bote.crypto.KeyUpdateHandler) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 12 with UnencryptedEmailPacket

use of i2p.bote.packet.dht.UnencryptedEmailPacket in project i2p.i2p-bote by i2p.

the class ResponsePacketTest method createDataPacket.

private DataPacket createDataPacket() throws GeneralSecurityException, IOException {
    byte[] dataToStore = new byte[] { 2, 109, -80, -37, -106, 83, -33, -39, -94, -76, -112, -98, 99, 25, -61, 44, -92, -85, 1, 10, -128, -2, -27, -86, -126, -33, -11, 42, 56, 3, -97, -101, 111, 7, -96, 25, 121, 74, 89, -40, -33, 82, -50, -18, 49, 106, 13, -121, 53, -83, -2, 35, -7, 71, -71, 26, 90, 1 };
    byte[] messageIdBytes = new byte[] { -69, -24, -109, 1, 69, -122, -69, 113, -68, -90, 55, -28, 105, 97, 125, 70, 51, 58, 14, 2, -13, -53, 90, -29, 36, 67, 36, -94, -108, -125, 11, 123 };
    UniqueId messageId = new UniqueId(messageIdBytes, 0);
    int fragmentIndex = 0;
    UnencryptedEmailPacket unencryptedPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(dataToStore), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket.setNumFragments(1);
    EmailDestination destination = new EmailDestination("0XuJjhgp58aOhvHHgpaxoQYsCUfDS6BECMEoVxFGEFPdk3y8lbzIsq9eUyeizFleMacYwoscCir8nQLlW34lxfRmirkNpD9vU1XnmjnZ5hGdnor1qIDqz3KJ040dVQ617MwyG97xxYLT0FsH907vBXgdc4RCHwKd1~9siagA5CSMaA~wM8ymKXLypiZGYexENLmim7nMzJTQYoOM~fVS99UaGJleDBN3pgZ2EvRYDQV2VqKH7Gee07R3y7b~c0tAKVHS0IbPQfTVJigrIHjTl~ZczxpaeTM04T8IgxKnO~lSmR1w7Ik8TpEkETwT9PDwUqQsjmlSY8E~WwwGMRJVyIRZUkHeRZ0aFq7us8W9EKzYtjjiU1z0QFpZrTfJE8oqCbnH5Lqv5Q86UdTPpriJC1N99E77TpCTnNzcBnpp6ko2JCy2IJUveaigKxS6EmS9KarkkkBRsckOKZZ6UNTOqPZsBCsx0Q9WvDF-Uc3dtouXWyenxRptaQsdkZyYlEQv");
    return new EncryptedEmailPacket(unencryptedPacket, destination);
}
Also used : UniqueId(i2p.bote.UniqueId) ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket)

Aggregations

UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)12 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 UniqueId (i2p.bote.UniqueId)5 KeyUpdateHandler (i2p.bote.crypto.KeyUpdateHandler)5 EmailDestination (i2p.bote.email.EmailDestination)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.junit.Test)4 File (java.io.File)3 Before (org.junit.Before)3 EmailIdentity (i2p.bote.email.EmailIdentity)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 GeneralSecurityException (java.security.GeneralSecurityException)2 MessagingException (javax.mail.MessagingException)2 Destination (net.i2p.data.Destination)2 Email (i2p.bote.email.Email)1 EmailMetadata (i2p.bote.email.EmailMetadata)1 EmailStatus (i2p.bote.folder.Outbox.EmailStatus)1 DhtException (i2p.bote.network.DhtException)1