From: Timo Sirainen Date: Thu, 4 Aug 2016 18:38:30 +0000 (+0300) Subject: lib-dcrypt: test-stream writes now to buffer, not to temp-iostream X-Git-Tag: 2.2.26~413 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b0f2d21e5d549ee14ed823cf122ed616584a367a;p=thirdparty%2Fdovecot%2Fcore.git lib-dcrypt: test-stream writes now to buffer, not to temp-iostream This simplifies the following change. --- diff --git a/src/lib-dcrypt/test-stream.c b/src/lib-dcrypt/test-stream.c index 126639bd02..75409fd47a 100644 --- a/src/lib-dcrypt/test-stream.c +++ b/src/lib-dcrypt/test-stream.c @@ -8,7 +8,6 @@ #include "istream-decrypt.h" #include "istream-hash.h" #include "istream-base64.h" -#include "iostream-temp.h" #include "randgen.h" #include "hash-method.h" #include "test-common.h" @@ -183,7 +182,8 @@ void test_write_read_v1(void) size_t pos = 0, siz; random_fill_weak(payload, IO_BLOCK_SIZE); - struct ostream *os = iostream_temp_create("/tmp", 0); + buffer_t *buf = buffer_create_dynamic(default_pool, sizeof(payload)); + struct ostream *os = o_stream_create_buffer(buf); struct ostream *os_2 = o_stream_create_encrypt(os, "", test_v2_kp.pub, IO_STREAM_ENC_VERSION_1); o_stream_nsend(os_2, payload, sizeof(payload)); @@ -197,7 +197,7 @@ void test_write_read_v1(void) o_stream_unref(&os); o_stream_unref(&os_2); - struct istream *is = iostream_temp_finish(&os, IO_BLOCK_SIZE); + struct istream *is = test_istream_create_data(buf->data, buf->used); struct istream *is_2 = i_stream_create_decrypt(is, test_v2_kp.priv); i_stream_unref(&is); @@ -211,6 +211,7 @@ void test_write_read_v1(void) test_assert(is_2->stream_errno == 0); i_stream_unref(&is_2); + buffer_free(&buf); test_end(); } @@ -224,7 +225,8 @@ void test_write_read_v1_short(void) size_t pos = 0, siz; random_fill_weak(payload, 1); - struct ostream *os = iostream_temp_create("/tmp", 0); + buffer_t *buf = buffer_create_dynamic(default_pool, 64); + struct ostream *os = o_stream_create_buffer(buf); struct ostream *os_2 = o_stream_create_encrypt(os, "", test_v2_kp.pub, IO_STREAM_ENC_VERSION_1); o_stream_nsend(os_2, payload, sizeof(payload)); @@ -238,7 +240,7 @@ void test_write_read_v1_short(void) o_stream_unref(&os); o_stream_unref(&os_2); - struct istream *is = iostream_temp_finish(&os, IO_BLOCK_SIZE); + struct istream *is = test_istream_create_data(buf->data, buf->used); struct istream *is_2 = i_stream_create_decrypt(is, test_v2_kp.priv); i_stream_unref(&is); @@ -252,6 +254,7 @@ void test_write_read_v1_short(void) test_assert(is_2->stream_errno == 0); i_stream_unref(&is_2); + buffer_free(&buf); test_end(); } @@ -262,7 +265,8 @@ void test_write_read_v1_empty(void) const unsigned char *ptr; size_t siz; test_begin("test_write_read_v1_empty"); - struct ostream *os = iostream_temp_create("/tmp", 0); + buffer_t *buf = buffer_create_dynamic(default_pool, 64); + struct ostream *os = o_stream_create_buffer(buf); struct ostream *os_2 = o_stream_create_encrypt(os, "", test_v1_kp.pub, IO_STREAM_ENC_VERSION_1); test_assert(o_stream_nfinish(os_2) == 0); if (os_2->stream_errno != 0) @@ -272,7 +276,7 @@ void test_write_read_v1_empty(void) o_stream_unref(&os_2); /* this should've been enough */ - struct istream *is = iostream_temp_finish(&os, IO_BLOCK_SIZE); + struct istream *is = test_istream_create_data(buf->data, buf->used); struct istream *is_2 = i_stream_create_decrypt(is, test_v1_kp.priv); i_stream_unref(&is); @@ -285,6 +289,7 @@ void test_write_read_v1_empty(void) if (is_2->stream_errno != 0) i_debug("error: %s", i_stream_get_error(is_2)); i_stream_unref(&is_2); + buffer_free(&buf); test_end(); } @@ -297,7 +302,8 @@ void test_write_read_v2(void) size_t pos = 0, siz; random_fill_weak(payload, IO_BLOCK_SIZE); - struct ostream *os = iostream_temp_create("/tmp", 0); + buffer_t *buf = buffer_create_dynamic(default_pool, sizeof(payload)); + struct ostream *os = o_stream_create_buffer(buf); struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v1_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD); o_stream_nsend(os_2, payload, sizeof(payload)); test_assert(o_stream_nfinish(os_2) == 0); @@ -307,7 +313,7 @@ void test_write_read_v2(void) o_stream_unref(&os); o_stream_unref(&os_2); - struct istream *is = iostream_temp_finish(&os, IO_BLOCK_SIZE); + struct istream *is = test_istream_create_data(buf->data, buf->used); struct istream *is_2 = i_stream_create_decrypt(is, test_v1_kp.priv); i_stream_unref(&is); @@ -323,6 +329,7 @@ void test_write_read_v2(void) i_debug("error: %s", i_stream_get_error(is_2)); i_stream_unref(&is_2); + buffer_free(&buf); test_end(); } @@ -336,7 +343,8 @@ void test_write_read_v2_short(void) size_t pos = 0, siz; random_fill_weak(payload, 1); - struct ostream *os = iostream_temp_create("/tmp", 0); + buffer_t *buf = buffer_create_dynamic(default_pool, 64); + struct ostream *os = o_stream_create_buffer(buf); struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v1_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD); o_stream_nsend(os_2, payload, sizeof(payload)); test_assert(o_stream_nfinish(os_2) == 0); @@ -346,7 +354,7 @@ void test_write_read_v2_short(void) o_stream_unref(&os); o_stream_unref(&os_2); - struct istream *is = iostream_temp_finish(&os, IO_BLOCK_SIZE); + struct istream *is = test_istream_create_data(buf->data, buf->used); struct istream *is_2 = i_stream_create_decrypt(is, test_v1_kp.priv); i_stream_unref(&is); @@ -362,6 +370,7 @@ void test_write_read_v2_short(void) i_debug("error: %s", i_stream_get_error(is_2)); i_stream_unref(&is_2); + buffer_free(&buf); test_end(); } @@ -372,7 +381,8 @@ void test_write_read_v2_empty(void) const unsigned char *ptr; size_t siz; test_begin("test_write_read_v2_empty"); - struct ostream *os = iostream_temp_create("/tmp", 0); + buffer_t *buf = buffer_create_dynamic(default_pool, 64); + struct ostream *os = o_stream_create_buffer(buf); struct ostream *os_2 = o_stream_create_encrypt(os, "aes-256-gcm-sha256", test_v1_kp.pub, IO_STREAM_ENC_INTEGRITY_AEAD); test_assert(o_stream_nfinish(os_2) == 0); if (os_2->stream_errno != 0) @@ -382,7 +392,7 @@ void test_write_read_v2_empty(void) o_stream_unref(&os_2); /* this should've been enough */ - struct istream *is = iostream_temp_finish(&os, IO_BLOCK_SIZE); + struct istream *is = test_istream_create_data(buf->data, buf->used); struct istream *is_2 = i_stream_create_decrypt(is, test_v1_kp.priv); i_stream_unref(&is); @@ -395,6 +405,7 @@ void test_write_read_v2_empty(void) if (is_2->stream_errno != 0) i_debug("error: %s", i_stream_get_error(is_2)); i_stream_unref(&is_2); + buffer_free(&buf); test_end(); }