/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
*
* Glenn Fowler
* David Korn
* AT&T Research
*/
#include <ast.h>
/*
* mime base64 encode
*/
{
register unsigned char* fp;
register unsigned char* tp;
register unsigned char* fe;
register unsigned char* te;
register unsigned char* tc;
register unsigned char* m;
register unsigned long b;
size_t n;
m = (unsigned char*)alp;
if (fz >= 3)
{
n = fz % 3;
fz = n;
}
{
n = 0;
}
else
{
if (fn)
if (tn)
*tn = 0;
n = 1;
}
for (;;)
{
do
{
goto done;
{
if (fn)
if (tn)
}
b = *fp++ << 16;
b |= *fp++ << 8;
b |= *fp++;
*tp++ = m[b >> 18];
*tp++ = m[b & 077];
if (n)
{
}
else
*tp++ = '\n';
}
done:
if (fz)
{
{
if (fn)
if (tn)
}
b = *fp++ << 16;
if (fz == 2)
b |= *fp++ << 8;
*tp++ = m[b >> 18];
}
if (n)
else
{
tp--;
*tp = 0;
if (tn)
if (fn)
}
return n;
}
/*
* mime base64 decode
*/
{
register unsigned char* fp;
register unsigned char* tp;
register unsigned char* fe;
register unsigned char* te;
register unsigned char* tx;
register unsigned char* m;
register int c;
register int state;
register unsigned long v;
unsigned char* fc;
ssize_t n;
if (!(m = map)[0])
{
}
{
if (tz > 2)
tz = 2;
n = 0;
}
else
{
n = 1;
}
for (;;)
{
state = 0;
v = 0;
{
if ((c = m[*fp++]) < 64)
{
v = (v << 6) | c;
if (++state == 4)
{
{
if (n)
n += 3;
else
{
{
*tp++ = (v >> 16);
{
*tp++ = (v >> 8);
*tp++ = (v);
}
}
if (tn)
if (fn)
}
}
else
{
*tp++ = (v >> 16);
*tp++ = (v >> 8);
*tp++ = (v);
}
state = 0;
v = 0;
}
}
else if (c == B64_PAD)
break;
}
switch (state)
{
case 0:
goto done;
case 2:
*tp++ = v >> 4;
else if (n)
n++;
else
{
if (tn)
if (fn)
}
break;
case 3:
{
*tp++ = v >> 10;
*tp++ = v >> 2;
else
{
if (tn)
if (fn)
}
}
else if (n)
n += 2;
else
{
if (tn)
if (fn)
}
break;
}
break;
fp--;
}
done:
if (n)
n--;
else
{
*tp = 0;
if (fn)
if (tn)
}
return n;
}