bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Siraineni_stream_hash_read(struct istream_private *stream)
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen struct hash_istream *hstream = (struct hash_istream *)stream;
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen i_stream_seek(stream->parent, stream->parent_start_offset +
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen ret = i_stream_read_copy_from_parent(&stream->istream);
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen if (ret > 0 && hstream->hash_context != NULL) {
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen data = i_stream_get_data(&stream->istream, &size);
202a34580f6204672d9b0d6a0756f35a3c4cdef6Timo Sirainen i_assert(stream->istream.v_offset <= hstream->high_offset);
202a34580f6204672d9b0d6a0756f35a3c4cdef6Timo Sirainen skip = hstream->high_offset - stream->istream.v_offset;
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen } else if (ret < 0) {
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen /* we finished hashing it. don't access it anymore, because
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen the memory pointed by the hash may be freed before the
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen istream itself */
cbb79ea1b1a49255c6edc46409a544666b22788fTimo Siraineni_stream_hash_seek(struct istream_private *stream,
cbb79ea1b1a49255c6edc46409a544666b22788fTimo Sirainen struct hash_istream *hstream = (struct hash_istream *)stream;
1c6f6f5bef70f16546b3bc8f4cd5f93f373e82a2Timo Sirainen "Seeking not supported before hashing is finished");
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Siraineni_stream_create_hash(struct istream *input, const struct hash_method *method,
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen hstream->istream.max_buffer_size = input->real_stream->max_buffer_size;
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen hstream->istream.stream_size_passthrough = TRUE;
25fb397382c6f7d39bfeee85774e7675f02bfb3cTimo Sirainen hstream->istream.istream.readable_fd = input->readable_fd;
3157f61431f19e01173e2e0d270c28af86dc97aaTimo Sirainen hstream->istream.istream.blocking = input->blocking;
cbb79ea1b1a49255c6edc46409a544666b22788fTimo Sirainen hstream->istream.istream.seekable = input->seekable;