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);
}
}
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);
}
Aggregations