aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/cipherpack/cipherpack.hpp2
-rw-r--r--src/cipherpack/crypto1.cpp8
-rw-r--r--test/cipherpack/test_01_cipherpack.cpp66
-rw-r--r--test/java/test/org/cipherpack/Test01Cipherpack.java58
4 files changed, 84 insertions, 50 deletions
diff --git a/include/cipherpack/cipherpack.hpp b/include/cipherpack/cipherpack.hpp
index b6c25ad..dccf935 100644
--- a/include/cipherpack/cipherpack.hpp
+++ b/include/cipherpack/cipherpack.hpp
@@ -186,7 +186,7 @@ namespace cipherpack {
{ return in.peek(out, length, peek_offset); }
bool end_of_data() const override
- { return in.end_of_data(); }
+ { return !in.good(); }
std::string id() const override
{ return in.id(); }
diff --git a/src/cipherpack/crypto1.cpp b/src/cipherpack/crypto1.cpp
index 81f8f6b..60443bb 100644
--- a/src/cipherpack/crypto1.cpp
+++ b/src/cipherpack/crypto1.cpp
@@ -108,7 +108,7 @@ static uint64_t _read_stream(jau::io::ByteInStream& in,
buffer.resize(got);
total += got;
- has_more = 1 <= got && !in.end_of_data() && ( !in.has_content_size() || total < in.content_size() );
+ has_more = 1 <= got && in.good() && ( !in.has_content_size() || total < in.content_size() );
try {
if( !consumer_fn(buffer, !has_more) ) {
break; // end streaming
@@ -151,7 +151,7 @@ static uint64_t _read_stream(jau::io::ByteInStream& in,
{
uint64_t got = _read_buffer(in, *buffers[idx]);
total_read += got;
- eof_read = 0 == got || in.end_of_data() || ( in.has_content_size() && total_read >= in.content_size() );
+ eof_read = 0 == got || !in.good() || ( in.has_content_size() && total_read >= in.content_size() );
eof[idx] = eof_read;
++idx;
}
@@ -171,7 +171,7 @@ static uint64_t _read_stream(jau::io::ByteInStream& in,
if( !eof_read ) {
uint64_t got = _read_buffer(in, *buffers[idx]);
total_read += got;
- eof_read = 0 == got || in.end_of_data() || ( in.has_content_size() && total_read >= in.content_size() );
+ eof_read = 0 == got || !in.good() || ( in.has_content_size() && total_read >= in.content_size() );
eof[idx] = eof_read;
if( 0 == got ) {
// read-ahead eof propagation if read zero bytes,
@@ -686,7 +686,7 @@ static PackHeader checkSignThenDecrypt_Impl(const std::vector<std::string>& sign
const jau::fraction_timespec _t0 = jau::getMonotonicTime();
- if( source.end_of_data() ) {
+ if( !source.good() ) {
listener->notifyError(decrypt_mode, header, "Source is EOS or has an error "+source.to_string());
return header;
}
diff --git a/test/cipherpack/test_01_cipherpack.cpp b/test/cipherpack/test_01_cipherpack.cpp
index 769de57..2c89980 100644
--- a/test/cipherpack/test_01_cipherpack.cpp
+++ b/test/cipherpack/test_01_cipherpack.cpp
@@ -856,7 +856,7 @@ class Test01Cipherpack : public TestData {
std::vector<uint8_t> buffer;
buffer.reserve(chunck_sz);
uint64_t sent=0;
- while( sent < infile.content_size() && !infile.end_of_data() && !outfile.fail() ) {
+ while( sent < infile.content_size() && infile.good() && !outfile.fail() ) {
const size_t chunck_sz_max = std::min(chunck_sz, infile.content_size()-sent);
buffer.resize(buffer.capacity());
const uint64_t got = infile.read(buffer.data(), chunck_sz_max);
@@ -1011,18 +1011,21 @@ class Test01Cipherpack : public TestData {
static void feed_source_00_nosize_slow(jau::io::ByteInStream_Feed * enc_feed) {
uint64_t xfer_total = 0;
jau::io::ByteInStream_File enc_stream(enc_feed->id());
- while( !enc_stream.end_of_data() ) {
+ while( enc_stream.good() ) {
uint8_t buffer[slow_buffer_sz];
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- enc_feed->write(buffer, count);
- jau::sleep_for( slow_delay );
+ if( enc_feed->write(buffer, count) ) {
+ jau::sleep_for( slow_delay );
+ } else {
+ break;
+ }
}
}
(void)xfer_total;
// probably set after transfering due to above sleep, which also ends when total size has been reached.
- enc_feed->set_eof( enc_stream.fail() ? jau::io::async_io_result_t::FAILED : jau::io::async_io_result_t::SUCCESS );
+ enc_feed->set_eof( enc_feed->fail() || enc_stream.fail() ? jau::io::async_io_result_t::FAILED : jau::io::async_io_result_t::SUCCESS );
}
// throttled, with content size
@@ -1033,33 +1036,38 @@ class Test01Cipherpack : public TestData {
uint64_t xfer_total = 0;
jau::io::ByteInStream_File enc_stream(enc_feed->id());
- while( !enc_stream.end_of_data() && xfer_total < file_size ) {
+ while( enc_stream.good() && xfer_total < file_size ) {
uint8_t buffer[slow_buffer_sz];
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- enc_feed->write(buffer, count);
- jau::sleep_for( slow_delay );
+ if( enc_feed->write(buffer, count) ) {
+ jau::sleep_for( slow_delay );
+ } else {
+ break;
+ }
}
}
// 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 ? jau::io::async_io_result_t::SUCCESS : jau::io::async_io_result_t::FAILED );
+ enc_feed->set_eof( !enc_feed->fail() && !enc_stream.fail() && xfer_total == file_size ? jau::io::async_io_result_t::SUCCESS : jau::io::async_io_result_t::FAILED );
}
// full speed, no content size
static void feed_source_10_nosize_fast(jau::io::ByteInStream_Feed * enc_feed) {
uint64_t xfer_total = 0;
jau::io::ByteInStream_File enc_stream(enc_feed->id());
- while( !enc_stream.end_of_data() ) {
+ while( enc_stream.good() ) {
uint8_t buffer[cipherpack::Constants::buffer_size];
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- enc_feed->write(buffer, count);
+ if( !enc_feed->write(buffer, count) ) {
+ break;
+ }
}
}
(void)xfer_total;
- enc_feed->set_eof( enc_stream.fail() ? jau::io::async_io_result_t::FAILED : jau::io::async_io_result_t::SUCCESS );
+ enc_feed->set_eof( enc_feed->fail() || enc_stream.fail() ? jau::io::async_io_result_t::FAILED : jau::io::async_io_result_t::SUCCESS );
}
// full speed, with content size
@@ -1070,30 +1078,35 @@ class Test01Cipherpack : public TestData {
uint64_t xfer_total = 0;
jau::io::ByteInStream_File enc_stream(enc_feed->id());
- while( !enc_stream.end_of_data() && xfer_total < file_size ) {
+ while( enc_stream.good() && xfer_total < file_size ) {
uint8_t buffer[cipherpack::Constants::buffer_size];
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- enc_feed->write(buffer, count);
+ if( !enc_feed->write(buffer, count) ) {
+ break;
+ }
}
}
- enc_feed->set_eof( xfer_total == file_size ? jau::io::async_io_result_t::SUCCESS : jau::io::async_io_result_t::FAILED );
+ enc_feed->set_eof( !enc_feed->fail() && !enc_stream.fail() && xfer_total == file_size ? jau::io::async_io_result_t::SUCCESS : jau::io::async_io_result_t::FAILED );
}
// full speed, no content size, interrupting @ 1024 bytes within our header
static void feed_source_20_nosize_irqed_1k(jau::io::ByteInStream_Feed * enc_feed) {
uint64_t xfer_total = 0;
jau::io::ByteInStream_File enc_stream(enc_feed->id());
- while( !enc_stream.end_of_data() ) {
+ while( enc_stream.good() ) {
uint8_t buffer[1024];
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- enc_feed->write(buffer, count);
- if( xfer_total >= 1024 ) {
- enc_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
- return;
+ if( enc_feed->write(buffer, count) ) {
+ if( xfer_total >= 1024 ) {
+ enc_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
+ return;
+ }
+ } else {
+ break;
}
}
}
@@ -1107,15 +1120,18 @@ class Test01Cipherpack : public TestData {
uint64_t xfer_total = 0;
jau::io::ByteInStream_File enc_stream(enc_feed->id());
- while( !enc_stream.end_of_data() ) {
+ while( enc_stream.good() ) {
uint8_t buffer[1024];
size_t count = enc_stream.read(buffer, sizeof(buffer));
if( 0 < count ) {
xfer_total += count;
- enc_feed->write(buffer, count);
- if( xfer_total >= file_size/4 ) {
- enc_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
- return;
+ if( enc_feed->write(buffer, count) ) {
+ if( xfer_total >= file_size/4 ) {
+ enc_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader();
+ return;
+ }
+ } else {
+ break;
}
}
}
diff --git a/test/java/test/org/cipherpack/Test01Cipherpack.java b/test/java/test/org/cipherpack/Test01Cipherpack.java
index 00ff2ef..83dcfdf 100644
--- a/test/java/test/org/cipherpack/Test01Cipherpack.java
+++ b/test/java/test/org/cipherpack/Test01Cipherpack.java
@@ -776,8 +776,11 @@ public class Test01Cipherpack extends data_test {
final int count = in.read(buffer);
if( 0 < count ) {
// xfer_total += count;
- enc_feed.write(buffer, 0, count);
- try { Thread.sleep( slow_delay_ms ); } catch(final Throwable t) {}
+ if( enc_feed.write(buffer, 0, count) ) {
+ try { Thread.sleep( slow_delay_ms ); } catch(final Throwable t) {}
+ } else {
+ break;
+ }
}
}
} catch (final Exception ex) {
@@ -787,7 +790,7 @@ public class Test01Cipherpack extends data_test {
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 */ );
+ enc_feed.set_eof( enc_feed.fail() ? -1 /* FAILED */ : 1 /* SUCCESS */ );
} };
// throttled, with content size
@@ -808,8 +811,11 @@ public class Test01Cipherpack extends data_test {
final int count = in.read(buffer);
if( 0 < count ) {
xfer_total += count;
- enc_feed.write(buffer, 0, count);
- try { Thread.sleep( slow_delay_ms ); } catch(final Throwable t) {}
+ if( enc_feed.write(buffer, 0, count) ) {
+ try { Thread.sleep( slow_delay_ms ); } catch(final Throwable t) {}
+ } else {
+ break;
+ }
}
}
} catch (final Exception ex) {
@@ -819,7 +825,7 @@ public class Test01Cipherpack extends data_test {
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 */);
+ enc_feed.set_eof( !enc_feed.fail() && xfer_total == file_size ? 1 /* SUCCESS */ : -1 /* FAILED */);
} };
// full speed, no content size
@@ -838,7 +844,9 @@ public class Test01Cipherpack extends data_test {
final int count = in.read(buffer);
if( 0 < count ) {
// xfer_total += count;
- enc_feed.write(buffer, 0, count);
+ if( !enc_feed.write(buffer, 0, count) ) {
+ break;
+ }
}
}
} catch (final Exception ex) {
@@ -848,7 +856,7 @@ public class Test01Cipherpack extends data_test {
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 */ );
+ enc_feed.set_eof( enc_feed.fail() ? -1 /* FAIL */ : 1 /* SUCCESS */ );
} };
// full speed, with content size
@@ -869,7 +877,9 @@ public class Test01Cipherpack extends data_test {
final int count = in.read(buffer);
if( 0 < count ) {
xfer_total += count;
- enc_feed.write(buffer, 0, count);
+ if( !enc_feed.write(buffer, 0, count) ) {
+ break;
+ }
}
}
} catch (final Exception ex) {
@@ -879,7 +889,7 @@ public class Test01Cipherpack extends data_test {
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 */);
+ enc_feed.set_eof( !enc_feed.fail() && xfer_total == file_size ? 1 /* SUCCESS */ : -1 /* FAILED */);
} };
// full speed, with content size, implicit eof based on count
@@ -901,7 +911,9 @@ public class Test01Cipherpack extends data_test {
final int count = in.read(buffer);
if( 0 < count ) {
xfer_total += count;
- enc_feed.write(buffer, 0, count);
+ if( !enc_feed.write(buffer, 0, count) ) {
+ break;
+ }
} else if( 0 > count ) {
in_eof = true;
}
@@ -913,7 +925,7 @@ public class Test01Cipherpack extends data_test {
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 */);
+ enc_feed.set_eof( !enc_feed.fail() && xfer_total == file_size ? 1 /* SUCCESS */ : -1 /* FAILED */);
} };
// full speed, no content size, interrupting @ 1024 bytes within our header
@@ -932,10 +944,13 @@ public class Test01Cipherpack extends data_test {
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;
+ if( enc_feed.write(buffer, 0, count) ) {
+ if( xfer_total >= 1024 ) {
+ enc_feed.set_eof( -1 /* FAILED */ ); // calls data_feed->interruptReader();
+ return;
+ }
+ } else {
+ break;
}
}
}
@@ -963,10 +978,13 @@ public class Test01Cipherpack extends data_test {
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;
+ if( enc_feed.write(buffer, 0, count) ) {
+ if( xfer_total >= file_size/4 ) {
+ enc_feed.set_eof( -1 /* FAILED */ ); // calls data_feed->interruptReader();
+ return;
+ }
+ } else {
+ break;
}
}
}