* @break_lines is typically used when putting base64-encoded data in emails.
* It breaks the lines at 72 columns instead of putting all of the text on
* the same line. This avoids problems with long lines in the email system.
+ * Note however that it breaks the lines with <literal>LF</literal>
+ * characters, not <literal>CR LF</literal> sequences, so the result cannot
+ * be passed directly to SMTP or certain other protocols.
*
* Return value: The number of bytes of output that was written
*
/* convert 4 base64 bytes to 3 normal bytes */
v=*save;
i=*state;
- inptr = (const guchar *)in;
+
last[0] = last[1] = 0;
+
+ /* we use the sign in the state to determine if we got a padding character
+ in the previous sequence */
+ if (i < 0)
+ {
+ i = -i;
+ last[0] = '=';
+ }
+
+ inptr = (const guchar *)in;
while (inptr < inend)
{
c = *inptr++;
}
*save = v;
- *state = i;
+ *state = last[0] == '=' ? -i : i;
return outptr - out;
}
* @text: zero-terminated string with base64 text to decode
* @out_len: (out): The length of the decoded data is written here
*
- * Decode a sequence of Base-64 encoded text into binary data
+ * Decode a sequence of Base-64 encoded text into binary data. Note
+ * that the returned binary data is not necessarily zero-terminated,
+ * so it should not be used as a character string.
*
* Return value: (transfer full) (array length=out_len) (element-type guint8):
* newly allocated buffer containing the binary data
input_length = strlen (text);
/* We can use a smaller limit here, since we know the saved state is 0,
- +1 used to avoid calling g_malloc0(0), and hence retruning NULL */
+ +1 used to avoid calling g_malloc0(0), and hence returning NULL */
ret = g_malloc0 ((input_length / 4) * 3 + 1);
*out_len = g_base64_decode_step (text, input_length, ret, &state, &save);