📄 a_encode.c
字号:
Notes: The function whose address is passed as a parameter is called zero
or more times to take away some accumulated data. The function is called
with these parameters:
_UINT8 * The parameter (ebuffp) passed to this routine
_UINT8 * The buffer where the data resides
_UINT16 The number of octets in the buffer.
The function should return the number of octets consumed, type _UINT16.
The function should return a zero if it has taken all the data it wants.
Returns: nothing
****************************************************************************/
void A_EncodeInt(_UINT16 id, _UINT8 flags, _INT32 value,_UINT8 * ebuffp)
{
_UINT16 length;
_UINT8 *rp;
_UINT8 buff[OCTETS_PER_INT32];
length = A_SizeOfInt(value);
A_EncodeType(id, (_UINT8) (flags & A_IDC_MASK), ebuffp);
A_EncodeLength(length,ebuffp);
rp = buff + (_UINT16 ) length;
for(;;)
{
*(--rp) = (_UINT8) value;
if(rp == buff)
break;
/*lint -e704 */
value >>= 8;
/*lint +e704 */
}
(void)A_EncodeHelper(ebuffp, buff, length);
}
/****************************************************************************
A_EncodeUnsignedInt -- generate ASN.1 format of integer (WITH TYPE & LENGTH)
where the local form of the integer is unsigned.
Parameters:
_UINT16 The type value
_UINT8 A_IDC_MASK flag values
_UINT32 The integer to convert (unsigned 32 bit)
_UINT16 (*f()) Function to be called to take generated data
_UINT8 * Parameter to be passed unchanged to the function.
Notes: The function whose address is passed as a parameter is called zero
or more times to take away some accumulated data. The function is called
with these parameters:
_UINT8 * The parameter (ebuffp) passed to this routine
_UINT8 * The buffer where the data resides
_UINT16 The number of octets in the buffer.
The function should return the number of octets consumed, type _UINT16.
The function should return a zero if it has taken all the data it wants.
Returns: nothing
****************************************************************************/
void A_EncodeUnsignedInt(_UINT16 id,_UINT8 flags, _UINT32 value, _UINT8 * ebuffp)
{
_UINT16 leng, xleng;
_UINT8 *rp;
_UINT8 buff[OCTETS_PER_INT32 + 1];
leng = A_SizeOfUnsignedInt(value);
A_EncodeType(id, (_UINT8) (flags & A_IDC_MASK),ebuffp);
A_EncodeLength(leng,ebuffp);
rp = buff + (_UINT16 ) leng;
/* If the unsigned number takes 5 octets, the high order octet is merely */
/* a zero byte to hold the zero sign. */
for(xleng = leng; xleng--;)
{
*(--rp) = (_UINT8) value;
value >>= 8; /* This better be shifting zeros into the high end! */
}
(void)A_EncodeHelper(ebuffp, buff, leng);
}
/****************************************************************************
A_EncodeOctetString -- Generate ASN.1 format of octet string (WITH TYPE & LENGTH)
Parameters:
_UINT16 The type value
_UINT8 A_IDC_MASK flag values
_UINT8 * Address of the string
_UINT16 Length of the string
_UINT16 (*f()) Function to be called to take generated data
_UINT8 * Parameter to be passed unchanged to the function.
Notes: The function whose address is passed as a parameter is called zero
or more times to take away some accumulated data. The function is called
with these parameters:
_UINT8 * The parameter (ebuffp) passed to this routine
_UINT8 * The buffer where the data resides
_UINT16 The number of octets in the buffer.
The function should return the number of octets consumed, type _UINT16.
The function should return a zero if it has taken all the data it wants.
****************************************************************************/
void A_EncodeOctetString(_UINT16 id,_UINT8 flags,
_UINT8 * osp, _UINT16 oslen,_UINT8 * ebuffp)
{
/* Do a primitive encoding */
if(oslen>MAX_OCTET_LENGTH)
oslen=MAX_OCTET_LENGTH;
A_EncodeType(id, (_UINT8) (flags & A_IDC_MASK), ebuffp);
A_EncodeLength(oslen, ebuffp);
if(oslen != 0)
A_EncodeHelper(ebuffp, osp, oslen);
}
/****************************************************************************
A_EncodeSubId -- generate ASN.1 format of a subidentifier from an
object identifier
Parameters:
_UINT32 The subidentifier to encode
_UINT16 (*f()) Function to be called to take generated data
_UINT8 * Parameter to be passed unchanged to the function.
Notes: The function whose address is passed as a parameter is called zero
or more times to take away some accumulated data. The function is called
with these parameters:
_UINT8 * The parameter (ebuffp) passed to this routine
_UINT8 * The buffer where the data resides
_UINT16 The number of octets in the buffer.
The function should return the number of octets consumed, type _UINT16.
The function should return a zero if it has taken all the data it wants.
Returns: nothing
****************************************************************************/
void A_EncodeSubId(_UINT32 value,_UINT8 * ebuffp)
{
_UINT16 leng;
_UINT8 *rp;
_UINT8 buff[OCTETS_PER_INT32 + 1];
_UINT8 last;
leng = A_SizeOfSubId(value);
for(rp = buff + leng, last = 0x00; rp != buff;)
{
*(--rp) = (_UINT8) (value & 0x007F) | last;
value >>= 7;
last = 0x80;
}
(void)A_EncodeHelper(ebuffp, buff, leng);
}
/****************************************************************************
A_EncodeObjectId -- generate ASN.1 format of Object ID (WITH TYPE & LENGTH)
Parameters:
_UINT16 The type value
_UINT8 A_IDC_MASK flag values
OBJ_ID_T * Pointer to the internal object Id structure
_UINT16 (*f()) Function to be called to take generated data
_UINT8 * Parameter to be passed unchanged to the function.
Notes: The function whose address is passed as a parameter is called zero
or more times to take away some accumulated data. The function is called
with these parameters:
_UINT8 * The parameter (ebuffp) passed to this routine
_UINT8 * The buffer where the data resides
_UINT16 The number of octets in the buffer.
The function should return the number of octets consumed, type _UINT16.
The function should return a zero if it has taken all the data it wants.
Returns: nothing
****************************************************************************/
void A_EncodeObjectId(_UINT16 id, _UINT8 flags, OBJ_ID_T * objp, _UINT8 * ebuffp)
{
_UINT16 leng;
_UINT32 *cp = objp->component_list;
_UINT16 i;
_UINT32 x;
leng = A_SizeOfObjectId(objp);
A_EncodeType(id, (_UINT8) (flags & A_IDC_MASK), ebuffp);
A_EncodeLength(leng, ebuffp);
if(leng == 0)
return;
/* Merge the first two components of the object identifier to form the */
/* first subidentifier. */
{
x = *cp++;
x = x * 40 + *cp++;
A_EncodeSubId(x, ebuffp);
}
for(i = 2; i < objp->num_components; i++)
{
A_EncodeSubId(*cp++,ebuffp);
}
}
/* We only inlcude the ui64 function if the type is installed */
/****************************************************************************
A_EncodeUnsignedInt64 -- generate ASN.1 format of integer (WITH TYPE & LENGTH)
where the local form of the integer is unsigned 64.
Parameters:
_UINT16 The type value
_UINT8 A_IDC_MASK flag values
UINT64_T * The integer to convert (unsigned 64 bit)
_UINT16 (*f()) Function to be called to take generated data
_UINT8 * Parameter to be passed unchanged to the function.
Notes: The function whose address is passed as a parameter is called zero
or more times to take away some accumulated data. The function is called
with these parameters:
_UINT8 * The parameter (ebuffp) passed to this routine
_UINT8 * The buffer where the data resides
_UINT16 The number of octets in the buffer.
The function should return the number of octets consumed, type _UINT16.
The function should return a zero if it has taken all the data it wants.
Returns: nothing
****************************************************************************/
void A_EncodeUnsignedInt64(_UINT16 id,_UINT8 flags, UINT64_T * value, _UINT8 * ebuffp)
{
_UINT16 leng, xleng;
_UINT8 *rp;
_UINT8 buff[(OCTETS_PER_INT32 * 2) + 1];
memset(buff,0,sizeof(buff));
leng = A_SizeOfUnsignedInt64(value);
A_EncodeType(id, (_UINT8) (flags & A_IDC_MASK),ebuffp);
A_EncodeLength(leng, ebuffp);
#if 1
rp = (_UINT8*) &buff[leng];
/* If the unsigned number takes 9 octets, the high order octet is merely */
/* a zero byte to hold the zero sign. */
if(leng <= 4)
{
for(xleng = leng;xleng>0; xleng--)
{
*(--rp) = (_UINT8) value->low;
value->low >>= 8;
}
}
else
{
for(xleng = 4;xleng>0; xleng--)
{
*(--rp) = (_UINT8) value->low;
value->low >>= 8;
}
for(xleng = leng - 4;xleng>0; xleng--)
{
*(--rp) = (_UINT8) value->high;
value->high >>= 8;
}
}
#endif
(void)A_EncodeHelper(ebuffp, buff, leng);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -