📄 decodeid.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "idobj.h"
#include "idencode.h"
#include "emailschema.h"
#include "oidlist.h"
#include "errorctx.h"
int VoltDecodeIdentityDistrict (
VoltLibCtx *libCtx,
unsigned char *encoding,
unsigned int encodingLen,
unsigned char *districtName,
unsigned int bufferSize,
unsigned int *districtNameLen
)
{
int status;
unsigned int len;
unsigned char *input = encoding;
Asn1Identity *ident = (Asn1Identity *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
ident = Asn1Identity_new ();
if (ident == (Asn1Identity *)0)
break;
/* Decode.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
d2i_Asn1Identity (&ident, &input, encodingLen);
if (ident == (Asn1Identity *)0)
break;
/* Is the output buffer big enough?
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_BUFFER_TOO_SMALL;
len = (unsigned int)(ident->district->length + 1);
*districtNameLen = len;
if (bufferSize < len)
break;
/* It's big enough, just copy the name.
*/
Z2Memcpy (districtName, ident->district->data, len - 1);
districtName[len - 1] = 0;
status = 0;
} while (0);
if (ident != (Asn1Identity *)0)
Asn1Identity_free (ident);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, 0, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VoltDecodeIdentityDistrict", fnctLine, (char *)0)
return (status);
}
int VoltDecodeIdentity (
unsigned char *encoding,
unsigned int encodingLen,
VtIdentitySchemaDecode **decoders,
unsigned int decoderCount,
unsigned int *arrayIndex,
VoltIdentityObject *idObj
)
{
int status;
unsigned int index, actualLen;
VoltLibCtx *libCtx = (VoltLibCtx *)(idObj->voltObject.libraryCtx);
Asn1Identity *ident = (Asn1Identity *)0;
unsigned char *temp;
unsigned char *nameCopy = (unsigned char *)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* The identity object must be empty.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltIsIdentityObjectEmpty ((VtIdentityObject)idObj);
if (status != 0)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
ident = Asn1Identity_new ();
if (ident == (Asn1Identity *)0)
break;
/* Decode.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
temp = encoding;
d2i_Asn1Identity (&ident, &temp, encodingLen);
if (ident == (Asn1Identity *)0)
break;
actualLen = (unsigned int)temp - (unsigned int)encoding;
/* Run through the decoders, asking each if it knows the schemaType.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
for (index = 0; index < decoderCount; ++index)
{
if (decoders[index] == (VtIdentitySchemaDecode *)0)
continue;
VOLT_SET_FNCT_LINE (fnctLine)
status = decoders[index] (
idObj, ident, VOLT_DECODER_TYPE_FLAG);
/* If the call was successful (status is 0), we found what we're
* looking for. If the return was VT_ERROR_UNKNOWN_SCHEMA, continue
* looking. Any other error and exit.
*/
if (status != VT_ERROR_UNKNOWN_SCHEMA)
break;
}
/* If there's an error, pass it on.
*/
if (status != 0)
break;
/* If the caller wants the index, pass it on.
*/
if (arrayIndex != (unsigned int *)0)
*arrayIndex = index;
/* Create a district object and set it with the district name.
*/
if (idObj->mpCtx != (VtMpIntCtx)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateDistrictObject (
(VtLibCtx)libCtx, VtDistrictImplMpCtx, (Pointer)(idObj->mpCtx),
&(idObj->district));
if (status != 0)
break;
}
else
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateDistrictObject (
(VtLibCtx)libCtx, (VtDistrictImpl *)0, (Pointer)0,
&(idObj->district));
if (status != 0)
break;
}
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
nameCopy = (unsigned char *)Z2Malloc (ident->district->length + 1, 0);
if (nameCopy == (unsigned char *)0)
break;
Z2Memcpy (nameCopy, ident->district->data, ident->district->length);
nameCopy[ident->district->length] = 0;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetDistrictParam (
idObj->district, VtDistrictParamQualifiedName, (Pointer)nameCopy);
if (status != 0)
break;
/* Everything worked, copy the actual encoding into the object.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
idObj->encoding.data = (unsigned char *)Z2Malloc (actualLen, 0);
if (idObj->encoding.data == (unsigned char *)0)
break;
Z2Memcpy (idObj->encoding.data, encoding, actualLen);
idObj->encoding.len = actualLen;
status = 0;
} while (0);
if (nameCopy != (unsigned char *)0)
Z2Free (nameCopy);
if (ident != (Asn1Identity *)0)
Asn1Identity_free (ident);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, idObj, status, 0, errorType,
(char *)0, "VoltDecodeIdentity", fnctLine, (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -