自主协议库编译通过

This commit is contained in:
lnk
2026-06-15 15:48:16 +08:00
parent d3579a2aa7
commit 7205cb5cb9
621 changed files with 224958 additions and 48 deletions

65
mmslib/asn1/ard_bool.c Normal file
View File

@@ -0,0 +1,65 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_bool.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ard_bool.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/************************************************************************/
/************************************************************************/
/* get_bool */
/* Function to read an ASN.1 ST_BOOLEAN from a message being decoded */
/* Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_bool (ASN1_DEC_CTXT *ac, ST_BOOLEAN *ptr)
{
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_bool: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
if (ac->asn1r_elmnt_len != 1)
{
ALOG_NERR0 ("ASN.1 decode: Boolean length not == 1");
return (SD_FAILURE);
}
*ptr = (ST_BOOLEAN) *(ac->asn1r_field_ptr++);
return (SD_SUCCESS);
}

242
mmslib/asn1/ard_bstr.c Normal file
View File

@@ -0,0 +1,242 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_bstr.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 07/21/09 JRB 12 Set asn1r_bitstr_truncated flag for primitive*/
/* OR constructed bitstring. */
/* 07/21/09 JRB 11 Constructed bitstr code: enable it ALWAYS, */
/* overhaul to make sure segments are multiples */
/* of 8 bits, fix it to truncate. */
/* 07/07/09 JRB 10 asn1r_get_bitstr: fix bitcount if truncated. */
/* 04/21/08 JRB 09 Add cast to fix warning. */
/* 03/17/04 RKR 08 Changed thisFileName */
/* 03/11/04 GLB 07 Remove "thisFileName" */
/* 03/31/03 JRB 06 asn1r_get_bitstr: add max_bits arg & truncate*/
/* bitstr if max_bits exceeded. */
/* 03/05/02 JRB 05 Eliminate warnings. */
/* 12/20/01 JRB 04 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 12/12/01 JRB 03 Changes to compile MMS-EASE */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ard_bstr.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#if defined(DEBUG_SISCO)
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/************************************************************************/
static ST_VOID _dec_bitstr_cstr (ASN1_DEC_CTXT *ac, ST_UINT16 id_code);
/************************************************************************/
/* get_bitstr */
/* Function to read a primitive bitstring from an ASN.1 message. */
/* Truncate bitstring if it exceeds "max_bits". */
/************************************************************************/
ST_RET asn1r_get_bitstr (ASN1_DEC_CTXT *ac, ST_UCHAR *bit_ptr, ST_INT max_bits)
{
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!bit_ptr)
{
slogCallStack (sLogCtrl,
"get_: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
ac->asn1r_bitstr_truncated = SD_FALSE; /* CRITICAL: init "truncated" flag*/
if (ac->asn1r_elmnt_len < 1) /* For element length of 0, return error code. */
return (SD_FAILURE);
i = *(ac->asn1r_field_ptr++);
if (i>7 || i<0)
return (2); /* Return error code for bad unused-bits value. */
if (ac->asn1r_elmnt_len == 1) /* When there is only the unused-bits octet, */
{ /* it must = 0, and there are no data bits. */
if (i!=0)
return (2);
ac->asn1r_bitcount = 0;
}
else /* Treat normal case where there are data bits. */
{
ac->asn1r_bitcount = ((ac->asn1r_elmnt_len-1)*8 - i); /* Compute # data bits. */
/* If caller imposed a limit, truncate. */
if (max_bits != 0 && ac->asn1r_bitcount > max_bits)
{
ac->asn1r_bitcount = max_bits; /* truncated */
ac->asn1r_bitstr_truncated = SD_TRUE;
}
/* Copy bitstring to user buffer */
bstrcpy (bit_ptr, ac->asn1r_field_ptr, ac->asn1r_bitcount);
ac->asn1r_field_ptr += (ac->asn1r_elmnt_len - 1); /* point to next*/
}
return (SD_SUCCESS);
}
/************************************************************************/
/* get_bitstr_cstr */
/* Function to setup to get a constructed bitstring. */
/************************************************************************/
ST_VOID asn1r_get_bitstr_cstr (ASN1_DEC_CTXT *ac, ST_INT bits, ST_UCHAR *ptr)
{
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_bitstr_cstr: attempt to reference through a NULL pointer");
return;
}
#endif
ac->asn1r_max_bits = bits; /* max allowed # bits */
ac->_ad_bitptr = ptr; /* pointer to bit storage area */
*ac->_ad_bitptr = 0; /* zero first byte of user's storage area */
ac->asn1r_bitcount = 0; /* running bit count */
ac->asn1r_bitstr_truncated = SD_FALSE; /* CRITICAL: init "truncated" flag*/
ac->asn1r_u_id_fun = _dec_bitstr_cstr; /* universal until bitstr done */
ac->asn1r_c_id_fun = asn1r_class_err; /* no more context */
ac->asn1r_a_id_fun = asn1r_class_err; /* or application */
ac->asn1r_p_id_fun = asn1r_class_err; /* or private */
ac->asn1r_save_method = ac->asn1r_decode_method;
ac->asn1r_decode_method = ASN1_CLASS_METHOD;
ac->_asn1r_fun_save = ac->asn1r_decode_done_fun; /* save the previous done fun */
ac->asn1r_decode_done_fun = asn1r_done_err; /* can't be done for now */
ac->_asn1r_cstr_done_save = ac->asn1r_c_done_fun[ac->asn1r_msg_level];
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = asn1r_chk_getcstr_done;
}
/************************************************************************/
/* _dec_bitstr_cstr */
/* Function to decode asn.1 constructor bitstrings. */
/* NOTE: last segment may be any length but other segments must be */
/* multiple of 8 bits. We don't know which segment is last until the */
/* decode completes. We assume any segment that is NOT a multiple of */
/* 8 bits must be the last, so if any segment is received after that, */
/* it is a protocol error. */
/************************************************************************/
static ST_VOID _dec_bitstr_cstr (ASN1_DEC_CTXT *ac, ST_UINT16 id_code)
{
ST_INT numbytes;
ST_INT numbits;
ST_UCHAR unused_bits; /* # of unused bits in last byte */
ALOG_DEC0 ("_dec_bitstr_cstr");
if ((id_code & BITS_CODE) != BITS_CODE)
{ /* Protocol error - invalid ID Code. */
ALOG_NERR0 ("ASN.1 decode: unexpected tag");
asn1r_set_dec_err(ac, ASN1E_UNEXPECTED_TAG);
return;
}
if (ac->asn1r_constr_elmnt) /* Don't do anything for constructors */
{
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = NULL;
return;
}
/* Handle primitive bitstrings */
if (ac->asn1r_bitstr_truncated)
{
/* Already truncated when earlier segment decoded. Just skip over this data.*/
ac->asn1r_field_ptr += ac->asn1r_elmnt_len;
return;
}
/* If bitcount before adding this segment is not multiple of 8, the */
/* previous segment length was illegal. */
if (ac->asn1r_bitcount % 8)
{ /* Protocol error */
ALOG_NERR0 ("ASN.1 decode: constructed bitstring previous segment length not multiple of 8");
asn1r_set_dec_err(ac, ASN1E_INVALID_BITSTR);
return;
}
/* check length. Handle most common case first. */
if (ac->asn1r_elmnt_len > 1)
{
unused_bits = *ac->asn1r_field_ptr; /* read the unused-bits byte. */
if (unused_bits > 7)
{ /* Protocol error */
ALOG_NERR0 ("ASN.1 decode: constructed bitstring unused bits > 7");
asn1r_set_dec_err(ac, ASN1E_INVALID_BITSTR);
return;
}
/* # of bytes of data does not include the "unused bits" byte. */
numbytes = (ST_INT16) (ac->asn1r_elmnt_len - 1);
numbits = numbytes*8 - unused_bits;
if (ac->asn1r_bitcount + numbits > ac->asn1r_max_bits)
{
/* Truncate. Recalculate numbits, numbytes. */
numbits = ac->asn1r_max_bits - ac->asn1r_bitcount;
numbytes = numbits / 8;
if (numbits % 8)
numbytes++;
ac->asn1r_bitstr_truncated = SD_TRUE; /* set "truncated" flag */
}
/* Copy bitstring data (at ac->asn1r_field_ptr + 1) to user buffer */
if (numbits)
bstrcpy (ac->_ad_bitptr, ac->asn1r_field_ptr + 1, numbits);
ac->_ad_bitptr += numbytes; /* adjust pointer */
ac->asn1r_bitcount += numbits; /* adjust bit count */
}
else if (ac->asn1r_elmnt_len == 1) /* ONLY unused-bits byte. Must be 0.*/
{
unused_bits = *ac->asn1r_field_ptr; /* read the unused-bits byte. */
if (unused_bits != 0)
{ /* Protocol error */
ALOG_NERR0 ("ASN.1 decode: bitstring no data. unused bits != 0");
asn1r_set_dec_err(ac, ASN1E_INVALID_BITSTR);
return;
}
}
else /* (ac->asn1r_elmnt_len < 1) */
{ /* Protocol error */
ALOG_NERR1 ("ASN.1 decode: bitstring element length = %d illegal",
ac->asn1r_elmnt_len);
asn1r_set_dec_err(ac, ASN1E_INVALID_BITSTR);
return;
}
/* CRITICAL: update field_ptr only here. */
ac->asn1r_field_ptr += ac->asn1r_elmnt_len;
return;
}

72
mmslib/asn1/ard_btod.c Normal file
View File

@@ -0,0 +1,72 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_btod.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 05 Remove "thisFileName" */
/* 03/05/02 JRB 04 Eliminate warnings. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ard_btod.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/************************************************************************/
/* get_btod */
/************************************************************************/
ST_RET asn1r_get_btod (ASN1_DEC_CTXT *ac, MMS_BTOD *out)
{
ST_INT32 ms; /* ms time component */
ST_INT32 day = 0; /* day component of TimeOfDay value */
#ifdef DEBUG_ASN1_DECODE
if (!out)
{
slogCallStack (sLogCtrl,
"get_btod: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* Read Time Component (first 4 bytes) */
ms = (((ST_INT32) *(ac->asn1r_field_ptr++)) << 24) & 0xFF000000L;
ms |= (((ST_INT32) *(ac->asn1r_field_ptr++)) << 16) & 0x00FF0000L;
ms |= (((ST_INT32) *(ac->asn1r_field_ptr++)) << 8) & 0x0000FF00L;
ms |= ((ST_INT32) *(ac->asn1r_field_ptr++)) & 0x000000FFL;
/* Check to see if TimeOfDay is in long or short form */
if (ac->asn1r_elmnt_len == 4)
{
out->form = MMS_BTOD4;
}
else
{
out->form = MMS_BTOD6;
day = (((ST_INT32) *(ac->asn1r_field_ptr++)) << 8) & 0xFF00;
day |= ((ST_INT32) *(ac->asn1r_field_ptr++)) & 0x00FF;
}
out->ms = ms;
out->day = day;
return (SD_SUCCESS);
}

274
mmslib/asn1/ard_delm.c Normal file
View File

@@ -0,0 +1,274 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_delmn.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_delmn.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* Variable used in skipping over entire data elements. */
static ST_VOID _get_delmnt_all (ASN1_DEC_CTXT *ac, ST_UINT16 id);
static ST_VOID _get_delmnt_done (ASN1_DEC_CTXT *ac);
static ST_VOID _get_delmnt_start (ASN1_DEC_CTXT *ac, ST_UINT16 id);
static ST_VOID _parse_next_done (ASN1_DEC_CTXT *ac);
static ST_VOID _parse_next_all (ASN1_DEC_CTXT *ac, ST_UINT16 id);
static ST_VOID _parse_next_start (ASN1_DEC_CTXT *ac, ST_UINT16 id);
static ST_VOID _parse_cstr_start(ASN1_DEC_CTXT *ac);
/************************************************************************/
/************************************************************************/
/* get_delmnt submodule */
/* The code below makes up the 'get_delmnt' and 'parse_next' functions, */
/* which are used to simply ignore (possibly for later parsing) whatever*/
/* data element is next. A user function is called at the end of the */
/* data element to continue the parse as necessary. Both functions are */
/* useful for data elements that require another 'layer' of software to */
/* parse the data element. The difference is that get_delmnt moves */
/* the data to a user-designated buffer, whereas parse_next leaves it */
/* in place. */
/************************************************************************/
/************************************************************************/
/* get_delmnt */
/* This function is used to parse the next ASN.1 data element, regard- */
/* less of type, then call the selected done function. Inputs to */
/* get_delmnt are the pointer to the user buffer where the data element */
/* is to be put (as unparsed ASN.1-encoded data), the maximum length of */
/* the buffer, and the user done function to be called when the end of */
/* the data element is encountered. The actual length of the data ele- */
/* ment is available to the user's done function through the global */
/* variable asn1_octetcount. If there was not enough room in the user */
/* buffer, a protocol error (OCTCSTR_TOO_BIG) will result. */
/************************************************************************/
ST_VOID asn1r_get_delmnt (ASN1_DEC_CTXT *ac, ST_INT buflen, ST_UCHAR *bufptr,
ST_VOID (*done_fun)(ASN1_DEC_CTXT *ac))
{
ac->_asn1_maxoctets = buflen; /* save buflen in global var. */
ac->_asn1_octetptr = bufptr; /* initialize _asn1_octetptr */
ac->asn1r_octetcount = 0; /* initialize asn1_octetcount */
ac->_parse_begin_ptr = ac->asn1r_field_ptr; /* save ptr to start of element */
ac->_ad_parse_asn1r_fun_save = done_fun; /* save the selected done fun */
ac->_ad_parse_method_save = ac->asn1r_decode_method; /* save method; restore later */
ac->asn1r_decode_method = ASN1_CLASS_METHOD;
ac->asn1r_c_id_fun = _get_delmnt_start; /* select CTX function */
ac->asn1r_u_id_fun = _get_delmnt_start; /* select UNI function */
ac->asn1r_p_id_fun = _get_delmnt_start; /* select PRV function */
ac->asn1r_a_id_fun = _get_delmnt_start; /* select APP function */
}
/************************************************************************/
/* _get_delmnt_start */
/* This is the first function executed for the get_delmnt operation. */
/************************************************************************/
static ST_VOID _get_delmnt_start (ASN1_DEC_CTXT *ac, ST_UINT16 id)
{
ALOG_DEC0 ("_get_delmnt_start");
_get_delmnt_all (ac, id); /* move current elmnt to user buffer */
if (ac->asn1r_constr_elmnt) /* if this is a constructor elment - */
{ /* reset done fun for this msg level */
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = _get_delmnt_done;
ac->asn1r_c_id_fun = _get_delmnt_all; /* select CTX function */
ac->asn1r_u_id_fun = _get_delmnt_all; /* select UNI function */
ac->asn1r_p_id_fun = _get_delmnt_all; /* select PRV function */
ac->asn1r_a_id_fun = _get_delmnt_all; /* select APP function */
}
else /* if this is a primitive element - */
_get_delmnt_done (ac); /* all done with the parse */
}
/************************************************************************/
/* _get_delmnt_all */
/* Moves the head of the current data element to the user buffer, and */
/* moves the contents also in the case of a primitive data element. */
/* Updates asn1_octetcount and leaves asn1_field_ptr pointing to the next elmnt. */
/************************************************************************/
static ST_VOID _get_delmnt_all (ASN1_DEC_CTXT *ac, ST_UINT16 id)
{
ST_INT head_len;
ST_INT i;
ALOG_DEC0 ("_get_delmnt_all");
head_len = ac->asn1r_field_ptr - ac->asn1r_field_start;/* check for room */
ac->asn1r_octetcount += head_len; /* in the user buffer for */
if (ac->asn1r_octetcount > ac->_asn1_maxoctets) /* the head of this data elmnt */
{
ALOG_NERR0 ("ASN.1 decode: constructed octetstring too long");
asn1r_set_dec_err (ac, ASN1E_OCTSTR_TOO_BIG);
return;
}
ac->asn1r_field_ptr = ac->asn1r_field_start;
for (i=0; i<head_len; i++) /* move the head of this elmnt */
*(ac->_asn1_octetptr++) = *(ac->asn1r_field_ptr++); /* to the user buffer */
if (ac->asn1r_constr_elmnt) /* if a constructor elment - */
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = NULL;
else /* if a primitive data element */
{
ac->asn1r_octetcount += ac->asn1r_elmnt_len; /* check that the user buffer */
if (ac->asn1r_octetcount > ac->_asn1_maxoctets) /* is big enough for the con- */
{ /* tents of this primitive elmnt*/
ALOG_NERR0 ("ASN.1 decode: constructed octetstring too long");
asn1r_set_dec_err (ac, ASN1E_OCTSTR_TOO_BIG);
return;
}
for (i=0; i<ac->asn1r_elmnt_len; i++) /* move the primitive contents */
*(ac->_asn1_octetptr++) = *(ac->asn1r_field_ptr++); /* to the user buffer */
}
}
/************************************************************************/
/* _get_delmnt_done */
/* This function is called when the data element to be parsed is done. */
/* This is either via a constructor done call or from the start fun. */
/************************************************************************/
static ST_VOID _get_delmnt_done (ASN1_DEC_CTXT *ac)
{
ac->asn1r_decode_method = ac->_ad_parse_method_save; /* restore method */
(*ac->_ad_parse_asn1r_fun_save)(ac); /* invoke the user function */
}
/************************************************************************/
/* parse_cstr_contents */
/************************************************************************/
ST_VOID asn1r_parse_cstr_contents (ASN1_DEC_CTXT *ac, ST_VOID (*done_fun)(ASN1_DEC_CTXT *ac))
{
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = done_fun;
if (ac->asn1r_elmnt_len)
{
ac->_contents_done = ac->asn1r_field_ptr + ac->asn1r_elmnt_len;
_parse_cstr_start(ac);
}
}
/************************************************************************/
/* _parse_cstr_start */
/* Function will indirectly call itself until the original asn1_c_done_fun */
/* set by parse_cstr_contents expires. */
/************************************************************************/
static ST_VOID _parse_cstr_start (ASN1_DEC_CTXT *ac)
{
ALOG_DEC0 ("_parse_next_start");
if (ac->asn1r_field_ptr < ac->_contents_done)
asn1r_parse_next (ac, _parse_cstr_start);
}
/************************************************************************/
/* parse_next */
/* This function is used to parse the next ASN.1 data element, regard- */
/* less of type, then call the selected done function. In the user's */
/* done function, the length of the data element is given in the global */
/* variable 'asn1_octetcount', and the pointer to the beginning of the data */
/* element is 'parse_begin_ptr'. */
/************************************************************************/
ST_VOID asn1r_parse_next (ASN1_DEC_CTXT *ac, ST_VOID (*done_fun)(ASN1_DEC_CTXT *ac))
{
ac->_ad_parse_asn1r_fun_save = done_fun; /* save the selected done fun */
ac->_ad_parse_method_save = ac->asn1r_decode_method; /* save method */
ac->asn1r_decode_method = ASN1_CLASS_METHOD;
ac->_parse_begin_ptr = ac->asn1r_field_ptr; /* save ptr to start of element */
ac->asn1r_c_id_fun = _parse_next_start; /* select CTX function */
ac->asn1r_u_id_fun = _parse_next_start; /* select UNI function */
ac->asn1r_p_id_fun = _parse_next_start; /* select PRV function */
ac->asn1r_a_id_fun = _parse_next_start; /* select APP function */
}
/************************************************************************/
/* _parse_next_start */
/* First function executed for the parse_next operation. */
/************************************************************************/
static ST_VOID _parse_next_start (ASN1_DEC_CTXT *ac, ST_UINT16 id)
{
ALOG_DEC0 ("_parse_next_start");
if (ac->asn1r_constr_elmnt) /* if this is a constructor elment - */
{
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = _parse_next_done;
ac->asn1r_c_id_fun = _parse_next_all; /* select CTX function */
ac->asn1r_u_id_fun = _parse_next_all; /* select UNI function */
ac->asn1r_p_id_fun = _parse_next_all; /* select PRV function */
ac->asn1r_a_id_fun = _parse_next_all; /* select APP function */
}
else /* primitive element */
{
ac->asn1r_field_ptr += ac->asn1r_elmnt_len; /* skip the contents */
_parse_next_done (ac); /* all done with the parse */
}
}
/************************************************************************/
/* _parse_next_all */
/* This function is used as the only state function when parsing a */
/* constructor element. It just lets the ASN.1 tools look it over. */
/************************************************************************/
static ST_VOID _parse_next_all (ASN1_DEC_CTXT *ac, ST_UINT16 id)
{
ALOG_DEC0 ("_parse_next_all");
if (ac->asn1r_constr_elmnt) /* if this is a constructor elment - */
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = NULL;
else /* primitive element */
ac->asn1r_field_ptr += ac->asn1r_elmnt_len; /* skip the contents */
}
/************************************************************************/
/* _parse_next_done */
/* This function is called when the data element to be parsed is done. */
/* This is either via a constructor done call or from the start fun. */
/************************************************************************/
static ST_VOID _parse_next_done (ASN1_DEC_CTXT *ac)
{
ac->asn1r_octetcount = (ST_INT16) (ac->asn1r_field_ptr - ac->_parse_begin_ptr);
ac->asn1r_decode_method = ac->_ad_parse_method_save; /* restore method */
(*ac->_ad_parse_asn1r_fun_save)(ac); /* invoke the user function */
}

572
mmslib/asn1/ard_flt.c Normal file
View File

@@ -0,0 +1,572 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_float.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 10/03/08 JRB 08 Make sure elmnt_len is legal. */
/* 03/11/04 GLB 07 Remove "thisFileName" */
/* 02/19/03 JRB 06 Use SD_BYTE_ORDER. */
/* 02/19/03 JRB 05 Del VAX VMS support. For ALPHA VMS, assume */
/* compiler option /FLOAT=IEEE_FLOAT is used */
/* so it behaves like other systems. */
/* 03/05/02 JRB 04 Eliminate warnings. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_float.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
#ifdef ASN1_ARB_FLOAT
static ST_INT16 _fp_common (ASN1_DEC_CTXT *ac, ST_INT16 *sign, ST_UINT16 *exp, ST_UCHAR *lptr,
ST_INT16 *m, ST_UCHAR *next, ST_INT16 doubl_prec);
#endif
/************************************************************************/
/************************************************************************/
/* get_float */
/* Function to convert the MMS floating point type in the ASN.1 message */
/* stream to the single precision "float" type of the C programming */
/* language. This function will handle any size mantissa (which is */
/* rounded to fit into the local single precision floating point format)*/
/* and any size exponent width up to 15 bits. Exponents too large or */
/* small for the local representation translate into + or - infinity or */
/* zero, as the case may be. The return codes are: */
/* */
/* 0 - finite valid floating pt # decoded successfully */
/* 1 - invalid floating point number */
/* 2 - exponent length greater than 15 */
/* -1 - floating point value = NaN */
/* -2 - floating point value = + infinity */
/* -3 - floating point value = - infinity */
/* */
/************************************************************************/
ST_RET asn1r_get_float (ASN1_DEC_CTXT *ac, ST_FLOAT *out)
{
ST_UCHAR n; /* length of the exponent part */
ST_UCHAR *ptr; /* char ptr to output float variable out*/
ST_UCHAR *next; /* points to next data element */
ST_UCHAR *original_asn1_field_ptr;
ST_BOOLEAN float_is_zero;
#ifdef ASN1_ARB_FLOAT
ST_UINT16 exp; /* local variable to hold exponent part */
ST_INT i; /* utility variable */
ST_INT16 sign; /* sign of the floating point quantity */
ST_INT32 signexp; /* contains sign and exp parts of out */
ST_INT16 m; /* # of fract bits in 1st 2 exp octets */
ST_UINT32 *fract; /* contains fraction part of out */
#endif
#ifdef DEBUG_ASN1_DECODE
if (!out)
{
slogCallStack (sLogCtrl,
"get_float: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* MMS spec says FloatingPoint must be at least 2 octets */
if (ac->asn1r_elmnt_len < 2)
{
ALOG_ERR0 ("ASN.1 decode: length < 2 not allowed for FloatingPoint");
return (SD_FAILURE);
}
next = ac->asn1r_field_ptr + ac->asn1r_elmnt_len;
n = (ST_UCHAR) *(ac->asn1r_field_ptr++); /* read exponent width */
/* check to see if all the octets are 0 */
original_asn1_field_ptr = ac->asn1r_field_ptr;
float_is_zero = SD_TRUE; /* assume the float = 0 */
while(ac->asn1r_field_ptr < next)
{
if (*(ac->asn1r_field_ptr++) != 0)
{
float_is_zero = SD_FALSE;
break;
}
}
if (float_is_zero)
{
ac->asn1r_field_ptr = next;
*out = (ST_FLOAT)0; /* this float = 0 */
return(SD_SUCCESS); /* return success */
}
else
ac->asn1r_field_ptr = original_asn1_field_ptr;
ptr = (ST_UCHAR *) out;
/* Treat case where MMS floating point format coincides with IEEE 754. */
if (ac->asn1r_elmnt_len == 5 && n == 8)
{
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
#else
ac->asn1r_field_ptr += 3;
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
#endif
*ptr = (ST_UCHAR) *ac->asn1r_field_ptr;
ac->asn1r_field_ptr = next;
return (SD_SUCCESS);
}
#ifdef ASN1_ARB_FLOAT
/* Otherwise, convert arbitrary MMS floating point into local single- */
/* precision floating point. */
/* Get exponent and sign information, and read in the fraction part of */
/* the floating point number. */
m = 15 - (ST_INT16)n;
if ((i = _fp_common (ac,&sign,&exp,ptr,&m,next,SD_FALSE)) < 3)
{
*out = (ST_FLOAT)0;
return ((ST_INT16) i);
}
/* Shift fraction part to bottom 3 bytes, add 1, and then shift one */
/* more byte. This rounds fraction to local precision and places it */
/* nine bits into the floating point number, where it's supposed to go. */
fract = (ST_UINT32 *) out;
*fract = (*fract>>m) & (ST_UINT32)0x00FFFFFFL;
*fract = (*fract + (ST_UINT32)0x00000001L) >> 1; /* add 1 and then shift */
if (*fract & (ST_UINT32)0x00800000L)
{ /* rounding may cause */
exp++; /* exponent to increment*/
*fract &= (ST_UINT32)0x007FFFFFL;
}
/* OR the sign, exponent and fraction parts together to make a valid */
/* local floating point value. */
exp <<= 7; /* ready to be ORed with other parts */
signexp = ((ST_INT32) exp) << 16;
if (sign < 0)
signexp |= 0x80000000L;
*fract |= (ST_UINT32)signexp;
/* Return to calling routine with success indicated. */
return (SD_SUCCESS);
#else /* No arbitrary float format support */
return (SD_FAILURE);
#endif
}
/************************************************************************/
/* get_double */
/* Function to convert the MMS floating point type in the ASN.1 message */
/* stream to the double precision "double" type of the C programming */
/* language. This function will handle any size mantissa (which is */
/* rounded to fit into the local double precision floating point format)*/
/* and any size exponent width up to 15 bits. Exponents too large or */
/* small for the local representation translate into + or - infinity or */
/* zero, as the case may be. The return codes are: */
/* */
/* 0 - finite valid floating pt # decoded successfully */
/* 1 - invalid floating point number */
/* 2 - exponent length greater than 15 */
/* -1 - floating point value = NaN */
/* -2 - floating point value = + infinity */
/* -3 - floating point value = - infinity */
/* */
/************************************************************************/
ST_RET asn1r_get_double (ASN1_DEC_CTXT *ac, ST_DOUBLE *out)
{
ST_UCHAR n; /* length of the exponent part */
ST_UCHAR *ptr; /* char ptr to the out variable */
ST_UCHAR *next; /* points to next data element */
ST_UINT32 *h_ulong;
ST_UINT32 *l_ulong;
ST_UCHAR *original_asn1_field_ptr;
ST_BOOLEAN float_is_zero;
#ifdef ASN1_ARB_FLOAT
ST_INT garbage_bits_in_mantissa;
ST_UCHAR round; /* flag indicating rounding, not trunc. */
ST_UINT32 temp; /* utility variable */
ST_UINT16 exp; /* value of exponent (biased) */
ST_INT i; /* utility variable */
ST_UINT32 signexp; /* contains sign and exp parts of out */
ST_INT16 sign; /* sign of the floating point quantity */
ST_INT16 m; /* # of fract bits in 1st fract octet */
ST_INT16 local_double_exp_width; /* The local exp width of native double */
ST_UINT32 *fract; /* points to fraction part of out */
#endif
#ifdef DEBUG_ASN1_DECODE
if (!out)
{
slogCallStack (sLogCtrl,
"get_double: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
next = ac->asn1r_field_ptr + ac->asn1r_elmnt_len;
n = (ST_UCHAR) *(ac->asn1r_field_ptr++); /* read exponent width */
/* check to see if all the octets are 0 */
original_asn1_field_ptr = ac->asn1r_field_ptr;
float_is_zero = SD_TRUE; /* assume the float = 0 */
while(ac->asn1r_field_ptr < next)
{
if (*(ac->asn1r_field_ptr++) != 0)
{
float_is_zero = SD_FALSE;
break;
}
}
if (float_is_zero)
{
ac->asn1r_field_ptr = next;
*out = (ST_FLOAT)0; /* this float = 0 */
return(SD_SUCCESS); /* return success */
}
else
ac->asn1r_field_ptr = original_asn1_field_ptr;
ptr = (ST_UCHAR *) out;
h_ulong = (ST_UINT32 *) out;
l_ulong = h_ulong + 1;
/* Treat case where MMS floating point format coincides with IEEE 754 */
/* double precision floating point format. */
if (ac->asn1r_elmnt_len == 9 && n == 11)
{
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
#else
ac->asn1r_field_ptr += 7;
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
*(ptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
#endif
*ptr = (ST_UCHAR) *ac->asn1r_field_ptr;
ac->asn1r_field_ptr = next;
return (SD_SUCCESS);
}
#ifdef ASN1_ARB_FLOAT
/* Otherwise, convert arbitrary MMS floating point into local single- */
/* precision floating point. */
/* Get exponent and sign information, and read in the fraction part of */
/* the floating point number. */
m = 15 - (ST_INT16)n;
if ((i = _fp_common (ac,&sign,&exp,ptr,&m,next,SD_TRUE)) < 3)
{
*out = (ST_DOUBLE)0;
return ((ST_INT16) i);
}
/* The number of bits used to store the exponent of a double precision */
/* floating point number varies from machine to machine. The following */
/* piece of code sets this local exponent width. */
/* Assume all systems now use IEEE 754 format */
local_double_exp_width = 11;
/* The following piece of code calculates the number of bit positions */
/* to shift the fraction bits in the mantissa. */
/* (local_exp_width + sign width) - (non_mantisa_bits) */
garbage_bits_in_mantissa = 8 - m; /* num of garb bits in mantissa */
i = (local_double_exp_width + 1) - garbage_bits_in_mantissa;
/* was i = m + 4 */
fract = (ST_UINT32 *) out;
#if SD_BYTE_ORDER==SD_LITTLE_ENDIAN /* little-endian (like Intel) */
fract++; /* high half of f.p. */
#endif
/* save lowest i bits that will be lost when positioning the fraction */
temp =((0x00000001L << (local_double_exp_width + 1)) - 1L);
temp = *fract & (temp >> garbage_bits_in_mantissa);
*fract <<= garbage_bits_in_mantissa; /* put fract at far left*/
*fract >>= (local_double_exp_width + 1); /* shift fract in place */
/* grt rid of any sign and exponent */
*fract &= 0x000fffff; /* other ports have 12 */
/* pt at low half of fp */
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
fract++;
#else
fract--;
#endif
*fract >>= (i-1); /* low half of f.p. */
if (*fract & (ST_UINT32)0x00000001L)
round = SD_TRUE;
else
round = SD_FALSE;
temp <<= (32-i);
*fract = (*fract>>1) | temp; /* OR with bits from top half */
/* Round off the fraction part to fit into the local 8-byte double- */
/* precision floating point number. */
if (round)
{ /* if low half is all 1's, then */
if (*fract == 0xFFFFFFFF) /* rounding affects hi half too */
{
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
*(fract--) = 0;
#else
*(fract++) = 0;
#endif
*fract += 1;
if (*fract & (ST_UINT32)0xFFF00000L) /* if adding one overflows into */
{ /* exp part, increment exponent */
exp += 1;
*fract &= (ST_UINT32)0x000FFFFFL;
}
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
fract++; /* end up pointing to low half */
#else
fract--; /* end up pointing to low half */
#endif
}
else
*fract += 1;
}
/* OR the sign, exponent and (high) fraction parts together to make a */
/* valid local floating point value. */
exp <<= 4; /* ready to be ORed with other parts */
signexp = (ST_UINT32)exp << 16;
if (sign < 0)
signexp |= (ST_UINT32)0x80000000L;
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
*(--fract) |= signexp;
#else
*(++fract) |= signexp;
#endif
/* Return to calling routine with success indicated. */
return (SD_SUCCESS);
#else
return (SD_FAILURE);
#endif
}
/************************************************************************/
/* _fp_common */
/* Function to read the sign, exp, and fract parts of an MMS floating */
/* point type into the designated arguments. This function represents */
/* the common logic of the two functions: get_float and get_double. */
/* Besides sign, exp, and fract, there are three other outputs from */
/* this function: */
/* asn1_field_ptr - global variable set to next data element in msg */
/* m - modified in this function to be the number of fraction bits */
/* in the 1st octet containing any fraction bits */
/* return value - 0 - valid floating pt # with value of 0 */
/* 1 - invalid floating point number */
/* 2 - exponent length greater than 15 */
/* 3 - valid, nonzero, finite floating pt # */
/* -1 - floating point value = NaN */
/* -2 - floating point value = + infinity */
/* -3 - floating point value = - infinity */
/************************************************************************/
#ifdef ASN1_ARB_FLOAT
static ST_INT16 _fp_common (
ASN1_DEC_CTXT *ac, /* ASN1 context pointer */
ST_INT16 *sign, /* sign */
ST_UINT16 *exp, /* exponent translated to local repr'n */
ST_UCHAR *lptr, /* pointer to local f.p. # */
ST_INT16 *m, /* begins as # of fract bits in 1st two */
/* octets, modified in this function */
ST_UCHAR *next, /* pointer to next data element */
ST_INT16 doubl_prec) /* local precision - single or double */
{
ST_INT16 lbias; /* bias of local floating point type */
ST_UINT16 lmaxexp; /* max exponent of local f.p. type */
ST_INT16 lfract; /* local precision length in bytes */
ST_UINT16 bias; /* bias for MMS f.p. type being decoded */
ST_UCHAR nonzero; /* flag indicating if fract part is !=0 */
ST_INT i; /* utility variable */
ST_UINT16 temp1; /* utility variable */
ST_UCHAR temp2; /* utility variable */
/* Initialize variables dependent on the precision of the local f.p. */
/* representation (either single or double). */
if (doubl_prec)
{
lbias = 1023;
lmaxexp = 2047;
lfract = 7;
}
else
{
lbias = 127;
lmaxexp = 255;
lfract = 3;
}
/* First, check size of exponent and fraction parts based on element */
/* length and number of fraction bits in 1st two bytes. */
if (ac->asn1r_elmnt_len < 3) /* must have minimum of */
{ /* 2 bytes for f.p. # */
ac->asn1r_field_ptr = next;
return (SD_FAILURE);
}
if (*m < 0) /* exp part too big */
{
ac->asn1r_field_ptr = next;
return (2);
}
if (*m >= 15) /* exp part too small */
{
ac->asn1r_field_ptr = next;
return (SD_FAILURE);
}
/* Move exponent and sign parts into *exp variable for manipulation. */
temp1 = ((ST_UINT16) *(ac->asn1r_field_ptr++)) << 8;
*exp = temp1 | ((ST_UINT16) *(ac->asn1r_field_ptr++) & (ST_UINT16)0x00ff);
/* Determine sign, and mask out. */
if (*exp & (ST_UINT16)0x8000)
{
*sign = -1;
*exp = *exp & (ST_UINT16)0x7FFF; /* zero sign bit */
}
else
*sign = 1;
/* Reset asn1_field_ptr to point to 1st octet containing any fraction bits. */
if (*m > 8)
ac->asn1r_field_ptr -= 2;
else if (*m > 0)
ac->asn1r_field_ptr--;
/* Calculate bias of MMS floating point number before m is changed. */
bias = (ST_UINT16)0x7FFF >> (*m+1); /* bias = 2**(n-1) - 1 */
/* Determine if exponent part is all 1's. In this case, MMS float = NaN */
/* or infinity, so return with appropriate return code. */
*exp = *exp >> *m; /* get rid of fract bits on right */
temp1 = (ST_UINT16)0x7FFF >> *m; /* prepare comparison bytes */
*m = *m%8;
if (*m == 0)
*m = 8; /* m = # fract bits in current octet */
if (*exp == temp1) /* check for all 1's in exponent */
{
nonzero = SD_FALSE; /* now check for all 0's in fraction */
temp2 = (ST_UCHAR) (*(ac->asn1r_field_ptr++) & ~(0xFF<<*m));
while (ac->asn1r_field_ptr <= next) /* if all fract bits = */
{ /* 0, then we have a + */
if (temp2) /* or - infinity */
{
nonzero = SD_TRUE;
break;
}
temp2 = (ST_UCHAR) *(ac->asn1r_field_ptr++);
}
ac->asn1r_field_ptr = next;
if (nonzero)
return (-1); /* nonzero fract => NaN */
else if (*sign > 0)
return (-2); /* case of + infinity */
else
return (-3); /* case of - infinity */
}
/* Now that we know MMS float is a valid finite value, translate its */
/* exponent part into the exponent for the local representation. */
if ((i = (ST_INT16)*exp + lbias - (ST_INT16)bias) < 0)
return (SD_SUCCESS); /* Value too small to represent locally.*/
*exp = (ST_UINT16) i;
if (*exp > lmaxexp) /* biased local exp */
{ /* value too big to */
ac->asn1r_field_ptr = next; /* represent locally - */
if (*sign > 0) /* treat as + or - inf */
return (-2);
else
return (-3);
}
/* Move fraction part into local variable. */
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
for (i=0;i<lfract;i++)
{
if (ac->asn1r_field_ptr < next)
*(lptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr++);
else
{
*(lptr++) = (ST_UCHAR) 0; /* zero fill if local precision */
}
}
#else
ac->asn1r_field_ptr += lfract;
for (i=0;i<lfract;i++)
{
if (ac->asn1r_field_ptr < next)
*(lptr++) = (ST_UCHAR) *(ac->asn1r_field_ptr--);
else
{
*(lptr++) = (ST_UCHAR) 0; /* zero fill if local precision */
ac->asn1r_field_ptr--; /* is greater than MMS f.p. */
}
}
*lptr = (ST_UCHAR) *ac->asn1r_field_ptr; /* we know last byte < next */
#endif
ac->asn1r_field_ptr = next;
return (3); /* normal case */
}
#endif /* end of ARB FLOAT support */

91
mmslib/asn1/ard_idnt.c Normal file
View File

@@ -0,0 +1,91 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_idnt.c */
/* PRODUCT(S) : ASN1DE */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 04/24/03 JRB 04 Del MAX_IDENT_LEN define, get from mms_def2.h*/
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_idnt.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include <ctype.h>
#include "asn1r.h"
#include "asn1log.h"
#include "mms_def2.h" /* need MAX_IDENT_LEN define */
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* get_identifier */
/* Reads visible character data from message into selected buffer. If */
/* character is encountered which is not valid for ASN.1 VisibleString */
/* type, error code will be returned as function return value. Other- */
/* wise, function return value will be zero. This function will verify */
/* that buffer is big enough. Conversion from ASCII to local character */
/* representation is not necessary for MS-DOS. */
/************************************************************************/
ST_RET asn1r_get_identifier (ASN1_DEC_CTXT *ac, ST_CHAR *ptr)
{
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_identifier: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
if (ac->asn1r_elmnt_len > MAX_IDENT_LEN)
{ /* if the name is to long return error */
ALOG_NERR1 ("ASN.1 decode: Identifier too long (%u) ",
(ST_UINT) ac->asn1r_elmnt_len);
return (SD_FAILURE);
}
if (isdigit(*ac->asn1r_field_ptr)) /* the first letter may not be a digit */
{
ALOG_NERR0 ("ASN.1 decode: Identifier cannot start with a digit");
return (SD_FAILURE);
}
for (i = ac->asn1r_elmnt_len; i; --i)
{
if ((!(isalnum(*ac->asn1r_field_ptr))) &&
(!(*ac->asn1r_field_ptr == '_')) &&
(!(*ac->asn1r_field_ptr == '$')))
{
ALOG_NERR1 ("ASN.1 decode: invalid character (0x%02x) in identifier",
(int) *ac->asn1r_field_ptr);
return (SD_FAILURE);
}
*ptr = (ST_CHAR) *(ac->asn1r_field_ptr++); /* Move character to user buffer. */
ptr++;
}
*ptr = '\x00'; /* Null terminate the visible string. */
return(SD_SUCCESS); /* If no problelms, return success. */
}

490
mmslib/asn1/ard_int.c Normal file
View File

@@ -0,0 +1,490 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2005, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_int.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 08/24/09 JRB 09 Fix signed int out of range error detection. */
/* Use separate signed & unsigned functions. */
/* Simplify negative value handling. */
/* 10/03/08 JRB 08 Fix crash by testing for asn1r_elmnt_len < 1.*/
/* 06/10/05 JRB 07 Use i64 suffix on WIN32, default to LL suffix*/
/* 03/03/05 EJV 06 Use LL suffix also on linux. */
/* 03/16/04 EJV 05 Added ST_(U)LONG typecast to logs,on some sys*/
/* ST_(U)INT32 can be (unsigned) long or int. */
/* asn1r_get_u8 (_u16): fixed potential problem.*/
/* 01/08/04 EJV 04 asn1r_get_int64: added define for sun. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_int.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/************************************************************************/
static ST_RET asn1r_get_int32 (ASN1_DEC_CTXT *ac, ST_INT32 *ptr);
static ST_RET asn1r_get_uint32 (ASN1_DEC_CTXT *ac, ST_UINT32 *ptr);
#ifdef INT64_SUPPORT
static ST_RET asn1r_get_int64 (ASN1_DEC_CTXT *ac, ST_INT64 *ptr);
static ST_RET asn1r_get_uint64 (ASN1_DEC_CTXT *ac, ST_UINT64 *ptr);
#endif
/************************************************************************/
/* get_i8 */
/* Function to read a short integer from a message being decoded. */
/* Assumes asn1_field_ptr points to data (content field), and asn1_elmnt_len */
/* equals exactly one byte. Leaves pointer set to next data element. */
/* Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_i8 (ASN1_DEC_CTXT *ac, ST_INT8 *ptr)
{
ST_INT32 value;
ST_RET ret;
ret = asn1r_get_int32 (ac, &value);
if (ret == SD_SUCCESS && (value > 127 || value < -128))
{
ALOG_NERR1 ("ASN.1 decode: Signed8 out of range (%ld)", (ST_LONG) value);
return (SD_FAILURE);
}
*ptr = (ST_CHAR) value;
return (ret);
}
/************************************************************************/
/* get_i16 */
/* Function to read an integer from a message being decoded. */
/* Assume asn1_field_ptr points to data, and asn1_elmnt_len */
/* equals one or two bytes. Leaves pointer set to next data element. */
/* Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_i16 (ASN1_DEC_CTXT *ac, ST_INT16 *ptr)
{
ST_INT32 value;
ST_RET ret;
ret = asn1r_get_int32 (ac, &value);
if (ret == SD_SUCCESS && (value > 32767 || value < -32768))
{
ALOG_NERR1 ("ASN.1 decode: Signed16 out of range (%ld)", (ST_LONG) value);
return (SD_FAILURE);
}
*ptr = (ST_INT16) value;
return (ret);
}
/************************************************************************/
/* get_i32 */
/* Function to read a long integer from a message being decoded. */
/* Assumes asn1_field_ptr points to data, and asn1_elmnt_len */
/* equals one to four bytes. Leaves pointer set to next data element. */
/* Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_i32 (ASN1_DEC_CTXT *ac, ST_INT32 *ptr)
{
ST_INT32 value;
ST_RET ret;
ret = asn1r_get_int32 (ac, &value);
*ptr = value;
return (ret);
}
/************************************************************************/
/* get_u8 */
/* Function to read an ASN.1 INTEGER from a message being decoded */
/* into a 1-byte unsigned char. Assumes asn1_field_ptr points to data */
/* field and asn1_elmnt_len has 1 or 2 bytes. Leaves asn1_field_ptr pointing to */
/* next data element. Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_u8 (ASN1_DEC_CTXT *ac, ST_UCHAR *ptr)
{
ST_UINT32 value;
ST_RET ret;
ret = asn1r_get_uint32 (ac, &value);
if (ret == SD_SUCCESS && value > 0xFF)
{
ALOG_NERR1 ("ASN.1 decode: Unsigned16 out of range (%lu)", (ST_ULONG) value);
return (SD_FAILURE);
}
*ptr = (ST_UCHAR) value;
return (ret);
}
/************************************************************************/
/* get_u16 */
/* Function to read an ASN.1 INTEGER from a message being decoded */
/* into a 2-byte unsigned integer. Assumes asn1_field_ptr points to data */
/* field and asn1_elmnt_len has 1 to 3 bytes. Leaves asn1_field_ptr pointing to */
/* next data element. Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_u16 (ASN1_DEC_CTXT *ac, ST_UINT16 *ptr)
{
ST_UINT32 value;
ST_RET ret;
ret = asn1r_get_uint32 (ac, &value);
if (ret == SD_SUCCESS && value > 0xFFFF)
{
ALOG_NERR1 ("ASN.1 decode: Unsigned16 out of range (%lu)", (ST_ULONG) value);
return (SD_FAILURE);
}
*ptr = (ST_UINT16) value;
return (ret);
}
/************************************************************************/
/* get_u32 */
/* Function to read an ASN.1 INTEGER from a message being decoded */
/* into a 4-byte unsigned ST_INT32. Assumes asn1_field_ptr points to data */
/* field and asn1_elmnt_len has 1 to 5 bytes. Leaves asn1_field_ptr pointing */
/* to next data element. Returns 0 if OK, non-zero if error. */
/************************************************************************/
ST_RET asn1r_get_u32 (ASN1_DEC_CTXT *ac, ST_UINT32 *ptr)
{
ST_UINT32 value;
ST_RET ret;
ret = asn1r_get_uint32 (ac, &value);
*ptr = value;
return (ret);
}
/************************************************************************/
/* Use this function ONLY for "signed" integers. */
/************************************************************************/
static ST_RET asn1r_get_int32 (ASN1_DEC_CTXT *ac, ST_INT32 *ptr)
{
/* NOTE: Use all "unsigned" variables so shifting & casting does not */
/* cause sign extension, then cast final result to ST_INT32. */
ST_UINT32 value; /* decoded value */
ST_UINT32 tmp;
ST_BOOLEAN positive;
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_i32: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* ASN.1 spec says 'integer' must be at least 1 octet */
if (ac->asn1r_elmnt_len < 1)
{
ALOG_ERR0 ("ASN.1 decode: length < 1 not allowed for integer");
return (SD_FAILURE);
}
/* Check to see if the ASN.1 data value is positive or negative */
if (*ac->asn1r_field_ptr & 0x80)
positive = SD_FALSE;
else
positive = SD_TRUE;
/* Large 'unsigned' values may be 5 bytes, with a leading 0. */
/* This value is 'signed', so it should NEVER be more than 4 bytes. */
i = ac->asn1r_elmnt_len;
if (i > 4)
{
ALOG_NERR0 ("ASN.1 decode: invalid 'signed' integer encoding (more than 4 bytes)");
return (SD_FAILURE);
}
/* Read the value into a ST_UINT32, shifting as we go */
if (!positive)
value = 0xFFFFFF00; /* negative value, start with high bits set */
else
value = 0; /* positive value, start with 0 */
while (SD_TRUE)
{
/* asn1r_field_ptr is (ST_UCHAR *), so this cast should NEVER sign extend.*/
tmp = (ST_UINT32) *(ac->asn1r_field_ptr++);
value |= tmp;
if (--i == 0)
break;
value <<= 8; /* more bytes to decode. Make room for next byte.*/
}
/* Finally, after all shifting & masking, cast it to 'signed' value. */
*ptr = (ST_INT32) value;
return (SD_SUCCESS);
}
/************************************************************************/
/* Use this function ONLY for "unsigned" integers. */
/************************************************************************/
static ST_RET asn1r_get_uint32 (ASN1_DEC_CTXT *ac, ST_UINT32 *ptr)
{
ST_UINT32 value; /* decoded value */
ST_UINT32 tmp;
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_u32: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* ASN.1 spec says 'integer' must be at least 1 octet */
if (ac->asn1r_elmnt_len < 1)
{
ALOG_ERR0 ("ASN.1 decode: length < 1 not allowed for integer");
return (SD_FAILURE);
}
/* ASN.1 data value MUST BE positive. */
if (*ac->asn1r_field_ptr & 0x80)
{
ALOG_NERR0 ("ASN.1 decode: Negative number received for unsigned integer");
return (SD_FAILURE);
}
/* Large 'unsigned' values may be 5 bytes, with a leading 0. */
/* If so, we strip the leading 0. */
i = ac->asn1r_elmnt_len;
if (i > 5)
{
ALOG_NERR0 ("ASN.1 decode: invalid UINT32 encoding (more than 5 bytes)");
return (SD_FAILURE);
}
if (i == 5) /* Large positive number, first byte must be 0. */
{
if (*ac->asn1r_field_ptr != 0)
{
ALOG_NERR0 ("ASN.1 decode: invalid UINT32 encoding (5 bytes but first byte != 0)");
return (SD_FAILURE);
}
++ac->asn1r_field_ptr; /* skip the leading 0 */
--i;
}
/* Read the value into a ST_UINT32, shifting as we go */
value = 0;
while (SD_TRUE)
{
/* asn1r_field_ptr is (ST_UCHAR *), so this cast should NEVER sign extend.*/
tmp = (ST_UINT32) *(ac->asn1r_field_ptr++);
value |= tmp;
if (--i == 0)
break;
value <<= 8; /* more bytes to decode. Make room for next byte.*/
}
*ptr = value;
return (SD_SUCCESS);
}
/************************************************************************/
#ifdef INT64_SUPPORT
/************************************************************************/
/************************************************************************/
ST_RET asn1r_get_u64 (ASN1_DEC_CTXT *ac, ST_UINT64 *ptr)
{
ST_UINT64 value;
ST_RET ret;
ret = asn1r_get_uint64 (ac, &value);
*ptr = value;
return (ret);
}
/************************************************************************/
ST_RET asn1r_get_i64 (ASN1_DEC_CTXT *ac, ST_INT64 *ptr)
{
ST_INT64 value;
ST_RET ret;
ret = asn1r_get_int64 (ac, &value);
*ptr = value;
return (ret);
}
/************************************************************************/
/* Use this function ONLY for "signed" integers. */
/************************************************************************/
static ST_RET asn1r_get_int64 (ASN1_DEC_CTXT *ac, ST_INT64 *ptr)
{
/* NOTE: Use all "unsigned" variables so shifting & casting does not */
/* cause sign extension, then cast final result to ST_INT64. */
ST_UINT64 value; /* decoded value */
ST_UINT64 tmp;
ST_BOOLEAN positive;
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_i64: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* ASN.1 spec says 'integer' must be at least 1 octet */
if (ac->asn1r_elmnt_len < 1)
{
ALOG_ERR0 ("ASN.1 decode: length < 1 not allowed for integer");
return (SD_FAILURE);
}
/* Check to see if the ASN.1 data value is positive or negative */
if (*ac->asn1r_field_ptr & 0x80)
positive = SD_FALSE;
else
positive = SD_TRUE;
/* Large 'unsigned' values may be 9 bytes, with a leading 0. */
/* This value is 'signed', so it should NEVER be more than 8 bytes. */
i = ac->asn1r_elmnt_len;
if (i > 8)
{
ALOG_NERR0 ("ASN.1 decode: invalid 'signed' integer encoding (more than 8 bytes)");
return (SD_FAILURE);
}
/* Read the value into a ST_UINT64, shifting as we go */
if (!positive)
{
#if defined(_WIN32)
value = 0xffffffffffffff00i64; /* negative value, start with high bits set*/
#else
value = 0xffffffffffffff00LL; /* negative value, start with high bits set*/
#endif
}
else
value = 0; /* positive value, start with 0 */
while (SD_TRUE)
{
/* asn1r_field_ptr is (ST_UCHAR *), so this cast should NEVER sign extend.*/
tmp = (ST_UINT64) *(ac->asn1r_field_ptr++);
value |= tmp;
if (--i == 0)
break;
value <<= 8; /* more bytes to decode. Make room for next byte.*/
}
/* Finally, after all shifting & masking, cast it to 'signed' value. */
*ptr = (ST_INT64) value;
return (SD_SUCCESS);
}
/************************************************************************/
/* Use this function ONLY for "unsigned" integers. */
/************************************************************************/
static ST_RET asn1r_get_uint64 (ASN1_DEC_CTXT *ac, ST_UINT64 *ptr)
{
ST_UINT64 value; /* decoded value */
ST_UINT64 tmp;
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_u64: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* ASN.1 spec says 'integer' must be at least 1 octet */
if (ac->asn1r_elmnt_len < 1)
{
ALOG_ERR0 ("ASN.1 decode: length < 1 not allowed for integer");
return (SD_FAILURE);
}
/* ASN.1 data value MUST BE positive. */
if (*ac->asn1r_field_ptr & 0x80)
{
ALOG_NERR0 ("ASN.1 decode: Negative number received for unsigned integer");
return (SD_FAILURE);
}
/* Large 'unsigned' values may be 9 bytes, with a leading 0. */
/* If so, we strip the leading 0. */
i = ac->asn1r_elmnt_len;
if (i > 9)
{
ALOG_NERR0 ("ASN.1 decode: invalid UINT64 encoding (more than 9 bytes)");
return (SD_FAILURE);
}
if (i == 9) /* Large positive number, first byte must be 0. */
{
if (*ac->asn1r_field_ptr != 0)
{
ALOG_NERR0 ("ASN.1 decode: invalid UINT64 encoding (9 bytes but first byte != 0)");
return (SD_FAILURE);
}
++ac->asn1r_field_ptr; /* skip the leading 0 */
--i;
}
/* Read the value into a ST_UINT64, shifting as we go */
value = 0;
while (SD_TRUE)
{
/* asn1r_field_ptr is (ST_UCHAR *), so this cast should NEVER sign extend.*/
tmp = (ST_UINT64) *(ac->asn1r_field_ptr++);
value |= tmp;
if (--i == 0)
break;
value <<= 8; /* more bytes to decode. Make room for next byte.*/
}
*ptr = value;
return (SD_SUCCESS);
}
/************************************************************************/
#endif /* #ifdef INT64_SUPPORT */
/************************************************************************/

113
mmslib/asn1/ard_objd.c Normal file
View File

@@ -0,0 +1,113 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_objid.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ard_objid.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/************************************************************************/
/* get_objid */
/* Function to read an object identifier data element from an ASN.1 msg */
/* and put sub-identifiers into integer array. */
/************************************************************************/
#define MAX_OBJ_ID_COMPONENTS 16
ST_RET asn1r_get_objid (ASN1_DEC_CTXT *ac, ST_INT16 component_list[], ST_INT *num_components)
{
ST_UCHAR c; /* Temporary storage for octets. */
ST_UCHAR *last_pos; /* One past last position of this data element. */
ST_UINT16 j; /* Temporarily holds value encoded in 2 octets. */
ST_INT i; /* Counter for looping through sub-identifiers. */
#ifdef DEBUG_ASN1_DECODE
if (!num_components || !component_list)
{
slogCallStack (sLogCtrl,
"get_objid: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
last_pos = ac->asn1r_field_ptr + ac->asn1r_elmnt_len;
c = *(ac->asn1r_field_ptr++); /* First 2 subIDs reside in 1st octet. */
if (c & 0x80)
{
ALOG_NERR0 ("ASN.1 decode: Object ID first octet error");
return (SD_FAILURE);
}
if ((component_list[0] = c/40) > 2)
{
ALOG_NERR0 ("ASN.1 decode: Object ID component 0 too big");
return (SD_FAILURE);
}
if ((component_list[1] = c%40) > 39)
{
ALOG_NERR0 ("ASN.1 decode: Object ID component 1 too big");
return (SD_FAILURE);
}
*num_components = 2;
/* Decode remaining subIDs in contents of object identifier data el't. */
for (i=2; ac->asn1r_field_ptr < last_pos; i++,(*num_components)++)
{
if (i >= MAX_OBJ_ID_COMPONENTS) /* avoid overwrite */
{
ALOG_NERR0 ("ASN.1 decode: Object ID too many components");
return (SD_FAILURE);
}
if ((c = *(ac->asn1r_field_ptr++)) & 0x80) /* if next octet is not last - */
{
if (*ac->asn1r_field_ptr & 0x80) /* reject if more than 2 octets */
{
ALOG_NERR0 ("ASN.1 decode: Object ID more than 2 octets for value");
return (SD_FAILURE);
}
j = (ST_UINT16) (c & 0x7F) << 7; /* support two octets per subID */
j |= (*(ac->asn1r_field_ptr++) & 0x7F); /* merge the 14 ID bits */
component_list[i] = j;
}
else /* only one octet */
component_list[i] = (ST_UINT16) c; /* write masked ID code */
}
return(SD_SUCCESS);
}

188
mmslib/asn1/ard_ostr.c Normal file
View File

@@ -0,0 +1,188 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2006, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_ostr.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 07/20/09 JRB 10 Enable constructed octetstring code ALWAYS. */
/* 07/02/07 JRB 09 Chg ..fixlen, ..varlen arg to (ST_UCHAR *). */
/* 07/10/06 EJV 08 Add casting to elim warnings on Sun. */
/* 12/05/05 JRB 07 Add asn1r_get_octstr_fixlen,asn1r_get_octstr_varlen*/
/* 03/17/04 RKR 06 Changed thisFileName */
/* 03/11/04 GLB 05 Remove "thisFileName" */
/* 03/05/02 JRB 04 Eliminate warnings. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ard_ostr.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#if defined(DEBUG_SISCO)
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
static ST_VOID _dec_octstr_cstr (ASN1_DEC_CTXT *ac, ST_UINT16 id_code);
/************************************************************************/
/* asn1r_get_octstr_fixlen */
/* Just like asn1r_get_octstr but checks the length for a */
/* "fixed length" octet string (len must exactly match expected len). */
/************************************************************************/
ST_RET asn1r_get_octstr_fixlen (ASN1_DEC_CTXT *aCtx, ST_UCHAR *ptr, ST_INT len)
{
ST_RET retcode;
if (aCtx->asn1r_elmnt_len != len)
{
ALOG_ERR2("ASN.1 decode: octet string len = %d does not match expected len = %d",
aCtx->asn1r_elmnt_len, len);
retcode = SD_FAILURE;
}
else
retcode = asn1r_get_octstr (aCtx, (ST_UCHAR *) ptr);
return (retcode);
}
/************************************************************************/
/* asn1r_get_octstr_varlen */
/* Just like asn1r_get_octstr but checks the length for a */
/* "variable length" octet string (len must be "<=" max len). */
/************************************************************************/
ST_RET asn1r_get_octstr_varlen (ASN1_DEC_CTXT *aCtx, ST_UCHAR *ptr, ST_INT maxlen, ST_INT *lenout)
{
ST_RET retcode;
if (aCtx->asn1r_elmnt_len > maxlen)
{
ALOG_ERR2("ASN.1 decode: octet string len = %d exceeds max len = %d",
aCtx->asn1r_elmnt_len, maxlen);
retcode = SD_FAILURE;
}
else
{
*lenout = aCtx->asn1r_elmnt_len;
retcode = asn1r_get_octstr (aCtx, (ST_UCHAR *) ptr);
}
return (retcode);
}
/************************************************************************/
/* get_octstr */
/* Function to read a primitive octet string from an ASN.1 message. */
/************************************************************************/
ST_RET asn1r_get_octstr (ASN1_DEC_CTXT *ac, ST_UCHAR *octptr)
{
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!octptr)
{
slogCallStack (sLogCtrl,
"get_octstr: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
if (ac->asn1r_elmnt_len) /* Treat normal case where there are data octets. */
{
for (i = ac->asn1r_elmnt_len; i; --i) /* Move octets to user storage area. */
*(octptr++) = *(ac->asn1r_field_ptr++);
}
ac->asn1r_octetcount = ac->asn1r_elmnt_len; /* Compute number of data octets. */
return (SD_SUCCESS);
}
/************************************************************************/
/* get_octstr_cstr */
/* Function to setup to get a constructed octet string. */
/************************************************************************/
ST_VOID asn1r_get_octstr_cstr (ASN1_DEC_CTXT *ac, ST_INT numoctets, ST_UCHAR *octptr)
{
#ifdef DEBUG_ASN1_DECODE
if (!octptr)
{
slogCallStack (sLogCtrl,
"get_octstr_cstr: attempt to reference through a NULL pointer");
return;
}
#endif
ac->_asn1_maxoctets = numoctets; /* max allowed # octets */
ac->_asn1_octetptr = octptr; /* pointer to user's storage area */
ac->asn1r_octetcount = 0; /* running octet count */
ac->asn1r_u_id_fun = _dec_octstr_cstr; /* universal until octstr done */
ac->asn1r_c_id_fun = asn1r_class_err; /* no more context */
ac->asn1r_a_id_fun = asn1r_class_err; /* or application */
ac->asn1r_p_id_fun = asn1r_class_err; /* or private */
ac->asn1r_save_method = ac->asn1r_decode_method;
ac->asn1r_decode_method = ASN1_CLASS_METHOD;
ac->_asn1r_fun_save = ac->asn1r_decode_done_fun; /* save the previous done fun */
ac->asn1r_decode_done_fun = asn1r_done_err; /* can't be done for now */
ac->_asn1r_cstr_done_save = ac->asn1r_c_done_fun[ac->asn1r_msg_level];
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = asn1r_chk_getcstr_done;
}
/************************************************************************/
/* _dec_octstr_cstr */
/* Function to decode asn.1 constructor octet strings */
/************************************************************************/
static ST_VOID _dec_octstr_cstr (ASN1_DEC_CTXT *ac, ST_UINT16 id_code)
{
ST_INT i;
ALOG_DEC0 ("_dec_octstr_cstr");
if ((id_code & OCT_CODE) != OCT_CODE)
{ /* Protocol error - invalid ID Code. */
ALOG_NERR0 ("ASN.1 decode: constructed octetstring, invalid tag");
asn1r_set_dec_err(ac, ASN1E_UNEXPECTED_TAG);
return;
}
if (ac->asn1r_constr_elmnt) /* Don't do anything for constructors. */
{
ac->asn1r_c_done_fun[ac->asn1r_msg_level] = NULL;
return;
}
ac->asn1r_octetcount += ac->asn1r_elmnt_len;
if (ac->asn1r_octetcount > ac->_asn1_maxoctets)
{ /* User error - overflowed user storage area. */
ALOG_NERR0 ("ASN.1 decode: constructed octetstring too long");
asn1r_set_dec_err(ac, ASN1E_OCTSTR_TOO_BIG);
return;
}
if (ac->asn1r_elmnt_len) /* Treat normal case where there are data octets. */
{
for (i = ac->asn1r_elmnt_len; i; --i) /* Move octets to user storage area. */
*(ac->_asn1_octetptr++) = *(ac->asn1r_field_ptr++);
}
return;
}

54
mmslib/asn1/ard_strn.c Normal file
View File

@@ -0,0 +1,54 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2001, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_strn.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 04 Remove "thisFileName" */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_strn.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* get_strn */
/* Reads character data from message into selected buffer. No error */
/* checking is done. The calling routine must verify that the buffer */
/* is big enough. Conversion from ASCII to local character represen- */
/* tation is not necessary for MS-DOS. */
/************************************************************************/
ST_VOID asn1r_get_strn (ASN1_DEC_CTXT *ac, ST_CHAR *ptr)
{
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_strn: attempt to reference through a NULL pointer");
return;
}
#endif
for (i = ac->asn1r_elmnt_len; i; --i)
*(ptr++) = (ST_CHAR) *(ac->asn1r_field_ptr++);
}

284
mmslib/asn1/ard_time.c Normal file
View File

@@ -0,0 +1,284 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2006, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_time.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 01/16/07 JRB 07 Fix err decoding time near "19700101000000Z" */
/* in timezone east of GMT by using usr_mkgmtime.*/
/* 03/23/06 EJV 06 Cast time_t var to (ST_ULONG) and use '%lu'. */
/* 07/26/02 EJV 05 Added code to skip fraction of a second. */
/* 12/20/01 JRB 04 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 11/19/01 EJV 03 Made asn1dec_figureDelta func static */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_time.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
#include "time_str.h" /* for usr_mkgmtime */
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* get_time */
/* Function to decode Generalized Time into MS-DOS time (= number of */
/* seconds since 00:00 Jan 1, 1970, GMT). */
/************************************************************************/
ST_RET asn1r_get_time (ASN1_DEC_CTXT *ac, time_t *decTimeTValue)
{
struct tm breakDown;
struct tm gStruTime;
ST_UCHAR *last_pos;
ST_CHAR time_comp[6];
ST_BOOLEAN adjustmetPos;
ST_INT adjust;
time_t resultantTimeT;
/* check to see if the pointer for returning is valid */
if (!decTimeTValue)
{
ALOG_ERR0 ("Required pointer passed to function is NULL, expecting non NULL time_t pointer");
return(SD_FAILURE);
}
ALOG_DEC0("Decode ASN1 generalized time string ");
last_pos = ac->asn1r_field_ptr + ac->asn1r_elmnt_len; /* 1 + last pos'n in data el't */
/* Determine the Year in this generalized time string */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[3] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[4] = 0;
/* Convert the year to a integer string */
breakDown.tm_year = (ST_INT16) atoi(time_comp);
breakDown.tm_year = breakDown.tm_year - 1900;
/* Determine the month in this generalized time string */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
/* Convert the month to a integer string */
breakDown.tm_mon = (ST_INT16) atoi(time_comp);
breakDown.tm_mon = breakDown.tm_mon - 1;
/* Determine the day of the month in this generalized time string */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
/* Convert the day of the month to a integer string */
breakDown.tm_mday = (ST_INT16) atoi(time_comp);
/* Determine the hour in this generalized time string */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
/* Convert the hour to a integer string */
breakDown.tm_hour = (ST_INT16) atoi(time_comp);
/* Determine the min in this generalized time string */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
/* Convert the min to a integer string */
breakDown.tm_min = (ST_INT16) atoi(time_comp);
/* Determine the sec in this generalized time string */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
/* Convert the sec to a integer string */
breakDown.tm_sec = (ST_INT16) atoi(time_comp);
/* Check to see if we have overrun */
if (ac->asn1r_field_ptr > last_pos)
return(SD_FAILURE);
/* Broken Down Time component's */
ALOG_CDEC0(" Broken Down Component's so far");
ALOG_CDEC1(" tm_sec %d",breakDown.tm_sec);
ALOG_CDEC1(" tm_min %d",breakDown.tm_min);
ALOG_CDEC1(" tm_hour %d",breakDown.tm_hour);
ALOG_CDEC1(" tm_mon %d",breakDown.tm_mon);
ALOG_CDEC1(" tm_year %d",breakDown.tm_year);
ALOG_CDEC1(" tm_mday %d",breakDown.tm_mday);
/* There maybe be a fraction of a second in the generalized time. */
/* Ignore the fraction value since we can not pass it currently up. */
if (*ac->asn1r_field_ptr == '.')
{
ac->asn1r_field_ptr++;
/* skip all digits after the period */
while (isdigit((ST_INT)(*ac->asn1r_field_ptr)) && ac->asn1r_field_ptr <= last_pos)
ac->asn1r_field_ptr++;
}
/* Actually break down the date and time as a local time*/
if (ac->asn1r_field_ptr == last_pos)
{
/* Place the known data into the fields */
gStruTime.tm_sec = breakDown.tm_sec;
gStruTime.tm_min = breakDown.tm_min;
gStruTime.tm_hour = breakDown.tm_hour;
gStruTime.tm_mon = breakDown.tm_mon;
gStruTime.tm_year = breakDown.tm_year;
gStruTime.tm_mday = breakDown.tm_mday;
gStruTime.tm_yday = 0;
gStruTime.tm_wday = 0;
gStruTime.tm_isdst = 0;
/* Ask for a make time */
resultantTimeT = mktime(&gStruTime);
if (resultantTimeT == (time_t)-1)
{
ALOG_ERR0 ("mktime function returned -1 for time");
return(SD_FAILURE);
}
ALOG_CDEC1("Local time Decode : First Pass %lu ", (ST_ULONG) resultantTimeT);
/* if the DST flag came up set, re run it with the DST flag */
if (gStruTime.tm_isdst == 1)
{
gStruTime.tm_sec = breakDown.tm_sec;
gStruTime.tm_min = breakDown.tm_min;
gStruTime.tm_hour = breakDown.tm_hour;
gStruTime.tm_mon = breakDown.tm_mon;
gStruTime.tm_year = breakDown.tm_year;
gStruTime.tm_mday = breakDown.tm_mday;
gStruTime.tm_yday = 0;
gStruTime.tm_wday = 0;
gStruTime.tm_isdst = 1;
resultantTimeT = mktime(&gStruTime);
if (resultantTimeT == (time_t)-1)
{
ALOG_ERR0 ("mktime function returned -1 for time");
return(SD_FAILURE);
}
ALOG_CDEC1("Local time Decode : Second Pass %lu ", (ST_ULONG) resultantTimeT);
}
ALOG_CDEC1("Local time Decode : Result %lu ", (ST_ULONG) resultantTimeT);
/* Now factor the Difference between GMT and local */
*decTimeTValue = resultantTimeT;
return (SD_SUCCESS);
}
/* Actually break down the date and time as a GMT based time with possible offset */
if ((*ac->asn1r_field_ptr == 'Z')||(*ac->asn1r_field_ptr == '+')||(*ac->asn1r_field_ptr == '-'))
{
/* Place the known data into the fields */
gStruTime.tm_sec = breakDown.tm_sec;
gStruTime.tm_min = breakDown.tm_min;
gStruTime.tm_hour = breakDown.tm_hour;
gStruTime.tm_mon = breakDown.tm_mon;
gStruTime.tm_year = breakDown.tm_year;
gStruTime.tm_mday = breakDown.tm_mday;
gStruTime.tm_yday = 0;
gStruTime.tm_wday = 0;
gStruTime.tm_isdst = 0;
/* Ask for a make time */
/* Convert "tm" struct to "time_t" assuming struct represents GMT time.*/
resultantTimeT = usr_mkgmtime(&gStruTime);
if (resultantTimeT == (time_t)-1)
{
ALOG_ERR0 ("usr_mkgmtime function returned -1 for time");
return(SD_FAILURE);
}
ALOG_CDEC1("GMT time Decode : Result %lu ", (ST_ULONG) resultantTimeT);
/* Now factor the Difference between GMT and local */
*decTimeTValue = resultantTimeT;
/* now if there are adjustment's to GMT */
if ((*ac->asn1r_field_ptr == '+')||(*ac->asn1r_field_ptr == '-'))
{
if (*ac->asn1r_field_ptr == '+')
{
ALOG_CDEC0("Doing a GMT based adjustment of (+) ");
adjustmetPos = SD_TRUE;
}
else
{
ALOG_CDEC0("Doing a GMT based adjustment of (-) ");
adjustmetPos = SD_FALSE;
}
ac->asn1r_field_ptr++;
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
adjust = atoi(time_comp);
ALOG_CDEC1("Adjust by Hours %d ",adjust);
if (adjustmetPos == SD_TRUE)
*decTimeTValue += (time_t) (adjust*(60 * 60)); /* adjust hrs */
else
*decTimeTValue -= (time_t) (adjust*(60 * 60)); /* adjust hrs */
time_comp[0] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[1] = (ST_CHAR)*ac->asn1r_field_ptr++;
time_comp[2] = 0;
adjust = atoi(time_comp);
ALOG_CDEC1("Adjust by Minutes %d ",adjust);
if (adjustmetPos == SD_TRUE)
*decTimeTValue += (time_t) (adjust*(60)); /* adjust min */
else
*decTimeTValue -= (time_t) (adjust*(60)); /* adjust min */
ALOG_CDEC1("GMT time Decode with offset : Result %lu ", (ST_ULONG) (*decTimeTValue));
return (SD_SUCCESS);
}
else
{
ac->asn1r_field_ptr++; /* Skip the 'Z' */
return (SD_SUCCESS);
}
} /* end of GMT based Time */
/* if the string to decode does not end in nothing, "Z", "+", "-" */
/* then return failure and dump the string */
ALOG_ERR0 ("Time string cannot be decoded by this ASN1 function");
return(SD_FAILURE);
}

80
mmslib/asn1/ard_utc.c Normal file
View File

@@ -0,0 +1,80 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2004, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_utc.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : Decode MMS UtcTime */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/16/04 EJV 05 Added ST_(U)LONG typecast to logs,on some sys*/
/* ST_(U)INT32 can be (unsigned) long or int. */
/* 07/26/02 EJV 04 Time Quality byte chg position to lowest. */
/* Added logging. */
/* 07/03/02 EJV 03 MMS_UTC_TIME: chg name usec to fraction. */
/* 12/20/01 JRB 02 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 11/09/01 EJV 01 New module, derived from ard_btod.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* asn1r_get_utc_time */
/************************************************************************/
ST_RET asn1r_get_utc_time (ASN1_DEC_CTXT *ac, MMS_UTC_TIME *dest)
{
#ifdef DEBUG_ASN1_DECODE
if (!dest)
{
slogCallStack (sLogCtrl,
"asn1r_get_utc_time: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
ALOG_DEC0("Decoding UtcTime");
/* Read the number of seconds since January 1, 1970 (4 bytes) */
dest->secs = (((ST_UINT32) *(ac->asn1r_field_ptr++)) << 24) & 0xFF000000L;
dest->secs |= (((ST_UINT32) *(ac->asn1r_field_ptr++)) << 16) & 0x00FF0000L;
dest->secs |= (((ST_UINT32) *(ac->asn1r_field_ptr++)) << 8) & 0x0000FF00L;
dest->secs |= ((ST_UINT32) *(ac->asn1r_field_ptr++)) & 0x000000FFL;
/* read fraction of a second (3 bytes) */
dest->fraction = (((ST_UINT32) *(ac->asn1r_field_ptr++)) << 16) & 0x00FF0000L;
dest->fraction |= (((ST_UINT32) *(ac->asn1r_field_ptr++)) << 8) & 0x0000FF00L;
dest->fraction |= ((ST_UINT32) *(ac->asn1r_field_ptr++)) & 0x000000FFL;
/* read the quality flags (1 byte) */
dest->qflags = ((ST_UINT32) *(ac->asn1r_field_ptr++));
ALOG_CDEC1("seconds: %lu", (ST_ULONG) dest->secs);
ALOG_CDEC1("fraction: %lu", (ST_ULONG) dest->fraction);
ALOG_CDEC1("quality: 0x%lX", (ST_ULONG) dest->qflags);
return (SD_SUCCESS);
}

214
mmslib/asn1/ard_vstr.c Normal file
View File

@@ -0,0 +1,214 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2004, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : ard_vstr.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 12/05/05 JRB 09 Add asn1r_get_vstr_maxlen. */
/* 03/22/05 JRB 08 Fix cast in log macro. */
/* 01/16/04 EJV 07 Added typecast to elim warning on AIX. */
/* 09/24/03 JRB 06 Fix to properly decode 0-length UTF8string. */
/* 04/22/03 JRB 05 Allow fixed len UTF8 only if local fmt=UTF16.*/
/* 04/02/03 JRB 04 Add UTF8string support (asn1r_get_utf8) */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_DEC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ad_vstr.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include <ctype.h>
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* asn1r_get_vstr_maxlen */
/* Just like asn1r_get_vstr but checks the string length. */
/* NOTE: caller's buffer must be 1 byte bigger than max_len to allow */
/* room for NULL terminator. */
/************************************************************************/
ST_RET asn1r_get_vstr_maxlen (ASN1_DEC_CTXT *aCtx, ST_CHAR *ptr, ST_INT max_len)
{
if (aCtx->asn1r_elmnt_len > max_len)
{
ALOG_ERR0("ASN.1 decode: visible string too long");
return (SD_FAILURE);
}
else
return (asn1r_get_vstr (aCtx, ptr));
}
/************************************************************************/
/* get_vstr */
/* Reads visible character data from message into selected buffer. If */
/* character is encountered which is not valid for ASN.1 VisibleString */
/* type, error code will be returned as function return value. Other- */
/* wise, function return value will be zero. The calling function must */
/* verify that buffer is big enough. Conversion from ASCII to local */
/* character representation is not necessary for MS-DOS. */
/************************************************************************/
ST_RET asn1r_get_vstr (ASN1_DEC_CTXT *ac, ST_CHAR *ptr)
{
ST_INT i;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_vstr: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
for (i = ac->asn1r_elmnt_len; i; --i)
{
*ptr = (ST_CHAR) *(ac->asn1r_field_ptr++); /* Move character to user buffer. */
if (*ptr < ' ') /* Check that character is not a control char. */
{
ALOG_NERR1 ("ASN.1 decode: invalid character (0x%02x) in visible string",
(ST_UINT)(ST_UCHAR) *ptr); /* 2 casts to avoid sign extension*/
return (SD_FAILURE);
}
ptr++;
}
*ptr = '\x00'; /* Null terminate the visible string. */
return(SD_SUCCESS); /* If no problelms, return success. */
}
/************************************************************************/
/* asn1r_get_utf8 */
/* Reads Unicode UTF8 string data from message into selected buffer. If */
/* character is encountered which is not valid for ASN.1 UTF8string */
/* type, error code will be returned as function return value. Other- */
/* wise, function return value will be zero. The calling function must */
/* verify that buffer is big enough. */
/************************************************************************/
ST_RET asn1r_get_utf8 (ASN1_DEC_CTXT *aCtx, ST_CHAR *ptr, ST_INT el_len)
{
ST_INT dst_len, local_len;
#ifdef DEBUG_ASN1_DECODE
if (!ptr)
{
slogCallStack (sLogCtrl,
"get_utf8: attempt to reference through a NULL pointer");
return(SD_FAILURE);
}
#endif
/* Convert from UTF8 to local format. Input is NOT NULL terminated.
* abs (el_len) = maximum number of Unicode "characters".
* Multiply by the maximum size of each Unicode "character".
*/
#if (UNICODE_LOCAL_FORMAT==UNICODE_UTF16)
dst_len = abs(el_len)*2;
#else /* default is UTF8 */
dst_len = abs(el_len)*4;
#endif
local_len = asn1r_utf8_to_local (ptr, dst_len, (ST_CHAR *) aCtx->asn1r_field_ptr, aCtx->asn1r_elmnt_len);
if (local_len < 0)
{
ALOG_NERR0 ("ASN.1 decode: UTF8 to local conversion failed");
return(SD_FAILURE);
}
/* If this is "fixed length" (el_len>0), length must match. */
#if (UNICODE_LOCAL_FORMAT==UNICODE_UTF16)
if (el_len > 0 && el_len*2 != local_len) /* Fixed len string */
{
ALOG_NERR2 ("ASN.1 decode: expected UTF8string%d, received UTF8string%d",
el_len, local_len/2);
return (SD_FAILURE);
}
*(ST_UINT16*)(ptr+local_len) = 0; /* add "2 byte" NULL */
#else /* default is UTF8 */
if (el_len > 0) /* Fixed len string */
{
/* This error should never occur because no way to define fixed len UTF8.*/
ALOG_ERR0 ("ASN.1 decode: 'FIXED LENGTH' UTF8string not supported on this platform");
return (SD_FAILURE);
}
ptr[local_len] = '\0'; /* add NULL */
#endif
aCtx->asn1r_field_ptr += aCtx->asn1r_elmnt_len; /* Update decode ptr*/
return(SD_SUCCESS);
}
#if (UNICODE_LOCAL_FORMAT==UNICODE_UTF16)
#if defined(_WIN32)
#include <windows.h>
/************************************************************************/
/* On Windows, the local format is UTF16, so this function converts */
/* from UTF8 string to UTF16 string. */
/* CRITICAL: "dst" is NOT automatically NULL terminated, so calling */
/* function must do so if necessary. */
/* dst_len = num bytes in dst "UTF16" string. */
/* src_len = num bytes in src "UTF8" string. */
/************************************************************************/
ST_INT asn1r_utf8_to_local (ST_CHAR *dst, ST_INT dst_len, ST_CHAR *src, ST_INT src_len)
{
int ret;
ST_UINT16 *dst_utf16 = (ST_UINT16 *) dst;
/* This function expects the max number of UTF16 chars (2 bytes per char)
* in the last arg, so divide "dst_len" by 2.
* It does NOT automatically NULL terminate, so neither does this function.
* It returns the number of UTF16 chars converted, so we multiply the
* return value by 2 to return the number of bytes.
*/
/*renxiaobao UTF8<46><38><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>޸<EFBFBD>*/
#ifdef WIN32
memcpy(dst,src,src_len); return src_len;
#else
ret = MultiByteToWideChar (CP_UTF8, 0,
src, src_len, dst_utf16, dst_len/2);
if (ret >= 0)
return (ret*2); /* success */
return (-1); /* error */
#endif
}
#else /* All other systems */
#error Unicode UTF16 currently only supported on Windows
#endif
#else /* UNICODE_LOCAL_FORMAT==UNICODE_UTF8 */
/************************************************************************/
/* This function should work on any system where the local Unicode */
/* format is UTF8. The ASN.1 format is also UTF8, so this function */
/* basically just copies the string. */
/* CRITICAL: dst_len must be >= src_len */
/************************************************************************/
ST_INT asn1r_utf8_to_local (ST_CHAR *dst, ST_INT dst_len, ST_CHAR *src, ST_INT src_len)
{
if (dst_len >= src_len) /* make sure dst has room */
{
if (src_len > 0)
memcpy (dst, src, src_len);
return (src_len); /* success */
}
return (-1); /* error */
}
#endif /* UNICODE_LOCAL_FORMAT==UNICODE_UTF8 */

48
mmslib/asn1/are_bool.c Normal file
View File

@@ -0,0 +1,48 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_bool.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 06 Remove "thisFileName" */
/* 01/14/03 JRB 05 Avoid redundant logging of encode overrun. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_bool.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/************************************************************************/
/* wr_bool */
/************************************************************************/
ST_VOID asn1r_wr_bool (ASN1_ENC_CTXT *ac, ST_BOOLEAN data)
{
if (ac->asn1r_field_ptr - 1 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
*(ac->asn1r_field_ptr--) = (ST_UCHAR) data;
}

74
mmslib/asn1/are_bstr.c Normal file
View File

@@ -0,0 +1,74 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_bstr.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 04/09/08 JRB 08 Fail encode if Bstring len < 0. */
/* 03/11/04 GLB 07 Remove "thisFileName" */
/* 01/14/03 JRB 06 Avoid redundant logging of encode overrun. */
/* 03/05/02 JRB 05 Eliminate warnings. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_bstr.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* wr_bitstr */
/************************************************************************/
ST_VOID asn1r_wr_bitstr (ASN1_ENC_CTXT *ac, ST_UCHAR *bitPtr, ST_INT numBits)
{
ST_INT bitsLeft;
ST_INT numBytes;
if (numBits < 0)
{
ALOG_ERR0 ("ASN.1 Bitstring encode: Length < 0 not allowed");
/* This is not really an overrun, but the overrun flag is the only */
/* thing checked by the caller to detect an encoding error. */
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
numBytes = numBits/8; /* calculate the total # bytes req'd */
if ((bitsLeft = numBits % 8)!=0) /* get remainder */
numBytes++;
if (ac->asn1r_field_ptr - numBytes < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
ac->asn1r_field_ptr -= numBytes;
memcpy (ac->asn1r_field_ptr+1, bitPtr, numBytes);
if (bitsLeft) /* write the unused-bits octet */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (8 - bitsLeft);
else
*(ac->asn1r_field_ptr--) = 0;
}

58
mmslib/asn1/are_btod.c Normal file
View File

@@ -0,0 +1,58 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_btod.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 06 Remove "thisFileName" */
/* 01/14/03 JRB 05 Avoid redundant logging of encode overrun. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_btod.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* wr_btod */
/************************************************************************/
ST_VOID asn1r_wr_btod (ASN1_ENC_CTXT *ac, MMS_BTOD *data)
{
/* check for overun of buffer */
if (ac->asn1r_field_ptr - 6 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
if (data->form == MMS_BTOD6)
{
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (data->day & 0xFF); /* low byte */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->day >> 8) & 0xFF);/* high byte */
}
/* In any case, calculate and write the time component of the TimeOfDay */
/* value. */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (data->ms & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->ms >> 8) & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->ms >> 16) & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->ms >> 24) & 0xFF);
}

43
mmslib/asn1/are_delm.c Normal file
View File

@@ -0,0 +1,43 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_delmn.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 05 Remove "thisFileName" */
/* 01/22/02 JRB 04 Chg asn1r_field_start to asn1r_field_end. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_delmn.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* wr_delmnt */
/* Function to write an entire data element to a message being built. */
/* Useful when another layer of software encodes a data element to be */
/* inserted into the current message. */
/************************************************************************/
ST_VOID asn1r_wr_delmnt (ASN1_ENC_CTXT *ac, ST_UCHAR *bufPtr, ST_INT bufLen)
{
asn1r_wr_octstr (ac, bufPtr, bufLen);
ac->asn1r_field_end = ac->asn1r_field_ptr;
}

122
mmslib/asn1/are_flt.c Normal file
View File

@@ -0,0 +1,122 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_float.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 08 Remove "thisFileName" */
/* 01/14/03 JRB 07 Avoid redundant logging of encode overrun. */
/* 02/19/03 JRB 06 Use SD_BYTE_ORDER. */
/* 02/19/03 JRB 05 Del VAX VMS support. For ALPHA VMS, assume */
/* compiler option /FLOAT=IEEE_FLOAT is used */
/* so it behaves like other systems. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_float.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* wr_float */
/* Function to convert a value of the single precision "float" type to */
/* the MMS floating point type (of length 5 octets) and write it to the */
/* message being constructed. The encoded floating point value is in */
/* the standard IEEE 754 single precision floating point format with */
/* the additional exponent width octet. */
/************************************************************************/
ST_VOID asn1r_wr_float (ASN1_ENC_CTXT *ac, ST_FLOAT in)
{
ST_UCHAR *ptr;
ST_FLOAT f;
if (ac->asn1r_field_ptr - 5 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
#if defined(__OS2__)
ptr = (ST_UCHAR *) &in;
#else
f = (ST_FLOAT) in;
ptr = (ST_UCHAR *) &f;
#endif
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
f = (ST_FLOAT) in;
ptr = (ST_UCHAR *) &f;
ptr += 3;
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
#else
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
#endif
*(ac->asn1r_field_ptr--) = *ptr;
*(ac->asn1r_field_ptr--) = (ST_UCHAR)'\x08';
}
/************************************************************************/
/* wr_double */
/* Function to convert a value of the double precision "double" type to */
/* the MMS floating point type (of length 9 octets) and write it to the */
/* message being constructed. The encoded floating point value is in */
/* the standard IEEE 754 double precision floating point format with */
/* the additional exponent width octet. */
/************************************************************************/
ST_VOID asn1r_wr_double (ASN1_ENC_CTXT *ac, ST_DOUBLE in)
{
ST_UCHAR *ptr;
if (ac->asn1r_field_ptr - 9 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
#if SD_BYTE_ORDER==SD_BIG_ENDIAN /* big-endian (like Motorola) */
ptr = (ST_UCHAR *) &in + 7;
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
*(ac->asn1r_field_ptr--) = *(ptr--);
#else
ptr = (ST_UCHAR *) &in;
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
*(ac->asn1r_field_ptr--) = *(ptr++);
#endif
*(ac->asn1r_field_ptr--) = *ptr;
*(ac->asn1r_field_ptr--) = (ST_UCHAR)'\x0B';
}

241
mmslib/asn1/are_int.c Normal file
View File

@@ -0,0 +1,241 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_int.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 08 Remove "thisFileName" */
/* 01/14/03 JRB 07 Avoid redundant logging of encode overrun. */
/* 01/22/02 JRB 06 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 05 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 11/12/01 EJV 04 Fixed function name asn1r_wr_i64 */
/* 09/26/00 JRB 03 Add another #ifdef INT64_SUPPORT */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_int.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* Local functions in this module */
/* These are not static because we may want to use them in macro's */
/* to speed things up some time in the future. */
ST_VOID asn1r_wr_int32 (ASN1_ENC_CTXT *ac, ST_INT32 data, ST_BOOLEAN positive);
#ifdef INT64_SUPPORT
ST_VOID asn1r_wr_int64 (ASN1_ENC_CTXT *ac, ST_INT64 data, ST_BOOLEAN positive);
#endif
/************************************************************************/
/* wr_i8 */
/************************************************************************/
ST_VOID asn1r_wr_i8 (ASN1_ENC_CTXT *ac, ST_INT8 data)
{
asn1r_wr_int32 (ac, (ST_INT32) data, (ST_BOOLEAN) (data >= 0 ? SD_TRUE : SD_FALSE));
}
/************************************************************************/
/* wr_i16 */
/* Function to write a 16-bit integer into message being constructed. */
/* Can handle values to 16 bits. Sets asn1_field_ptr to next position. */
/************************************************************************/
ST_VOID asn1r_wr_i16 (ASN1_ENC_CTXT *ac, ST_INT16 data)
{
asn1r_wr_int32 (ac, (ST_INT32) data, (ST_BOOLEAN) (data >= 0 ? SD_TRUE : SD_FALSE));
}
/************************************************************************/
/* wr_i32 */
/************************************************************************/
ST_VOID asn1r_wr_i32 (ASN1_ENC_CTXT *ac, ST_INT32 data)
{
asn1r_wr_int32 (ac, data, (ST_BOOLEAN) (data >= 0 ? SD_TRUE : SD_FALSE));
}
/************************************************************************/
/* wr_u8 */
/************************************************************************/
ST_VOID asn1r_wr_u8 (ASN1_ENC_CTXT *ac, ST_UINT8 data)
{
asn1r_wr_int32 (ac, (ST_INT32) data, SD_TRUE);
}
/************************************************************************/
/* wr_u16 */
/************************************************************************/
ST_VOID asn1r_wr_u16 (ASN1_ENC_CTXT *ac, ST_UINT16 data)
{
asn1r_wr_int32 (ac, (ST_INT32) data, SD_TRUE);
}
/************************************************************************/
/* wr_u32 */
/************************************************************************/
ST_VOID asn1r_wr_u32 (ASN1_ENC_CTXT *ac, ST_UINT32 data)
{
asn1r_wr_int32 (ac, (ST_INT32) data, SD_TRUE);
}
/************************************************************************/
/* _wr_int32 */
/************************************************************************/
ST_VOID asn1r_wr_int32 (ASN1_ENC_CTXT *ac, ST_INT32 data, ST_BOOLEAN positive)
{
ST_INT i;
if (ac->asn1r_field_ptr - 5 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
/* First just write all 32 bits into the message */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) data;
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 8);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 16);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 24);
if (positive)
{
/* ASN.1 requires us to eliminate redundant leading zero's, and */
/* we need to make sure the MSB is not set in the high order byte */
if (*(ac->asn1r_field_ptr + 1) & 0x80)
*(ac->asn1r_field_ptr--) = 0x00;
else
{
for (i = 0; i < 3; ++i)
{
if ((*(ac->asn1r_field_ptr + 1) == 0x00) &&
(!(*(ac->asn1r_field_ptr + 2) & 0x80)))
{
++ac->asn1r_field_ptr;
}
else
break;
}
}
}
else /* The data value is negative */
{
/* ASN.1 requires us to eliminate redundant leading 0xFF's, and */
/* we need to make sure that the MSB is set in the high order byte */
for (i = 0; i < 3; ++i)
{
if ((*(ac->asn1r_field_ptr + 1) == 0xFF) &&
(*(ac->asn1r_field_ptr + 2) & 0x80))
{
++ac->asn1r_field_ptr;
}
else
break;
}
}
}
/************************************************************************/
/************************************************************************/
#ifdef INT64_SUPPORT
/************************************************************************/
/* wr_i64 */
/************************************************************************/
ST_VOID asn1r_wr_i64 (ASN1_ENC_CTXT *ac, ST_INT64 data)
{
asn1r_wr_int64 (ac, (ST_INT64) data, (ST_BOOLEAN) (data >= 0 ? SD_TRUE : SD_FALSE));
}
ST_VOID asn1r_wr_u64 (ASN1_ENC_CTXT *ac, ST_UINT64 data)
{
asn1r_wr_int64 (ac, (ST_INT64) data, SD_TRUE);
}
/************************************************************************/
/* _wr_int64 */
/************************************************************************/
ST_VOID asn1r_wr_int64 (ASN1_ENC_CTXT *ac, ST_INT64 data, ST_BOOLEAN positive)
{
ST_INT i;
if (ac->asn1r_field_ptr - 9 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
*(ac->asn1r_field_ptr--) = (ST_UCHAR) data;
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 8);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 16);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 24);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 32);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 40);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 48);
*(ac->asn1r_field_ptr--) = (ST_UCHAR)(data >> 56);
if (positive)
{
/* ASN.1 requires us to eliminate redundant leading zero's, and */
/* we need to make sure the MSB is not set in the high order byte */
if (*(ac->asn1r_field_ptr + 1) & 0x80)
*(ac->asn1r_field_ptr--) = 0x00;
else
{
for (i = 0; i < 7; ++i)
{
if ((*(ac->asn1r_field_ptr + 1) == 0x00) &&
(!(*(ac->asn1r_field_ptr + 2) & 0x80)))
{
++ac->asn1r_field_ptr;
}
else
break;
}
}
}
else /* The data value is negative */
{
/* ASN.1 requires us to eliminate redundant leading 0xFF's, and */
/* we need to make sure that the MSB is set in the high order byte */
for (i = 0; i < 7; ++i)
{
if ((*(ac->asn1r_field_ptr + 1) == 0xFF) &&
(*(ac->asn1r_field_ptr + 2) & 0x80))
{
++ac->asn1r_field_ptr;
}
else
break;
}
}
}
/************************************************************************/
#endif /* #ifdef INT64_SUPPORT */
/************************************************************************/

80
mmslib/asn1/are_objd.c Normal file
View File

@@ -0,0 +1,80 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_objid.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/11/04 GLB 07 Remove "thisFileName" */
/* 01/14/03 JRB 06 Avoid redundant logging of encode overrun. */
/* 03/05/02 JRB 05 Eliminate warnings. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_objid.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* Static functions in this module */
static ST_VOID _wr_component (ASN1_ENC_CTXT *ac, ST_INT16);
/************************************************************************/
/* wr_objid */
/* Function to write an object identifier data element to a message */
/* being built. */
/************************************************************************/
ST_VOID asn1r_wr_objid (ASN1_ENC_CTXT *ac, ST_INT16 component_list[], ST_INT num_components)
{
ST_INT i;
ST_INT16 icomp;
for (i = num_components - 1; i > 1; i--)
_wr_component(ac, component_list[i]);
icomp = component_list[1] + component_list[0]*40;
_wr_component(ac, icomp);
}
/************************************************************************/
/* _wr_component */
/* Function to write an integer to a field of octets in the following */
/* format: [1xxxxxxx] ... 0xxxxxxx , where all but the last */
/* octet starts with a 1 bit, and where the x's are the bits of the */
/* binary integer input to the function (distributed 7 bits per octet).*/
/************************************************************************/
static ST_VOID _wr_component (ASN1_ENC_CTXT *ac, ST_INT16 icomp)
{
if (ac->asn1r_field_ptr -2 < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
if (icomp < 0x80)
*(ac->asn1r_field_ptr--) = (ST_UCHAR) icomp;
else
{
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (icomp & 0x7F);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (((icomp >> 7) & 0x7F) | 0x80);
}
}

61
mmslib/asn1/are_ostr.c Normal file
View File

@@ -0,0 +1,61 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2002, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_ostr.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 04/09/08 JRB 08 Fail encode if Ostring len < 0. */
/* 08/01/05 JRB 07 Add const on asn1_wr_octstr args. */
/* 03/11/04 GLB 06 Remove "thisFileName" */
/* 01/14/03 JRB 05 Avoid redundant logging of encode overrun. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_ostr.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* wr_octstr */
/* Function to write a primitive octet string to a message being built. */
/************************************************************************/
ST_VOID asn1r_wr_octstr (ASN1_ENC_CTXT *ac, const ST_UCHAR *octPtr, ST_INT numOctets)
{
if (numOctets < 0)
{
ALOG_ERR0 ("ASN.1 Octetstring encode: Length < 0 not allowed");
/* This is not really an overrun, but the overrun flag is the only */
/* thing checked by the caller to detect an encoding error. */
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
if (ac->asn1r_field_ptr - numOctets < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
ac->asn1r_field_ptr -= numOctets;
memcpy (ac->asn1r_field_ptr+1, octPtr, numOctets);
}

88
mmslib/asn1/are_time.c Normal file
View File

@@ -0,0 +1,88 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2006, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_time.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/23/06 EJV 07 Cast time_t var to (ST_ULONG) and use '%lu'. */
/* 01/14/03 JRB 06 Avoid redundant logging of encode overrun. */
/* 07/29/02 EJV 05 Log tmp_buf instead of ac->asn1r_field_ptr. */
/* 01/22/02 JRB 04 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_time.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/* for wr_time the length of the string */
#define ASN1_WR_TIME_ENC_L 15
/************************************************************************/
/* wr_time */
/* Function to encode date and time from MS-DOS time (= number of */
/* seconds from 00:00 Jan 1, 1970, GMT) to the ASN.1 Generalized time */
/************************************************************************/
ST_VOID asn1r_wr_time (ASN1_ENC_CTXT *ac, time_t toEncodeTime)
{
struct tm *gmtTime;
ST_UCHAR tmp_buf [ASN1_WR_TIME_ENC_L + 1];
ALOG_ENC0("Encoding a GMT Zulu based time string");
/* check to see if the ASN1 field pointer will overflow the buffer */
if (ac->asn1r_field_ptr - ASN1_WR_TIME_ENC_L < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
/* move the asn1 field ptr backward in the buffer */
ac->asn1r_field_ptr = ac->asn1r_field_ptr - (ASN1_WR_TIME_ENC_L-1);
ALOG_CENC1("Passed Unix epoche based GMT time is (in) = %lu", (ST_ULONG) toEncodeTime);
/*renxiaobao <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>*/
if(toEncodeTime<0x12cea600) toEncodeTime = 0x12cea600; /*1980*/
gmtTime = gmtime(&toEncodeTime);
if(gmtTime)
{
/* encode a local time string */
strftime ((ST_CHAR *)tmp_buf,ASN1_WR_TIME_ENC_L + 1,"%Y%m%d%H%M%SZ",gmtTime);
}
else
{
sprintf(tmp_buf,"19800001000000Z");
printf("gmtime fail toEncodeTime=%lx\n",toEncodeTime);
}
/* encode a local time string */
/*strftime ((ST_CHAR *)tmp_buf,ASN1_WR_TIME_ENC_L + 1,"%Y%m%d%H%M%SZ",gmtTime);*/
memcpy (ac->asn1r_field_ptr, tmp_buf, ASN1_WR_TIME_ENC_L); /* no 0x00 copied */
ALOG_CENC1("ASN1 encoded String %s", tmp_buf);
/* move the field pointer 1 more position back in the encode buffer */
ac->asn1r_field_ptr = ac->asn1r_field_ptr -1;
}

82
mmslib/asn1/are_utc.c Normal file
View File

@@ -0,0 +1,82 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2004, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_utc.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : Encode MMS UtcTime */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 03/16/04 EJV 07 Added ST_(U)LONG typecast to logs,on some sys*/
/* ST_(U)INT32 can be (unsigned) long or int. */
/* 01/14/03 JRB 06 Avoid redundant logging of encode overrun. */
/* 07/26/02 EJV 05 Time Quality byte chg position to lowest. */
/* Added logging. */
/* 07/03/02 EJV 04 MMS_UTC_TIME: chg name usec to fraction. */
/* 01/22/02 JRB 03 Chg asn1r_end_of_buffer to asn1r_buf_start. */
/* 12/20/01 JRB 02 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 11/08/01 EJV 01 New module, derived from are_btod.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* asn1r_wr_utc_time */
/************************************************************************/
ST_VOID asn1r_wr_utc_time (ASN1_ENC_CTXT *ac, MMS_UTC_TIME *data)
{
#define _ASN1R_UTCTIME_LEN 8
ALOG_ENC0("Encoding UtcTime");
/* check for overun of buffer (UtcTime is encoded on 8 bytes) */
if (ac->asn1r_field_ptr - _ASN1R_UTCTIME_LEN < ac->asn1r_buf_start)
{
ac->asn1r_encode_overrun = SD_TRUE;
return;
}
ALOG_CENC1("seconds: %lu", (ST_ULONG) data->secs);
ALOG_CENC1("fraction: %lu", (ST_ULONG) data->fraction);
ALOG_CENC1("quality: 0x%lX", (ST_ULONG) data->qflags);
/* write the quality flags */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) data->qflags;
/* write fraction of a second (3 bytes) */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (data->fraction & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->fraction >> 8) & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->fraction >> 16) & 0xFF);
/* write the number of seconds since January 1, 1970 */
*(ac->asn1r_field_ptr--) = (ST_UCHAR) (data->secs & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->secs >> 8) & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->secs >> 16) & 0xFF);
*(ac->asn1r_field_ptr--) = (ST_UCHAR) ((data->secs >> 24) & 0xFF);
ALOG_CENC1("Encoded %d bytes:", _ASN1R_UTCTIME_LEN);
ALOG_ENCH(_ASN1R_UTCTIME_LEN, ac->asn1r_field_ptr + 1);
}

162
mmslib/asn1/are_vstr.c Normal file
View File

@@ -0,0 +1,162 @@
/************************************************************************/
/* SISCO SOFTWARE MODULE HEADER *****************************************/
/************************************************************************/
/* (c) Copyright Systems Integration Specialists Company, Inc., */
/* 1986 - 2004, All Rights Reserved. */
/* */
/* PROPRIETARY AND CONFIDENTIAL */
/* */
/* MODULE NAME : are_vstr.c */
/* PRODUCT(S) : ASN1DE */
/* */
/* MODULE DESCRIPTION : */
/* */
/* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
/* */
/* MODIFICATION LOG : */
/* Date Who Rev Comments */
/* -------- --- ------ ------------------------------------------- */
/* 08/01/05 JRB 09 Add const on asn1_wr_vstr args. */
/* 03/11/04 GLB 08 Added "ifdef DEBUG_SISCO" to "thisFileName" */
/* 01/16/04 EJV 07 Added typecast to elim warning on AIX. */
/* 01/14/03 JRB 06 Avoid redundant logging of encode overrun. */
/* 09/24/03 JRB 05 Fix to properly encode 0-length UTF8string. */
/* 04/02/03 JRB 04 Add UTF8string support (asn1r_wr_utf8) */
/* 12/20/01 JRB 03 Chg ASN1_CTXT to ASN1_ENC_CTXT. */
/* 09/13/99 MDE 02 Added SD_CONST modifiers */
/* 07/26/99 MDE 01 New module, derived from ae_vstr.c */
/************************************************************************/
#include "glbtypes.h"
#include "sysincs.h"
#include "asn1r.h"
#include "asn1log.h"
/************************************************************************/
/* For debug version, use a static pointer to avoid duplication of */
/* __FILE__ strings. */
#ifdef DEBUG_SISCO
SD_CONST static ST_CHAR *SD_CONST thisFileName = __FILE__;
#endif
/************************************************************************/
/* wr_vstr */
/************************************************************************/
ST_VOID asn1r_wr_vstr (ASN1_ENC_CTXT *ac, const ST_CHAR *ptr)
{
asn1r_wr_octstr (ac, (ST_UCHAR*)ptr,strlen (ptr));
}
/************************************************************************/
/* asn1r_wr_utf8 */
/************************************************************************/
ST_RET asn1r_wr_utf8 (ASN1_ENC_CTXT *aCtx, ST_CHAR *ptr, ST_INT el_len)
{
ST_CHAR *utf8_ptr; /* temporary place to encode UTF8string. */
ST_INT utf8_len;
/* This code is a little tricky. Since we encode backwards, the data must
* be written before the current "ASN1_ENC_PTR". Since we don't know
* the len of the data until after the conversion (asn1r_local_to_utf8),
* we allow for the maximum converted size, then after the conversion, we move
* the data forward to just before "ASN1_ENC_PTR".
*/
/* Compute maximum converted size.
* abs (el_len) = maximum number of Unicode "characters".
* Multiply by the maximum size of each Unicode "character" (4).
*/
utf8_len = (abs(el_len)*4); /* 4 bytes per char */
/* Point to safe spot in ASN.1 encode buffer where maximum size
* UTF8string can be encoded (including NULL terminator).
*/
utf8_ptr = (ST_CHAR *) ASN1_ENC_PTR(aCtx) - utf8_len;
if (utf8_ptr < (ST_CHAR *) aCtx->asn1r_buf_start)
{
aCtx->asn1r_encode_overrun = SD_TRUE;
return (SD_FAILURE);
}
/* Convert data to UTF8string (NOT NULL terminated).
* NOTE: utf8_len is overwritten with the actual number of encoded bytes.
*/
utf8_len = asn1r_local_to_utf8 (utf8_ptr, utf8_len, ptr);
if (utf8_len < 0) /* 0 len is OK. */
{
ALOG_NERR0 ("wr_utf8: conversion from local to UTF8 failed");
return (SD_FAILURE);
}
/* Move data forward in ASN.1 encode buffer. */
if (utf8_len > 0)
{
memmove (ASN1_ENC_PTR(aCtx)-utf8_len, (ST_UCHAR*)utf8_ptr, utf8_len);
aCtx->asn1r_field_ptr -= utf8_len; /* update ASN.1 encode ptr */
}
return (SD_SUCCESS);
}
/*renxioabao utf8 UTF8<46><38><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>*/
/*#if (UNICODE_LOCAL_FORMAT==UNICODE_UTF16)*/
#if 0
#if defined(_WIN32)
#include <windows.h>
/************************************************************************/
/* On Windows, the local format is UTF16, so this function converts */
/* from UTF16 string to UTF8 string. */
/* The source string (at src_ptr) must be NULL terminated. */
/* dst_len = num bytes available in dst "UTF8" string. */
/* RETURN: num bytes in dst (not including NULL). */
/************************************************************************/
ST_INT asn1r_local_to_utf8 (ST_CHAR *dst_ptr, ST_INT dst_len, ST_CHAR *src_ptr)
{
ST_INT count;
/* NOTE: pass (src_len==-1) to WideCharToMultiByte.
* "src_ptr" must be NULL terminated, and chars converted
* up to and including the NULL.
* Return value is len of dst, possibly including NULL terminator.
*/
count = WideCharToMultiByte (CP_UTF8, 0,
(ST_UINT16 *) src_ptr, -1, dst_ptr, dst_len, NULL, NULL);
if (count > 0)
{
/* "count" MAY include the NULL terminator. If so, return 1 less. */
if (dst_ptr[count-1]=='\0')
return (count-1); /* if count includes NULL, subtract 1 */
else
return (count); /* if count does not include NULL, return count */
}
return (-1); /* error */
}
#else /* All other systems */
#error Unicode UTF16 currently only supported on Windows
#endif
#else /* UNICODE_LOCAL_FORMAT==UNICODE_UTF8 */
/************************************************************************/
/* This function should work on any system where the local Unicode */
/* format is UTF8. The ASN.1 format is also UTF8, so this function */
/* basically just copies the string. */
/* The source string (at src_ptr) must be NULL terminated. */
/* This function just copies up to (not including the NULL terminator). */
/* dst_len = num bytes available in dst "UTF8" string. */
/* CRITICAL: dst_len must be >= src_len */
/* RETURN: num bytes in dst (not including NULL). */
/************************************************************************/
ST_INT asn1r_local_to_utf8 (ST_CHAR *dst_ptr, ST_INT dst_len, ST_CHAR *src_ptr)
{
ST_INT ret = -1; /* assume error */
ST_INT src_len;
src_len = strlen(src_ptr); /* compute src_len */
if (src_len <= dst_len)
{
if (src_len > 0)
strncpy (dst_ptr, src_ptr, src_len); /* not including NULL terminator*/
ret = src_len; /* success */
}
return (ret);
}
#endif /* UNICODE_LOCAL_FORMAT==UNICODE_UTF8 */

1693
mmslib/asn1/asn1r.c Normal file

File diff suppressed because it is too large Load Diff