Converting Data Between Binary and ASCII

if ((status = B_EncodeInit (asciiEncoder)) != 0) break;

Step 4: Update

Enter the data to encode through B_EncodeUpdate. The application is responsible for allocating the space for the output of this routine. When encoding, for each three bytes of input there are four bytes of output. So when allocating space, multiply the input size by 4/3 and round up. If memory is not an issue, you can make the output buffer twice the size of the input length.

Given pre-existing binary input, your calls to the Update functions would be as follows:

/* We are assuming binaryData already points to allocated space and contains the data to encode into ASCII.

*/

unsigned char *binaryData; unsigned int binaryDataLen;

unsigned char *asciiEncoding = NULL_PTR; unsigned int asciiEncodingLenUpdate;

/* Allocate a buffer twice the size of the binary data */ asciiEncoding = T_malloc (binaryDataLen * 2);

if ((status = (asciiEncoding == NULL_PTR)) != 0) break;

if ((status = B_EncodeUpdate

(asciiEncoder, asciiEncoding, &asciiEncodingLenUpdate, (binaryDataLen * 2), binaryData, binaryDataLen)) != 0)

break;

C h a p t e r 5 N o n - C r y p t o g r a p h i c O p e r a t i o n s

1 7 3

Page 195
Image 195
RSA Security 5.2.2 manual Update, If status = BEncodeInit asciiEncoder != 0 break