@Test public void testWriteMultipart() throws Exception { final Path room = new Path("test", EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.triplecrypt)); final byte[] content = RandomUtils.nextBytes(32769); final TransferStatus status = new TransferStatus(); status.setLength(content.length); final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file, Path.Type.triplecrypt)); final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session).withCache(cache); final SDSEncryptionBulkFeature bulk = new SDSEncryptionBulkFeature(session, nodeid); bulk.pre(Transfer.Type.upload, Collections.singletonMap(new TransferItem(test), status), new DisabledConnectionCallback()); final TripleCryptWriteFeature writer = new TripleCryptWriteFeature(session, nodeid, new SDSMultipartWriteFeature(session, nodeid)); final StatusOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out); final VersionId version = out.getStatus(); assertNotNull(version); assertTrue(new DefaultFindFeature(session).find(test)); assertEquals(content.length, new SDSAttributesFinderFeature(session, nodeid).find(test).getSize()); final byte[] compare = new byte[content.length]; final InputStream stream = new TripleCryptReadFeature(session, nodeid, new SDSReadFeature(session, nodeid)).read(test, new TransferStatus(), new DisabledConnectionCallback() { @Override public void warn(final Host bookmark, final String title, final String message, final String defaultButton, final String cancelButton, final String preference) { } @Override public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) { return new VaultCredentials("eth[oh8uv4Eesij"); } }); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class); if(log.isDebugEnabled()) { log.debug(String.format("Read file key for file %s", file)); } if(null == status.getFilekey()) { status.setFilekey(nodeid.getFileKey()); } final FileKey fileKey = reader.readValue(status.getFilekey().array()); return new TripleCryptOutputStream<>(session, proxy.write(file, status, callback), Crypto.createFileEncryptionCipher(TripleCryptConverter.toCryptoPlainFileKey(fileKey)), status ); } catch(CryptoSystemException | InvalidFileKeyException e) { throw new TripleCryptExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } }
TripleCryptWriteFeature implements Write<VersionId> { @Override public StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class); if(log.isDebugEnabled()) { log.debug(String.format("Read file key for file %s", file)); } if(null == status.getFilekey()) { status.setFilekey(nodeid.getFileKey()); } final FileKey fileKey = reader.readValue(status.getFilekey().array()); return new TripleCryptOutputStream<>(session, proxy.write(file, status, callback), Crypto.createFileEncryptionCipher(TripleCryptConverter.toCryptoPlainFileKey(fileKey)), status ); } catch(CryptoSystemException | InvalidFileKeyException e) { throw new TripleCryptExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } }
TripleCryptWriteFeature implements Write<VersionId> { @Override public StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class); if(log.isDebugEnabled()) { log.debug(String.format("Read file key for file %s", file)); } if(null == status.getFilekey()) { status.setFilekey(nodeid.getFileKey()); } final FileKey fileKey = reader.readValue(status.getFilekey().array()); return new TripleCryptOutputStream<>(session, proxy.write(file, status, callback), Crypto.createFileEncryptionCipher(TripleCryptConverter.toCryptoPlainFileKey(fileKey)), status ); } catch(CryptoSystemException | InvalidFileKeyException e) { throw new TripleCryptExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } TripleCryptWriteFeature(final SDSSession session, final SDSNodeIdProvider nodeid, final Write<VersionId> proxy); }
TripleCryptWriteFeature implements Write<VersionId> { @Override public StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class); if(log.isDebugEnabled()) { log.debug(String.format("Read file key for file %s", file)); } if(null == status.getFilekey()) { status.setFilekey(nodeid.getFileKey()); } final FileKey fileKey = reader.readValue(status.getFilekey().array()); return new TripleCryptOutputStream<>(session, proxy.write(file, status, callback), Crypto.createFileEncryptionCipher(TripleCryptConverter.toCryptoPlainFileKey(fileKey)), status ); } catch(CryptoSystemException | InvalidFileKeyException e) { throw new TripleCryptExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } TripleCryptWriteFeature(final SDSSession session, final SDSNodeIdProvider nodeid, final Write<VersionId> proxy); @Override StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override Append append(final Path file, final Long length, final Cache<Path> cache); @Override boolean temporary(); @Override boolean random(); }
TripleCryptWriteFeature implements Write<VersionId> { @Override public StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class); if(log.isDebugEnabled()) { log.debug(String.format("Read file key for file %s", file)); } if(null == status.getFilekey()) { status.setFilekey(nodeid.getFileKey()); } final FileKey fileKey = reader.readValue(status.getFilekey().array()); return new TripleCryptOutputStream<>(session, proxy.write(file, status, callback), Crypto.createFileEncryptionCipher(TripleCryptConverter.toCryptoPlainFileKey(fileKey)), status ); } catch(CryptoSystemException | InvalidFileKeyException e) { throw new TripleCryptExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } TripleCryptWriteFeature(final SDSSession session, final SDSNodeIdProvider nodeid, final Write<VersionId> proxy); @Override StatusOutputStream<VersionId> write(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override Append append(final Path file, final Long length, final Cache<Path> cache); @Override boolean temporary(); @Override boolean random();  }