A SERVICE OF

logo

Chapter 5 Non-Cryptographic Operations 175
Converting Data Between Binary and ASCII
Step 3: Init
To initialize decoding, call B_DecodeInit. This function takes only one argument, the
algorithm object:
Step 4: Update
Enter the data to decode through B_DecodeUpdate. The application is responsible for
allocating the space for the output of this routine. When decoding, there will be three
bytes of output for every four bytes of input. If memory is a concern, you may want to
determine the exact number of bytes you will need. If memory is not a concern, make
the output size equal to the input length.
Given your pre-existing ASCII input, your call to the Update function would be as
follows:
if ((status = B_SetAlgorithmInfo
(asciiDecoder, AI_RFC1113Recode, NULL_PTR)) != 0)
break;
if ((status = B_DecodeInit (asciiDecoder)) != 0)
break;
/* We are assuming asciiEncoding already points to allocated
space and contains the data to decode into binary. Also,
asciiEncodingLenTotal is already set with the length of
the asciiEncoding.
*/
unsigned char *asciiEncoding;
unsigned int asciiEncodingLenTotal;
unsigned char *binaryDecoding = NULL_PTR;
unsigned int binaryDecodingLenUpdate;
/* Allocate a buffer the same size as the ascii data. */
binaryDecoding = T_malloc (asciiEncodingLenTotal);
if ((status = (binaryDecoding == NULL_PTR)) != 0)
break;