]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: test-stream writes now to buffer, not to temp-iostream
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 4 Aug 2016 18:38:30 +0000 (21:38 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 7 Aug 2016 23:01:09 +0000 (02:01 +0300)
This simplifies the following change.

src/lib-dcrypt/test-stream.c

index 126639bd02d0ac572118d2ac7e8c28727a621abe..75409fd47af651435e061f707f3625532f283067 100644 (file)
@@ -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, "<unused>", 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, "<unused>", 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, "<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 @@ 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();
 }