File: base64_decode.c

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (37 lines) | stat: -rw-r--r-- 842 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "misc.h"

void base64_decode_bs(BinarySink *bs, ptrlen input)
{
    BinarySource src[1];
    BinarySource_BARE_INIT_PL(src, input);

    while (get_avail(src)) {
        char b64atom[4];
        unsigned char binatom[3];

        for (size_t i = 0; i < 4 ;) {
            char c = get_byte(src);
            if (get_err(src))
                c = '=';
            if (c == '\n' || c == '\r')
                continue;
            b64atom[i++] = c;
        }

        put_data(bs, binatom, base64_decode_atom(b64atom, binatom));
    }
}

void base64_decode_fp(FILE *fp, ptrlen input)
{
    stdio_sink ss;
    stdio_sink_init(&ss, fp);
    base64_decode_bs(BinarySink_UPCAST(&ss), input);
}

strbuf *base64_decode_sb(ptrlen input)
{
    strbuf *sb = strbuf_new_nm();
    base64_decode_bs(BinarySink_UPCAST(sb), input);
    return sb;
}