Logo Search packages:      
Sourcecode: nbsmtp version File versions  Download package

int from64tobits ( char *  out,
const char *  in 
)

base 64 to raw bytes in quasi-big-endian order, returning count of bytes

Parameters:
[out] out Where to save the converted string
[in] in String to convert
Returns:
Number of converted bytes.

Definition at line 75 of file base64.c.

Referenced by nbsmtp_auth().

{
      int len = 0;
      register unsigned char digit1, digit2, digit3, digit4;

      if (in[0] == '+' && in[1] == ' ')
            in += 2;
      if (*in == '\r')
            return(0);

      do {
            digit1 = in[0];
            if (DECODE64(digit1) == BAD)
                  return(-1);
            digit2 = in[1];
            if (DECODE64(digit2) == BAD)
                  return(-1);
            digit3 = in[2];
            if (digit3 != '=' && DECODE64(digit3) == BAD)
                  return(-1);
            digit4 = in[3];
            if (digit4 != '=' && DECODE64(digit4) == BAD)
                  return(-1);
            in += 4;
            *out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4);
            ++len;
            if (digit3 != '=')
            {
                  *out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2);
                  ++len;
                  if (digit4 != '=')
                  {
                        *out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4);
                        ++len;
                  }
            }
      } while (*in && *in != '\r' && digit4 != '=');

      return (len);
}


Generated by  Doxygen 1.6.0   Back to index