summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-06-04 19:49:05 +0200
committerSven Gothel <[email protected]>2022-06-04 19:49:05 +0200
commit464250eca2c563175030fe6ea80315527cd9cd22 (patch)
tree9d68aab3ec4ec097bad386f3ec37132efbf610df
parentc004c2900b987f956a4448feb8e19aad039875b9 (diff)
Completion of Java Test01Cipherpack, covering all tests of native test_01_cipherpack, all tests passed
-rw-r--r--test/cipherpack/test_01_cipherpack.cpp29
-rw-r--r--test/java/test/org/cipherpack/Test01Cipherpack.java291
2 files changed, 259 insertions, 61 deletions
diff --git a/test/cipherpack/test_01_cipherpack.cpp b/test/cipherpack/test_01_cipherpack.cpp
index b59d2ec..b1fe1fd 100644
--- a/test/cipherpack/test_01_cipherpack.cpp
+++ b/test/cipherpack/test_01_cipherpack.cpp
@@ -363,7 +363,7 @@ class Test01Cipherpack : public TestData {
jau::sleep_for( 16_ms );
}
}
- // probably set after decryption due to above sleep, which also ends when total size has been reached.
+ // probably set after transfering due to above sleep, which also ends when total size has been reached.
enc_feed->set_eof( jau::io::async_io_result_t::SUCCESS );
}
@@ -385,7 +385,7 @@ class Test01Cipherpack : public TestData {
}
}
// probably set after transfering due to above sleep, which also ends when total size has been reached.
- enc_feed->set_eof( jau::io::async_io_result_t::SUCCESS );
+ enc_feed->set_eof( xfer_total == file_size ? jau::io::async_io_result_t::SUCCESS : jau::io::async_io_result_t::FAILED );
}
// full speed, with content size
@@ -400,7 +400,6 @@ class Test01Cipherpack : public TestData {
uint8_t buffer[1024]; // 1k
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
- // jau::sleep_for( 100_ms );
xfer_total += count;
enc_feed->write(buffer, count);
}
@@ -409,47 +408,43 @@ class Test01Cipherpack : public TestData {
}
// full speed, no content size, interrupting @ 1024 bytes within our header
- static void feed_source_20(jau::io::ByteInStream_Feed * data_feed) {
+ static void feed_source_20(jau::io::ByteInStream_Feed * enc_feed) {
uint64_t xfer_total = 0;
- jau::io::ByteInStream_File enc_stream(data_feed->id(), true /* use_binary */);
+ jau::io::ByteInStream_File enc_stream(enc_feed->id(), true /* use_binary */);
while( !enc_stream.end_of_data() ) {
uint8_t buffer[1024]; // 1k
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- data_feed->write(buffer, count);
+ enc_feed->write(buffer, count);
if( xfer_total >= 1024 ) {
- data_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
+ enc_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
return;
}
}
}
- // probably set after transfering due to above sleep, which also ends when total size has been reached.
- data_feed->set_eof( jau::io::async_io_result_t::SUCCESS );
}
// full speed, with content size, interrupting 1/4 way
- static void feed_source_21(jau::io::ByteInStream_Feed * data_feed) {
- jau::fs::file_stats fs_feed(data_feed->id());
+ static void feed_source_21(jau::io::ByteInStream_Feed * enc_feed) {
+ jau::fs::file_stats fs_feed(enc_feed->id());
const uint64_t file_size = fs_feed.size();
- data_feed->set_content_size( file_size );
+ enc_feed->set_content_size( file_size );
uint64_t xfer_total = 0;
- jau::io::ByteInStream_File enc_stream(data_feed->id(), true /* use_binary */);
+ jau::io::ByteInStream_File enc_stream(enc_feed->id(), true /* use_binary */);
while( !enc_stream.end_of_data() ) {
uint8_t buffer[1024]; // 1k
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- data_feed->write(buffer, count);
+ enc_feed->write(buffer, count);
if( xfer_total >= file_size/4 ) {
- data_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
+ enc_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
return;
}
}
}
- // probably set after transfering due to above sleep, which also ends when total size has been reached.
- data_feed->set_eof( jau::io::async_io_result_t::SUCCESS );
}
void test21_enc_dec_fed_ok() {
diff --git a/test/java/test/org/cipherpack/Test01Cipherpack.java b/test/java/test/org/cipherpack/Test01Cipherpack.java
index 1bd5a61..c4f8495 100644
--- a/test/java/test/org/cipherpack/Test01Cipherpack.java
+++ b/test/java/test/org/cipherpack/Test01Cipherpack.java
@@ -429,75 +429,278 @@ public class Test01Cipherpack extends data_test {
if( 0 < count ) {
xfer_total += count;
enc_feed.write(buffer, 0, count);
- try {
- Thread.sleep( 16 ); // 16 ms
- } catch(final Throwable t) {}
+ try { Thread.sleep( 16 ); } catch(final Throwable t) {}
}
}
} catch (final Exception ex) {
CPUtils.println(System.err, "feed_source_00: "+ex.getMessage());
ex.printStackTrace();
} finally {
- try {
- if( null != in ) {
- in.close();
+ try { if( null != in ) { in.close(); } } catch (final IOException e) { e.printStackTrace(); }
+ }
+ // probably set after transfering due to above sleep, which also ends when total size has been reached.
+ enc_feed.set_eof( 1 /* SUCCESS */ );
+ }
+
+ // throttled, with content size
+ static void feed_source_01(final ByteInStream_Feed enc_feed) {
+ long xfer_total = 0;
+ final File enc_stream = new File(enc_feed.id());
+ Assert.assertTrue( enc_stream.exists() );
+ final long file_size = enc_stream.length();
+ enc_feed.set_content_size( file_size );
+
+ InputStream in = null;
+ try {
+ in = new FileInputStream(enc_stream);
+ while( xfer_total < file_size && in.available() > 0 ) {
+ final byte[] buffer = new byte[1024]; // 1k
+ final int count = in.read(buffer);
+ if( 0 < count ) {
+ xfer_total += count;
+ enc_feed.write(buffer, 0, count);
+ try { Thread.sleep( 16 ); } catch(final Throwable t) {}
+ }
+ }
+ } catch (final Exception ex) {
+ CPUtils.println(System.err, "feed_source_01: "+ex.getMessage());
+ ex.printStackTrace();
+ } finally {
+ try { if( null != in ) { in.close(); } } catch (final IOException e) { e.printStackTrace(); }
+ }
+ // probably set after transfering due to above sleep, which also ends when total size has been reached.
+ enc_feed.set_eof( xfer_total == file_size ? 1 /* SUCCESS */ : -1 /* FAILED */);
+ }
+
+ // full speed, with content size
+ static void feed_source_10(final ByteInStream_Feed enc_feed) {
+ long xfer_total = 0;
+ final File enc_stream = new File(enc_feed.id());
+ Assert.assertTrue( enc_stream.exists() );
+ final long file_size = enc_stream.length();
+ enc_feed.set_content_size( file_size );
+
+ InputStream in = null;
+ try {
+ in = new FileInputStream(enc_stream);
+ while( xfer_total < file_size && in.available() > 0 ) {
+ final byte[] buffer = new byte[1024]; // 1k
+ final int count = in.read(buffer);
+ if( 0 < count ) {
+ xfer_total += count;
+ enc_feed.write(buffer, 0, count);
}
- } catch (final IOException e) {
- e.printStackTrace();
}
+ } catch (final Exception ex) {
+ CPUtils.println(System.err, "feed_source_10: "+ex.getMessage());
+ ex.printStackTrace();
+ } finally {
+ try { if( null != in ) { in.close(); } } catch (final IOException e) { e.printStackTrace(); }
+ }
+ // probably set after transfering due to above sleep, which also ends when total size has been reached.
+ enc_feed.set_eof( xfer_total == file_size ? 1 /* SUCCESS */ : -1 /* FAILED */);
+ }
+
+ // full speed, no content size, interrupting @ 1024 bytes within our header
+ static void feed_source_20(final ByteInStream_Feed enc_feed) {
+ long xfer_total = 0;
+ final File enc_stream = new File(enc_feed.id());
+ Assert.assertTrue( enc_stream.exists() );
+ final long file_size = enc_stream.length();
+ enc_feed.set_content_size( file_size );
+
+ InputStream in = null;
+ try {
+ in = new FileInputStream(enc_stream);
+ while( xfer_total < file_size && in.available() > 0 ) {
+ final byte[] buffer = new byte[1024]; // 1k
+ final int count = in.read(buffer);
+ if( 0 < count ) {
+ xfer_total += count;
+ enc_feed.write(buffer, 0, count);
+ if( xfer_total >= 1024 ) {
+ enc_feed.set_eof( -1 /* FAILED */ ); // calls data_feed->interruptReader();
+ return;
+ }
+ }
+ }
+ } catch (final Exception ex) {
+ CPUtils.println(System.err, "feed_source_20: "+ex.getMessage());
+ ex.printStackTrace();
+ } finally {
+ try { if( null != in ) { in.close(); } } catch (final IOException e) { e.printStackTrace(); }
+ }
+ }
+
+ // full speed, with content size, interrupting 1/4 way
+ static void feed_source_21(final ByteInStream_Feed enc_feed) {
+ long xfer_total = 0;
+ final File enc_stream = new File(enc_feed.id());
+ Assert.assertTrue( enc_stream.exists() );
+ final long file_size = enc_stream.length();
+ enc_feed.set_content_size( file_size );
+
+ InputStream in = null;
+ try {
+ in = new FileInputStream(enc_stream);
+ while( xfer_total < file_size && in.available() > 0 ) {
+ final byte[] buffer = new byte[1024]; // 1k
+ final int count = in.read(buffer);
+ if( 0 < count ) {
+ xfer_total += count;
+ enc_feed.write(buffer, 0, count);
+ if( xfer_total >= file_size/4 ) {
+ enc_feed.set_eof( -1 /* FAILED */ ); // calls data_feed->interruptReader();
+ return;
+ }
+ }
+ }
+ } catch (final Exception ex) {
+ CPUtils.println(System.err, "feed_source_21: "+ex.getMessage());
+ ex.printStackTrace();
+ } finally {
+ try { if( null != in ) { in.close(); } } catch (final IOException e) { e.printStackTrace(); }
}
- // probably set after decryption due to above sleep, which also ends when total size has been reached.
- enc_feed.set_eof( 1 /* SUCCESS */ );
}
@Test(timeout = 10000)
public final void test21_enc_dec_fed_ok() {
CPFactory.checkInitialized();
-
- final int file_idx = IDX_11kiB;
final List<String> enc_pub_keys = Arrays.asList(enc_pub_key1_fname, enc_pub_key2_fname, enc_pub_key3_fname);
- final String source_loc = fname_payload_lst.get(file_idx);
- final PackHeader ph1 = Cipherpack.encryptThenSign(CryptoConfig.getDefault(),
- enc_pub_keys,
- sign_sec_key1_fname, sign_sec_key_passphrase,
- source_loc, io_timeout,
- fname_payload_lst.get(file_idx), "test_case", payload_version, payload_version_parent,
- silentListener, fname_payload_encrypted_lst.get(file_idx));
- CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Encrypted %s to %s\n", fname_payload_lst.get(file_idx), fname_payload_encrypted_lst.get(file_idx));
- CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph1.toString(true, true));
- Assert.assertTrue( ph1.isValid() );
+ final List<String> sign_pub_keys = Arrays.asList(sign_pub_key1_fname, sign_pub_key2_fname, sign_pub_key3_fname);
+ {
+ final int file_idx = IDX_11kiB;
+ final String source_loc = fname_payload_lst.get(file_idx);
+ final PackHeader ph1 = Cipherpack.encryptThenSign(CryptoConfig.getDefault(),
+ enc_pub_keys,
+ sign_sec_key1_fname, sign_sec_key_passphrase,
+ source_loc, io_timeout,
+ fname_payload_lst.get(file_idx), "test_case", payload_version, payload_version_parent,
+ silentListener, fname_payload_encrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Encrypted %s to %s\n", fname_payload_lst.get(file_idx), fname_payload_encrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph1.toString(true, true));
+ Assert.assertTrue( ph1.isValid() );
- final String uri_encrypted = url_input_root + fname_payload_encrypted_lst.get(file_idx);
- final String file_decrypted = fname_payload_encrypted_lst.get(file_idx)+".dec";
+ final String file_decrypted = fname_payload_encrypted_lst.get(file_idx)+".dec";
+ {
+ // throttled, no content size, interruptReader() via set_eof() will avoid timeout
+ final ByteInStream_Feed enc_feed = new ByteInStream_Feed(fname_payload_encrypted_lst.get(file_idx), io_timeout);
+ final Thread feeder_thread = executeOffThread( () -> { feed_source_00(enc_feed); }, "test21_enc_dec_fed_ok::feed_source_00", false /* detach */);
- final List<String> sign_pub_keys = Arrays.asList(sign_pub_key1_fname, sign_pub_key2_fname, sign_pub_key3_fname);
+ final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
+ enc_feed,
+ silentListener, file_decrypted);
+ try {
+ feeder_thread.join(1000);
+ } catch (final InterruptedException e) { }
- {
- final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
- uri_encrypted, io_timeout,
- silentListener, file_decrypted);
- CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
- CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
- Assert.assertTrue( ph2.isValid() );
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
+ Assert.assertTrue( ph2.isValid() );
+ }
+ {
+ // throttled, with content size
+ final ByteInStream_Feed enc_feed = new ByteInStream_Feed(fname_payload_encrypted_lst.get(file_idx), io_timeout);
+ final Thread feeder_thread = executeOffThread( () -> { feed_source_01(enc_feed); }, "test21_enc_dec_fed_ok::feed_source_01", false /* detach */);
+
+ final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
+ enc_feed,
+ silentListener, file_decrypted);
+ try {
+ feeder_thread.join(1000);
+ } catch (final InterruptedException e) { }
+
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
+ Assert.assertTrue( ph2.isValid() );
+ }
}
{
- // throttled, no content size, interruptReader() via set_eof() will avoid timeout
- final ByteInStream_Feed enc_feed = new ByteInStream_Feed(fname_payload_encrypted_lst.get(file_idx), io_timeout);
- final Thread feeder_thread = executeOffThread( () -> { feed_source_00(enc_feed); }, "test21_enc_dec_fed_ok::feed_source_00", false /* detach */);
+ final int file_idx = IDX_65MiB;
+ final String source_loc = fname_payload_lst.get(file_idx);
+ final PackHeader ph1 = Cipherpack.encryptThenSign(CryptoConfig.getDefault(),
+ enc_pub_keys,
+ sign_sec_key1_fname, sign_sec_key_passphrase,
+ source_loc, io_timeout,
+ fname_payload_lst.get(file_idx), "test_case", payload_version, payload_version_parent,
+ silentListener, fname_payload_encrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Encrypted %s to %s\n", fname_payload_lst.get(file_idx), fname_payload_encrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph1.toString(true, true));
+ Assert.assertTrue( ph1.isValid() );
- final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
- enc_feed,
- silentListener, file_decrypted);
- try {
- feeder_thread.join(1000);
- } catch (final InterruptedException e) { }
+ final String file_decrypted = fname_payload_encrypted_lst.get(file_idx)+".dec";
+ {
+ // full speed, with content size
+ final ByteInStream_Feed enc_feed = new ByteInStream_Feed(fname_payload_encrypted_lst.get(file_idx), io_timeout);
+ final Thread feeder_thread = executeOffThread( () -> { feed_source_10(enc_feed); }, "test21_enc_dec_fed_ok::feed_source_10", false /* detach */);
- CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
- CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
- Assert.assertTrue( ph2.isValid() );
+ final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
+ enc_feed,
+ silentListener, file_decrypted);
+ try {
+ feeder_thread.join(1000);
+ } catch (final InterruptedException e) { }
+
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
+ Assert.assertTrue( ph2.isValid() );
+ }
}
}
+ @Test(timeout = 10000)
+ public final void test22_enc_dec_fed_irq() {
+ CPFactory.checkInitialized();
+ final List<String> enc_pub_keys = Arrays.asList(enc_pub_key1_fname, enc_pub_key2_fname, enc_pub_key3_fname);
+ final List<String> sign_pub_keys = Arrays.asList(sign_pub_key1_fname, sign_pub_key2_fname, sign_pub_key3_fname);
+ {
+ final int file_idx = IDX_65MiB;
+ final String source_loc = fname_payload_lst.get(file_idx);
+ final PackHeader ph1 = Cipherpack.encryptThenSign(CryptoConfig.getDefault(),
+ enc_pub_keys,
+ sign_sec_key1_fname, sign_sec_key_passphrase,
+ source_loc, io_timeout,
+ fname_payload_lst.get(file_idx), "test_case", payload_version, payload_version_parent,
+ silentListener, fname_payload_encrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Encrypted %s to %s\n", fname_payload_lst.get(file_idx), fname_payload_encrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph1.toString(true, true));
+ Assert.assertTrue( ph1.isValid() );
+
+ final String file_decrypted = fname_payload_encrypted_lst.get(file_idx)+".dec";
+ {
+ // full speed, no content size, interrupting @ 1024 bytes within our header
+ final ByteInStream_Feed enc_feed = new ByteInStream_Feed(fname_payload_encrypted_lst.get(file_idx), io_timeout);
+ final Thread feeder_thread = executeOffThread( () -> { feed_source_20(enc_feed); }, "test22_enc_dec_fed_irq::feed_source_20", false /* detach */);
+
+ final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
+ enc_feed,
+ silentListener, file_decrypted);
+ try {
+ feeder_thread.join(1000);
+ } catch (final InterruptedException e) { }
+
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
+ Assert.assertFalse( ph2.isValid() );
+ }
+ {
+ // full speed, with content size, interrupting 1/4 way
+ final ByteInStream_Feed enc_feed = new ByteInStream_Feed(fname_payload_encrypted_lst.get(file_idx), io_timeout);
+ final Thread feeder_thread = executeOffThread( () -> { feed_source_21(enc_feed); }, "test22_enc_dec_fed_irq::feed_source_21", false /* detach */);
+
+ final PackHeader ph2 = Cipherpack.checkSignThenDecrypt(sign_pub_keys, dec_sec_key1_fname, dec_sec_key_passphrase,
+ enc_feed,
+ silentListener, file_decrypted);
+ try {
+ feeder_thread.join(1000);
+ } catch (final InterruptedException e) { }
+
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: Decypted %s to %s\n", fname_payload_encrypted_lst.get(file_idx), fname_payload_decrypted_lst.get(file_idx));
+ CPUtils.fprintf_td(System.err, "test21_enc_dec_fed_ok: %s\n", ph2.toString(true, true));
+ Assert.assertFalse( ph2.isValid() );
+ }
+ }
+ }
public static void main(final String args[]) {
org.junit.runner.JUnitCore.main(Test01Cipherpack.class.getName());