- static const char b64_tab[256] = {
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*000-007*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*010-017*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*020-027*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*030-037*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*040-047*/
- '\177', '\177', '\177', '\76', '\177', '\177', '\177', '\77', /*050-057*/
- '\64', '\65', '\66', '\67', '\70', '\71', '\72', '\73', /*060-067*/
- '\74', '\75', '\177', '\177', '\177', '\100', '\177', '\177', /*070-077*/
- '\177', '\0', '\1', '\2', '\3', '\4', '\5', '\6', /*100-107*/
- '\7', '\10', '\11', '\12', '\13', '\14', '\15', '\16', /*110-117*/
- '\17', '\20', '\21', '\22', '\23', '\24', '\25', '\26', /*120-127*/
- '\27', '\30', '\31', '\177', '\177', '\177', '\177', '\177', /*130-137*/
- '\177', '\32', '\33', '\34', '\35', '\36', '\37', '\40', /*140-147*/
- '\41', '\42', '\43', '\44', '\45', '\46', '\47', '\50', /*150-157*/
- '\51', '\52', '\53', '\54', '\55', '\56', '\57', '\60', /*160-167*/
- '\61', '\62', '\63', '\177', '\177', '\177', '\177', '\177', /*170-177*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*200-207*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*210-217*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*220-227*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*230-237*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*240-247*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*250-257*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*260-267*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*270-277*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*300-307*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*310-317*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*320-327*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*330-337*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*340-347*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*350-357*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*360-367*/
- '\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*370-377*/
- };
- unsigned char buf[2 * BUFSIZ];
-
- while (1) {
- int last_data = 0;
- unsigned char *p;
-
- if (fgets (buf, sizeof(buf), stdin) == NULL) {
- errorMsg("%s: Short file\n", inname);
- return FALSE;
- }
- p = buf;
-
- if (memcmp (buf, "====", 4) == 0)
- break;
- if (last_data != 0) {
- errorMsg("%s: data following `=' padding character\n", inname);
- return FALSE;
- }
-
- /* The following implementation of the base64 decoding might look
- a bit clumsy but I only try to follow the POSIX standard:
- ``All line breaks or other characters not found in the table
- [with base64 characters] shall be ignored by decoding
- software.'' */
- while (*p != '\n') {
- char c1, c2, c3;
-
- while ((b64_tab[*p] & '\100') != 0)
- if (*p == '\n' || *p++ == '=')
- break;
- if (*p == '\n')
- /* This leaves the loop. */
- continue;
- c1 = b64_tab[*p++];
-
- while ((b64_tab[*p] & '\100') != 0)
- if (*p == '\n' || *p++ == '=') {
- errorMsg("%s: illegal line\n", inname);
- return FALSE;
- }
- c2 = b64_tab[*p++];
-
- while (b64_tab[*p] == '\177')
- if (*p++ == '\n') {
- errorMsg("%s: illegal line\n", inname);
- return FALSE;
- }
- if (*p == '=') {
- putchar (c1 << 2 | c2 >> 4);
- last_data = 1;
- break;
- }
- c3 = b64_tab[*p++];
-
- while (b64_tab[*p] == '\177')
- if (*p++ == '\n') {
- errorMsg("%s: illegal line\n", inname);
- return FALSE;
- }
- putchar (c1 << 2 | c2 >> 4);
- putchar (c2 << 4 | c3 >> 2);
- if (*p == '=') {
- last_data = 1;
- break;
- }
- else
- putchar (c3 << 6 | b64_tab[*p++]);
- }
- }
-
- return TRUE;