Home > Support > Documentation

BER/PER C Utility Functions
[BER Runtime Library Functions.]


Detailed Description

BER/DER utility functions are provided for memory management, formatting output of ASN.1 messages, and error reporting. In many cases, these functions are closely coupled with the rt (runtime) series of common functions. The common functions provide common functionality shared between the BER/DER, PER, and XER runtime libraries. In many cases, these functions simply provide wrappers to the rt functions to maintain compatibility with existing versions of the ASN1C compiler.


Defines

#define xu_addTagErrParm   berErrAddTagParm

Functions

OSBOOL berErrAddTagParm (OSCTXT *pctxt, ASN1TAG tag)
int berErrUnexpTag (OSCTXT *pctxt, ASN1TAG exptag)
const char * berTagToString (ASN1TAG tag, char *buffer, size_t bufsiz)
const char * berTagToDynStr (OSCTXT *pctxt, ASN1TAG tag)
int xu_verify_len (OSOCTET *msg_p)
void * xu_parse_mmbuf (OSOCTET **buf_p2, int *buflen_p, OSOCTET *start_p, int bufsiz)
void xu_alloc_array (OSCTXT *pctxt, ASN1SeqOf *seqOf_p, int recSize, int recCount)
void xu_octscpy_s (OSUINT32 *nocts_p, OSOCTET *data_p, char *cstr, char zterm)
void xu_octscpy_ss (ASN1OctStr *octStr_p, char *cstring, char zterm)
void xu_octscpy_d (OSCTXT *pctxt, OSUINT32 *nocts_p, const OSOCTET **data_p2, char *cstring, char zterm)
void xu_octscpy_ds (OSCTXT *pctxt, ASN1DynOctStr *octStr_p, char *cstring, char zterm)
void xu_octmcpy_s (ASN1OctStr *octStr_p, void *data_p, int datalen)
void xu_octmcpy_d (OSCTXT *pctxt, ASN1DynOctStr *octStr_p, void *data_p, int datalen)
char * xu_fetchstr (int numocts, char *data)
int xu_hexstrcpy (char *data, char *hstring)
int xu_binstrcpy (char *data, char *bstring)
int xu_dump (OSOCTET *msgptr, ASN1DumpCbFunc cb, void *cbArg_p)
int xu_fdump (FILE *file_p, OSOCTET *msgptr)
void xu_hex_dump (OSOCTET *data, int numocts, OSBOOL hdrflg)
void xu_fmt_tag (ASN1TAG *tag_p, char *class_p, char *form_p, char *id_code)
char * xu_fmt_contents (OSCTXT *pctxt, int len, int *count)
int xu_fread (FILE *fp, OSOCTET *bufp, int bufsiz)
void xu_SaveBufferState (OSCTXT *pCtxt, OSRTBufSave *pSavedInfo)
void xu_RestoreBufferState (OSCTXT *pCtxt, OSRTBufSave *pSavedInfo)
int berReadMsgFromSocket (OSCTXT *pctxt, OSRTSOCKET socket, OSOCTET *buffer, int bufsiz, OSOCTET **ppDestBuffer, int *pMessageSize)

Function Documentation

OSBOOL berErrAddTagParm OSCTXT *  pctxt,
ASN1TAG  tag
 

This function adds a tag parameter to the context error structure.

Parameters:
pctxt Pointer to a context structure.
tag The tag to add.
Returns:
Pointer to the text string (buffer).

int berErrUnexpTag OSCTXT *  pctxt,
ASN1TAG  exptag
 

This function logs a BER unexpected tag error (IDNOTFOU) by adding the expected and parsed tag to the error context and returning the error status.

Parameters:
pctxt Pointer to a context structure.
exptag Expected tag.
Returns:
RTERR_IDNOTFOU status code.

int berReadMsgFromSocket OSCTXT *  pctxt,
OSRTSOCKET  socket,
OSOCTET *  buffer,
int  bufsiz,
OSOCTET **  ppDestBuffer,
int *  pMessageSize
 

This routine reads the BER message into the given buffer. The TLV can be of indefinite length. If buffer is NULL, dynamic buffer will be allocated and returned as ppDestBuffer. Length of the message will be returned in pMessageSize.

Parameters:
pctxt Pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls.
socket The socket to read from. It should be already connected TCP socket.
buffer The static buffer to receive the parsed data. Can be NULL.
bufsiz The size of the buffer to receive the parsed data. Should be 0, if buffer is NULL.
ppDestBuffer The pointer to receive the destination buffer pointer. If buffer is static, this parameter can be NULL.
pMessageSize The pointer to integer to receive the size of read message.
Returns:
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.

const char* berTagToDynStr OSCTXT *  pctxt,
ASN1TAG  tag
 

This function converts an internal binary ASN.1 tag to a string in standard ASN.1 syntax form. This version creates a dynamic string by allocating memory using the rtxMemAlloc function. This memory will be release when context memory is freed.

Parameters:
pctxt Pointer to a context structure.
tag The tag to convert.
Returns:
Pointer to dynamic text string.

const char* berTagToString ASN1TAG  tag,
char *  buffer,
size_t  bufsiz
 

This function converts an internal binary ASN.1 tag to a string in standard ASN.1 syntax form.

Parameters:
tag The tag to convert.
buffer Text buffer into which the string will be written.
bufsiz Size of the text buffer.
Returns:
Pointer to the text string (buffer).

void xu_alloc_array OSCTXT *  pctxt,
ASN1SeqOf *  seqOf_p,
int  recSize,
int  recCount
 

This function will allocate space for a given count of fixed size elements.

Parameters:
pctxt A pointer to a context structure. This provides a storage area for the function to store all working variables that must be maintained between function calls.
seqOf_p A pointer to a generic sequence of structure variables to receive the returned memory. This structure contains a record count and a data pointer element. The record count is populated with the recCount passed into the function. The data pointer is set to the value that is returned from the memory allocation function.
recSize The number of bytes in one record in the array.
recCount The number of records to allocate. A pointer to a generic sequence of structure variable to receive the returned memory. This structure contains a record count and data pointer element. The record count is populated with the recCount passed into the function. The data pointer is set to the value that is returned from the memory allocation function.

int xu_dump OSOCTET *  msgptr,
ASN1DumpCbFunc  cb,
void *  cbArg_p
 

This function dumps an encoded ASN.1 message to the standard output device or to another interface in a formatted display. The display includes, for each message component, message tag (class, form, and ID code) and data (in hexadecimal and character text formats).

This function is invoked for each line of text formatted from the given message. The formatted line is passed on the text_p argument. The cbArg_p argument allows a user to defined callback argument to be passed to the callback function. This argument is specified in the call to xu_dump.

Use of the callback function is optional. If dump to standard output (stdout) is desired, the argument should be specified as NULL (note: the macro XU_DUMP in rtxsrc/rtxCommon.h can be used for this purpose).

Parameters:
*msgptr A pointer to an encoded ASN.1 message.
cb Callback function that gets invoked for each line of formatted output. For a dump to standard output (stdout), this parameter can be specified as NULL.
cbArg_p Callback function argument will be passed to the callback function.
Returns:
Status of the dump operation. Possible values are 0 if decoding is successful or one of the negative status codes.

int xu_fdump FILE *  file_p,
OSOCTET *  msgptr
 

This function dumps an encoded ASN.1 message to a text file. The display includes, for each message component, message tag (class, form, and ID code), length, and data (in hexadecimal and character text formats).

Parameters:
*file_p A text file pointer.
*msgptr A pointer to an encoded ASN.1 message buffer.
Returns:
Status of the dump operation. Possible values are 0 if decoding is successful or one of the negative status codes.

void xu_hex_dump OSOCTET *  data,
int  numocts,
OSBOOL  hdrflg
 

This function dumps binary data in raw hexadecimal and character text formats. It can be used only to examine runtime library encode/decode functions input or output data. This function outputs data only to the standard output device.

This function is considered depreciated and is only being maintained to provide backward compatibility with older versions of ASN1C.

Parameters:
*data A pointer to the start of the block of memory to be dumped.
numocts The number of octets (bytes) to be dumped.
hdrflg A Boolean variable indicating whether or not a head line should be dumped as the first line of the display.

void xu_RestoreBufferState OSCTXT *  pCtxt,
OSRTBufSave *  pSavedInfo
 

This function is used to restore the current buffer state from previously saved info.

Parameters:
pCtxt - A pointer to a context structure.
pSavedInfo - A pointer to a structure holding the saved info.

void xu_SaveBufferState OSCTXT *  pCtxt,
OSRTBufSave *  pSavedInfo
 

This function is used to save the current buffer state.

Parameters:
pCtxt - A pointer to a context structure.
pSavedInfo - A pointer to a structure to hold the saved info.