/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "buffer.h"
#include "base64.h"
#include "istream-private.h"
#include "istream-base64.h"
struct base64_encoder_istream {
/* current encoded line length. */
unsigned int chars_per_line;
bool crlf;
};
{
if (size >= 3)
return 1;
/* we have less than one base64 block.
see if there is more data available. */
if (ret <= 0) {
return ret;
}
return 1;
}
static int
{
const unsigned char *data;
return 0;
/* @UNSAFE: end of line, add newline */
return -2;
bstream->cur_line_len = 0;
}
/* can't fit everything to destination buffer.
write as much as we can. */
if (size == 0)
return -2;
/* encode 3 chars at a time, so base64_encode() doesn't
add '=' characters in the middle of the stream */
}
}
return 1;
}
{
(struct base64_encoder_istream *)stream;
int ret;
do {
if (ret == 0)
return 0;
if (ret < 0) {
return -1;
/* add the final partial block */
}
/* encode as many lines as fits into destination buffer */
return ret;
return post_count - pre_count;
}
static void
{
(struct base64_encoder_istream *)stream;
/* seeking backwards - go back to beginning and seek
forward from there. */
bstream->cur_line_len = 0;
}
}
static int
bool exact ATTR_UNUSED)
{
(struct base64_encoder_istream *)stream;
return -1;
}
return 0;
/* calculate size of encoded data */
/* update size with added newlines */
return 0;
}
struct istream *
unsigned int chars_per_line, bool crlf)
{
i_stream_get_fd(input), 0);
}