File: decode_part.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (20 lines) | stat: -rw-r--r-- 649 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "base64.h"

int base64_decode_part(const char encoded[4], unsigned char bin[3])
{
  int e0;
  int e1;
  int e2;
  int e3;
  if (encoded[0] == BASE64_PAD) return 0;
  if ((e0 = base64_asc2bin[(unsigned char)encoded[0]]) == -1 ||
      (e1 = base64_asc2bin[(unsigned char)encoded[1]]) == -1) return -1;
  bin[0] = (e0 << 2) | (e1 >> 4);
  if (encoded[2] == BASE64_PAD) return 1;
  if ((e2 = base64_asc2bin[(unsigned char)encoded[2]]) == -1) return -1;
  bin[1] = (e1 << 4) | (e2 >> 2);
  if (encoded[3] == BASE64_PAD) return 2;
  if ((e3 = base64_asc2bin[(unsigned char)encoded[3]]) == -1) return -1;
  bin[2] = (e2 << 6) | e3;
  return 3;
}