public void put(Collection<EncryptedEmailPacket> emailPackets) { for (EncryptedEmailPacket emailPacket: emailPackets) { Hash emailPacketKey = emailPacket.getDhtKey(); Hash delVerificationHash = emailPacket.getDeleteVerificationHash(); IndexPacketEntry entry = new IndexPacketEntry(emailPacketKey, delVerificationHash); put(entry); } }
@Override public String toString() { return super.toString() + " #entries=" + getNumEntries(); } }
/** * Tests if the <code>DeletionInfoPacket</code> contains a given DHT key. * @param dhtKey * @return <code>true</code> if the packet containes the DHT key, <code>false</code> otherwise. */ public boolean contains(Hash dhtKey) { return getEntry(dhtKey) != null; }
@Test public void testRemoveKey() { assertEquals(3, indexPacket1.getNumEntries()); // Try to remove a key that doesn't exist in the packet indexPacket1.remove(emailPacket4.getDhtKey()); assertEquals(3, indexPacket1.getNumEntries()); // Remove a key that does exist in the packet indexPacket1.remove(emailPacket1.getDhtKey()); assertEquals(2, indexPacket1.getNumEntries()); } }
@Test public void testGetPacketToStore() throws Exception { byte[] arrayA = dhtPacket.toByteArray(); byte[] arrayB = storeRequest.getPacketToStore().toByteArray(); assertArrayEquals("The two arrays differ!", arrayA, arrayB); } }
@Override public DeleteRequest getIndividualRequest(Hash dhtKey) { UniqueId delAuthorization = entries.get(dhtKey); if (delAuthorization == null) return null; IndexPacketDeleteRequest indivRequest = new IndexPacketDeleteRequest(emailDestHash); indivRequest.put(dhtKey, delAuthorization); return indivRequest; }
@Test public void testToByteArrayAndBack() throws GeneralSecurityException { IndexPacket newPacket1 = new IndexPacket(indexPacket1.toByteArray()); assertTrue("The two packets differ!", equal(indexPacket1, newPacket1)); IndexPacket newPacket2 = new IndexPacket(indexPacket2.toByteArray()); assertTrue("The two packets differ!", equal(indexPacket2, newPacket2)); }
/** * Adds an entry to the <code>DeletionInfoPacket</code>. If an entry with the same DHT key * exists in the packet already, nothing happens. * @param dhtKey * @param delAuthorization */ public void put(Hash dhtKey, UniqueId delAuthorization) { if (contains(dhtKey)) return; DeletionRecord entry = new DeletionRecord(dhtKey, delAuthorization); entries.add(entry); }
/** * Adds an entry to the <code>IndexPacket</code>. If an entry with the same DHT key * exists in the packet already, nothing happens. * @param entry */ public void put(IndexPacketEntry entry) { if (contains(entry.emailPacketKey)) return; entries.add(entry); }
@Override protected UnencryptedEmailPacket createFolderElement(File file) throws IOException { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); return new UnencryptedEmailPacket(inputStream); } finally { if (inputStream != null) inputStream.close(); } }
@Override public void setStoreTime(long time) { super.setStoreTime(storeTime); }
/** * Returns <code>true</code> if the DHT key stored in the packet matches * the computed (from the encrypted data) DHT key. * @see #getDhtKey() */ public boolean verifyPacketHash() { return getDhtKey().equals(dhtKey); }
/** * Tests if the <code>IndexPacket</code> contains a given DHT key. * @param emailPacketKey * @return <code>true</code> if the packet containes the DHT key, <code>false</code> otherwise. */ public boolean contains(Hash emailPacketKey) { return getEntry(emailPacketKey) != null; }
public Contact(String name, EmailDestination destination, String pictureBase64, String text) { this.name = name; this.destination = destination; setPictureBase64(pictureBase64); this.text = text; }
/** * Sets the number of packets the email was fragmented into. * @param numFragments */ public void setNumFragments(int numFragments) { this.numFragments = numFragments; verify(); }
@Override public Hash getDhtKey() { return getNameHash(); }
public Hash getKey() { return packetToStore.getDhtKey(); }
/** * Adds a new entry containing the DHT key and Delete Verification Hash of an Email Packet.<br/> * If an entry with the same DHT key exists already, nothing happens. * @param emailPacket */ public void put(EncryptedEmailPacket emailPacket) { Hash emailPacketKey = emailPacket.getDhtKey(); Hash delVerificationHash = emailPacket.getDeleteVerificationHash(); IndexPacketEntry newEntry = new IndexPacketEntry(emailPacketKey, delVerificationHash); put(newEntry); }
/** * Returns the delete verification hash for an email packet DHT key, * or <code>null</code> if the index packet doesn't contain the DHT key. * @param emailPacketKey */ public Hash getDeleteVerificationHash(Hash emailPacketKey) { IndexPacketEntry entry = getEntry(emailPacketKey); if (entry == null) return null; else return entry.delVerificationHash; }
/** * Removes an entry from the <code>IndexPacket</code> if it exists. * @param emailPacketKey */ public void remove(Hash emailPacketKey) { IndexPacketEntry entry = getEntry(emailPacketKey); if (entry != null) entries.remove(entry); }