static void hash_method_loop_sha1(void *context, const void *data, size_t size) { sha1_loop(context, data, size); }
static void sg__sha1_update(void * pAlgCtx, const SG_byte * pBuf, SG_uint32 lenBuf) { sha1_loop( (struct sha1_ctxt *)pAlgCtx, pBuf, lenBuf); }
void Sha1::update(sha1_ctxt* context, const tuple_cell* tc) { return sha1_loop(context, tc); }
static void test_compression_handler(const struct compression_handler *handler) { const char *path = "test-compression.tmp"; struct istream *file_input, *input; struct ostream *file_output, *output; unsigned char buf[IO_BLOCK_SIZE]; const unsigned char *data; size_t size; struct sha1_ctxt sha1; unsigned char output_sha1[SHA1_RESULTLEN], input_sha1[SHA1_RESULTLEN]; unsigned int i; int fd; ssize_t ret; test_begin(t_strdup_printf("compression handler %s", handler->name)); /* write compressed data */ fd = open(path, O_TRUNC | O_CREAT | O_RDWR, 0600); if (fd == -1) i_fatal("creat(%s) failed: %m", path); file_output = o_stream_create_fd_file(fd, 0, FALSE); output = handler->create_ostream(file_output, 1); sha1_init(&sha1); /* 1) write lots of easily compressible data */ memset(buf, 0, sizeof(buf)); for (i = 0; i < 1024*1024*4 / sizeof(buf); i++) { sha1_loop(&sha1, buf, sizeof(buf)); test_assert(o_stream_send(output, buf, sizeof(buf)) == sizeof(buf)); } /* 2) write uncompressible data */ for (i = 0; i < 1024*128 / sizeof(buf); i++) { random_fill_weak(buf, sizeof(buf)); sha1_loop(&sha1, buf, sizeof(buf)); test_assert(o_stream_send(output, buf, sizeof(buf)) == sizeof(buf)); } /* 3) write semi-compressible data */ for (i = 0; i < sizeof(buf); i++) { if (rand () % 3 == 0) buf[i] = rand() % 4; else buf[i] = i; } for (i = 0; i < 1024*128 / sizeof(buf); i++) { sha1_loop(&sha1, buf, sizeof(buf)); test_assert(o_stream_send(output, buf, sizeof(buf)) == sizeof(buf)); } o_stream_destroy(&output); o_stream_destroy(&file_output); sha1_result(&sha1, output_sha1); /* read and uncompress the data */ sha1_init(&sha1); file_input = i_stream_create_fd(fd, IO_BLOCK_SIZE, FALSE); input = handler->create_istream(file_input, FALSE); while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) { sha1_loop(&sha1, data, size); i_stream_skip(input, size); } test_assert(ret == -1); i_stream_destroy(&input); i_stream_destroy(&file_input); sha1_result(&sha1, input_sha1); test_assert(memcmp(input_sha1, output_sha1, sizeof(input_sha1)) == 0); if (unlink(path) < 0) i_error("unlink(%s) failed: %m", path); test_end(); }