void OCT_frombase64()

in src/oct.c [281:323]


void OCT_frombase64(octet *w,const char *b)
{
    int i;
    int j;
    int k;
    int pads;
    int len=(int)strlen(b);
    int c;
    int ch[4];
    int ptr[3];
    OCT_clear(w);

    j=k=0;
    while (j<len && k<w->max)
    {
        pads=0;
        for (i=0; i<4; i++)
        {
            c=80+b[j++];
            if (c<=112) continue; /* ignore white space */
            if (c>144 && c<171) c-=145;
            if (c>176 && c<203) c-=151;
            if (c>127 && c<138) c-=76;
            if (c==123) c=62;
            if (c==127) c=63;
            if (c==141)
            {
                pads++;    /* ignore pads '=' */
                continue;
            }
            ch[i]=c;
        }
        ptr[0]=(ch[0]<<2)|(ch[1]>>4);
        ptr[1]=(ch[1]<<4)|(ch[2]>>2);
        ptr[2]=(ch[2]<<6)|ch[3];
        for (i=0; i<3-pads && k<w->max; i++)
        {
            /* don't put in leading zeros */
            w->val[k++]=(char)ptr[i];
        }
    }
    w->len=k;
}