📄 zdm2read.c
字号:
default:
/* Should have caught invalid param earlier, so we should
* never reach here.
*/
VT_ASSERT(0);
}
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltZDM2ReadGetParam", (unsigned char*)0)
return status;
}
static int VoltZDM2ReadInit(
VtZDMObject zdmObj
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltZDM2ReadLocalCtx* readCtx;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(zdmObj != (VtZDMObject)0);
libCtx = zdmObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);
VT_ASSERT(readCtx->mSecureArchive != (VtSecureArchiveObject)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
do
{
if (readCtx->mInputStream == (VtStreamObject)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&readCtx->mBufferTypeInfo, &readCtx->mInputStream);
if (status != 0)
break;
readCtx->mOwnsInputStream = 1;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtSecureArchiveReadInit(readCtx->mSecureArchive);
if (status != 0)
break;
readCtx->mReadInitCalled = 1;
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltZDM2ReadInit", (unsigned char*)0)
return status;
}
static int VoltZDM2ReadUpdate(
VtZDMObject zdmObj,
unsigned char *message,
unsigned int messageLen,
unsigned int *bytesRead,
unsigned char *outputData,
unsigned int bufferSize,
unsigned int *outputDataLen
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltZDM2ReadLocalCtx* readCtx;
VtZDMCurrentEntryInfo currentEntryInfo;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(zdmObj != (VtZDMObject)0);
libCtx = zdmObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
do
{
if (!readCtx->mReadInitCalled)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
break;
}
/* If the current entry type is such that we're expecting output, then
* (at least for this impl) there can't be any more input data, and there
* must be an output buffer into which we'll put the data.
*/
if ((readCtx->mCurrentEntryType == VT_ZDM_CURRENT_ENTRY_MESSAGE_BODY) ||
(readCtx->mCurrentEntryType == VT_ZDM_CURRENT_ENTRY_ATTACHMENT))
{
if (message != (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
break;
}
if (outputDataLen == (unsigned int*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_NULL_ARG;
break;
}
}
switch (readCtx->mCurrentEntryType)
{
case VOLT_ZDM_CURRENT_ENTRY_NONE:
/* VOLT_ZDM_CURRENT_ENTRY_NONE is the initial current entry
* type for the ZDM object. The first thing the caller must do
* is set the input data for the ZDM. This can be done by either
* setting the input stream explicitly using the input stream
* param, or by reading in the data with a series of update calls.
* If the message data for the update call is NULL, then we assume
* the caller has set the input stream explicitly.
*/
if (message == (unsigned char*)0)
{
/* If the input stream was not set explicitly, then a temp
* input stream will have been set in the ReadInit call and
* the mOwnsInputStream flag will be set to 1. In that case
* the user must be input the archive data with Update calls,
* so it's an error if the message data is NULL.
*/
if (readCtx->mOwnsInputStream)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
break;
}
/* The user has set the input stream explicitly, but hasn't
* set the current entry yet, so we set the current entry type
* to read the message body as the default current entry
*/
currentEntryInfo.type = VT_ZDM_CURRENT_ENTRY_MESSAGE_BODY;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtSetZDMParam(zdmObj, VtZDMParamCurrentEntry,
(Pointer)¤tEntryInfo);
if (status != 0)
break;
/* And now we call ourselves recursively to do the actual update */
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2ReadUpdate(zdmObj, message, messageLen, bytesRead,
outputData, bufferSize, outputDataLen);
break;
}
VT_ASSERT(readCtx->mInputStream != (VtStreamObject)0);
/* Write the input data to the input stream */
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(readCtx->mInputStream, message, messageLen);
if (status != 0)
break;
if (bytesRead != (unsigned int*)0)
*bytesRead = messageLen;
break;
case VT_ZDM_CURRENT_ENTRY_MESSAGE_BODY:
case VT_ZDM_CURRENT_ENTRY_ATTACHMENT:
VOLT_SET_FNCT_LINE(fnctLine)
status = VtSecureArchiveReadUpdate(readCtx->mSecureArchive, message,
messageLen, bytesRead, outputData, bufferSize, outputDataLen);
break;
default:
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_ZDM_ENTRY;
break;
}
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltZDM2ReadUpdate", (unsigned char*)0)
return status;
}
static int VoltZDM2ReadFinal(
VtZDMObject zdmObj,
unsigned char *message,
unsigned int messageLen,
unsigned int *bytesRead,
unsigned char *outputData,
unsigned int bufferSize,
unsigned int *outputDataLen
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltZDM2ReadLocalCtx* readCtx;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(zdmObj != (VtZDMObject)0);
libCtx = zdmObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
do
{
VOLT_SET_FNCT_LINE(fnctLine)
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltZDM2ReadFinal", (unsigned char*)0)
return status;
}
static int VoltZDM2Verify(
VtZDMObject zdmObj,
VtPolicyCtx policyCtx,
VtStorageCtx storageCtx,
VtTransportCtx transportCtx,
VtCertVerifyCtx certVerifyCtx,
Pointer verifyCtxInfo,
VtVerifyFailureList vfyFailList,
unsigned int *verifyResult
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltZDM2ReadLocalCtx* readCtx;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(zdmObj != (VtZDMObject)0);
libCtx = zdmObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
do
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtSecureArchiveVerify(readCtx->mSecureArchive, policyCtx,
storageCtx, transportCtx, certVerifyCtx, verifyCtxInfo,
vfyFailList, verifyResult);
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltZDM2Verify", (unsigned char*)0)
return status;
}
int VtZDM2ImplRead(
VtZDMObject* obj,
Pointer associatedInfo,
unsigned int flags
)
{
int status = 0;
VtZDMObject zdmObj;
VoltZDM2ReadLocalCtx* readCtx = (VoltZDM2ReadLocalCtx*)0;
VtLibCtx libCtx = (VtLibCtx)0;
VtReadZDMInfo* zdmReadInfo = (VtReadZDMInfo*)associatedInfo;
VtReadSecureArchiveInfo secureArchiveReadInfo;
VtReadSecureArchiveInfo* secureArchiveReadInfoPtr =
(VtReadSecureArchiveInfo*)0;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(obj != (VtZDMObject*)0);
VT_ASSERT(*obj != (VtZDMObject)0);
do
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
if ((obj == (VtZDMObject*)0) || (*obj == (VtZDMObject)0))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_NULL_ARG;
break;
}
zdmObj = *obj;
libCtx = zdmObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
if (flags != VOLT_ZDM_SET_TYPE_FLAG)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_TYPE;
break;
}
readCtx = (VoltZDM2ReadLocalCtx*) Z3Malloc(sizeof(VoltZDM2ReadLocalCtx));
if (readCtx == (VoltZDM2ReadLocalCtx*)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
break;
}
Z2Memset(readCtx, 0, sizeof(VoltZDM2ReadLocalCtx));
if (zdmReadInfo != (VtReadZDMInfo*)0)
{
secureArchiveReadInfo.decoderCount = zdmReadInfo->decoderCount;
secureArchiveReadInfo.decoders = zdmReadInfo->decoders;
secureArchiveReadInfo.derCoderCount = zdmReadInfo->derCoderCount;
secureArchiveReadInfo.derCoders = zdmReadInfo->derCoders;
secureArchiveReadInfo.mpCtx = zdmReadInfo->mpCtx;
secureArchiveReadInfoPtr = &secureArchiveReadInfo;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateSecureArchiveObject(libCtx, VtSecureArchiveImplRead,
(Pointer)secureArchiveReadInfoPtr, &readCtx->mSecureArchive);
if (status != 0)
break;
VOLT_SET_ERROR_TYPE(errorType, 0)
readCtx->mBufferTypeInfo.bufferType = VT_BUFFER_TYPE_MEMORY;
zdmObj->localCtx = (Pointer) readCtx;
zdmObj->SetParam = VoltZDM2ReadSetParam;
zdmObj->GetParam = VoltZDM2ReadGetParam;
zdmObj->ReadInit = VoltZDM2ReadInit;
zdmObj->ReadUpdate = VoltZDM2ReadUpdate;
zdmObj->ReadFinal = VoltZDM2ReadFinal;
zdmObj->Verify = VoltZDM2Verify;
zdmObj->LocalCtxDestroy = VoltZDM2ReadLocalCtxDestroy;
}
while(0);
if (status != 0)
{
VoltZDM2ReadLocalCtxDestroy((Pointer)zdmObj, (Pointer)readCtx);
VOLT_LOG_ERROR(libCtx, status, errorType,
fnctLine, "VtZDM2ImplRead", (char *)0)
}
return status;
}
int VtZDMDetermineVersionAndType (
VtLibCtx libCtx,
unsigned char* message,
unsigned int messageLength,
unsigned int* version,
unsigned int* type
)
{
int status = 0;
unsigned char* p;
unsigned char* q;
unsigned char* messageEnd = message + messageLength;
unsigned int prefixLength;
unsigned int suffixLength;
unsigned int typeMsgLength;
unsigned int typeAttachmentLength;
long num;
unsigned char versionBuffer[32];
int foundVersion, foundType;
VOLT_DECLARE_FNCT_LINE(fnctLine)
*version = 0;
*type = 0;
do
{
prefixLength = Z2Strlen(VoltZDM2MetaVersionPrefix);
suffixLength = Z2Strlen(VoltZDM2MetaSuffix);
foundVersion = 0;
for (p = message; p < messageEnd; p++)
{
if (VoltCaseInsensitiveCompareBuffers(p, prefixLength,
VoltZDM2MetaVersionPrefix, prefixLength, libCtx) == 0)
{
p += prefixLength;
for (q = p; q < messageEnd; q++)
{
if (VoltCaseInsensitiveCompareBuffers(q, suffixLength,
VoltZDM2MetaSuffix, suffixLength, libCtx) == 0)
{
if (q - p < sizeof(versionBuffer))
{
Z2Memcpy(versionBuffer, p, q - p);
versionBuffer[q - p] = 0;
status = VoltDecimalStringToNum(versionBuffer, &num, libCtx);
if ((status == 0) && (num >= 1) && (num <= VOLT_ZDM2_CURRENT_VERSION))
{
*version = (int)num;
foundVersion = 1;
}
break;
}
}
}
if (foundVersion)
break;
}
}
if (!foundVersion)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_ZDM_MSG;
break;
}
prefixLength = Z2Strlen(VoltZDM2MetaTypePrefix);
typeMsgLength = Z2Strlen(VoltZDM2TypeMessage);
typeAttachmentLength = Z2Strlen(VoltZDM2TypeAttachment);
foundType = 0;
for (p = message; p < messageEnd; p++)
{
if (VoltCaseInsensitiveCompareBuffers(p, prefixLength,
VoltZDM2MetaTypePrefix, prefixLength, libCtx) == 0)
{
p += prefixLength;
for (q = p; q < messageEnd; q++)
{
if (VoltCaseInsensitiveCompareBuffers(q, suffixLength,
VoltZDM2MetaSuffix, suffixLength, libCtx) == 0)
{
if (VoltCaseInsensitiveCompareBuffers(p, q - p,
VoltZDM2TypeMessage, typeMsgLength, libCtx) == 0)
{
*type = VT_ZDM_MAIL;
foundType = 1;
break;
}
if (VoltCaseInsensitiveCompareBuffers(p, q - p,
VoltZDM2TypeAttachment, typeAttachmentLength, libCtx) == 0)
{
*type = VT_ZDM_ATTACHMENT;
foundType = 1;
break;
}
}
}
if (foundType)
break;
}
}
if (!foundType)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_ZDM_MSG;
break;
}
}
while (0);
VOLT_LOG_ERROR_COMPARE(status , libCtx, status, VT_ERROR_TYPE_PRIMARY,
fnctLine, "VtZDMDetermineVersionAndType", (unsigned char*)0)
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -