1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00
Files
winscp/source/putty/utils/base64_encode.c
Martin Prikryl f670f4ebb1 Resetting differences to official PuTTY that are no longer needed
Most, if not all, were for compatibility with the classic C++Builder compiler (declarations in the middle of code + inline structure initializers)

Source commit: a9f38c3a07777e538c3c6e0fbdd38e9d68327dfa
2025-12-06 01:29:35 +01:00

41 lines
1.0 KiB
C

#include "misc.h"
void base64_encode_bs(BinarySink *bs, ptrlen input, int cpl)
{
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, input);
int linelen = 0;
while (get_avail(src)) {
size_t n = get_avail(src) < 3 ? get_avail(src) : 3;
ptrlen binatom = get_data(src, n);
char b64atom[4];
base64_encode_atom(binatom.ptr, binatom.len, b64atom);
for (size_t i = 0; i < 4; i++) {
if (cpl > 0 && linelen >= cpl) {
linelen = 0;
put_byte(bs, '\n');
}
put_byte(bs, b64atom[i]);
linelen++;
}
}
if (cpl > 0)
put_byte(bs, '\n');
}
void base64_encode_fp(FILE *fp, ptrlen input, int cpl)
{
stdio_sink ss;
stdio_sink_init(&ss, fp);
base64_encode_bs(BinarySink_UPCAST(&ss), input, cpl);
}
strbuf *base64_encode_sb(ptrlen input, int cpl)
{
strbuf *sb = strbuf_new_nm();
base64_encode_bs(BinarySink_UPCAST(sb), input, cpl);
return sb;
}