Back to index

nordugrid-arc-nox  1.1.0~rc6
Namespaces | Functions | Variables
Base64.cpp File Reference
#include "Base64.h"

Go to the source code of this file.

Namespaces

namespace  Arc
 ARCJSDLParser The ARCJSDLParser class, derived from the JobDescriptionParser class, is primarily a job description parser for the consolidated job description language (ARCJSDL), derived from JSDL, described in the following document http://svn.nordugrid.org/trac/nordugrid/browser/arc1/trunk/doc/tech_doc/client/job_description.odt.

Functions

static int base64_decode_binary (unsigned char *bufplain, const char *bufcoded)
static int base64_encode_binary (char *encoded, const unsigned char *string, int len)

Variables

static const unsigned char pr2six [256]
static const char basis_64 [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Function Documentation

static int base64_decode_binary ( unsigned char *  bufplain,
const char *  bufcoded 
) [static]

Definition at line 97 of file Base64.cpp.

                                                      {
  int nbytesdecoded;
  register const unsigned char *bufin;
  register unsigned char *bufout;
  register int nprbytes;

  bufin = (const unsigned char*)bufcoded;
  while (pr2six[*(bufin++)] <= 63) {}
  nprbytes = (bufin - (const unsigned char*)bufcoded) - 1;
  nbytesdecoded = ((nprbytes + 3) / 4) * 3;

  bufout = (unsigned char*)bufplain;
  bufin = (const unsigned char*)bufcoded;

  while (nprbytes > 4) {
    *(bufout++) =
      (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
    *(bufout++) =
      (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
    *(bufout++) =
      (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
    bufin += 4;
    nprbytes -= 4;
  }

  /* Note: (nprbytes == 1) would be an error, so just ingore that case */
  if (nprbytes > 1)
    *(bufout++) =
      (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
  if (nprbytes > 2)
    *(bufout++) =
      (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
  if (nprbytes > 3)
    *(bufout++) =
      (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);

  nbytesdecoded -= (4 - nprbytes) & 3;
  return nbytesdecoded;
}

Here is the caller graph for this function:

static int base64_encode_binary ( char *  encoded,
const unsigned char *  string,
int  len 
) [static]

Definition at line 144 of file Base64.cpp.

                                                                      {
  int i;
  char *p;

  p = encoded;
  for (i = 0; i < len - 2; i += 3) {
    *p++ = basis_64[(string[i] >> 2) & 0x3F];
    *p++ = basis_64[((string[i] & 0x3) << 4) |
                    ((int)(string[i + 1] & 0xF0) >> 4)];
    *p++ = basis_64[((string[i + 1] & 0xF) << 2) |
                    ((int)(string[i + 2] & 0xC0) >> 6)];
    *p++ = basis_64[string[i + 2] & 0x3F];
  }
  if (i < len) {
    *p++ = basis_64[(string[i] >> 2) & 0x3F];
    if (i == (len - 1)) {
      *p++ = basis_64[((string[i] & 0x3) << 4)];
      *p++ = '=';
    }
    else {
      *p++ = basis_64[((string[i] & 0x3) << 4) |
                      ((int)(string[i + 1] & 0xF0) >> 4)];
      *p++ = basis_64[((string[i + 1] & 0xF) << 2)];
    }
    *p++ = '=';
  }

  *p++ = '\0';
  return p - encoded;
}

Here is the caller graph for this function:


Variable Documentation

const char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" [static]

Definition at line 138 of file Base64.cpp.

const unsigned char pr2six[256] [static]

Definition at line 30 of file Base64.cpp.