changeset 20588:2d909f393a27

lib-dcrypt: test-stream writes now to buffer, not to temp-iostream This simplifies the following change.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 04 Aug 2016 21:38:30 +0300
parents ac533640ffab
children bdf83b32af07
files src/lib-dcrypt/test-stream.c
diffstat 1 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dcrypt/test-stream.c	Thu Aug 04 21:29:14 2016 +0300
+++ b/src/lib-dcrypt/test-stream.c	Thu Aug 04 21:38:30 2016 +0300
@@ -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 @@
 	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, "<unused>", test_v2_kp.pub, IO_STREAM_ENC_VERSION_1);
 	o_stream_nsend(os_2, payload, sizeof(payload));
 
@@ -197,7 +197,7 @@
 	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 @@
 	test_assert(is_2->stream_errno == 0);
 
 	i_stream_unref(&is_2);
+	buffer_free(&buf);
 
 	test_end();
 }
@@ -224,7 +225,8 @@
 	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, "<unused>", test_v2_kp.pub, IO_STREAM_ENC_VERSION_1);
 	o_stream_nsend(os_2, payload, sizeof(payload));
 
@@ -238,7 +240,7 @@
 	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 @@
 	test_assert(is_2->stream_errno == 0);
 
 	i_stream_unref(&is_2);
+	buffer_free(&buf);
 
 	test_end();
 }
@@ -262,7 +265,8 @@
 	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, "<unused>", 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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 		i_debug("error: %s", i_stream_get_error(is_2));
 
 	i_stream_unref(&is_2);
+	buffer_free(&buf);
 
 	test_end();
 }
@@ -336,7 +343,8 @@
 	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 @@
 	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 @@
 		i_debug("error: %s", i_stream_get_error(is_2));
 
 	i_stream_unref(&is_2);
+	buffer_free(&buf);
 
 	test_end();
 }
@@ -372,7 +381,8 @@
 	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 @@
 	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 @@
 	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();
 }