📄 zdm2read.c
字号:
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
VtSecureArchiveParamArchiveAttribute, (Pointer*)&attributeInfo);
if (status != 0)
break;
*(const unsigned char**)getInfo = attributeInfo.value;
break;
case VT_ZDM_PARAM_INSECURE_MESSAGE_ID:
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDataNodeResolveChild(readCtx->mInsecureAttributes,
VoltZDM2MessageIDAttributeName, 0, &node);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDataNodeGetStringValue(node, (const unsigned char**)getInfo);
break;
case VT_ZDM_PARAM_FILE_NAME:
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
VtSecureArchiveParamFileName, getInfo);
break;
case VT_ZDM_PARAM_FILE_SIZE:
if (readCtx->mCurrentEntryType != VT_ZDM_CURRENT_ENTRY_ATTACHMENT)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
break;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
VtSecureArchiveParamFileSize, getInfo);
break;
case VT_ZDM_PARAM_PRIMARY_EMAIL_LIST:
case VT_ZDM_PARAM_CC_EMAIL_LIST:
if (!readCtx->mEmailRecipientsInited)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltZDM2InitEmailRecipients(zdmObj);
if (status != 0)
break;
}
VT_ASSERT(readCtx->mEmailRecipientsInited);
*(VtZDMEmailRecipientList**)getInfo =
(paramSelector == VT_ZDM_PARAM_PRIMARY_EMAIL_LIST) ?
&readCtx->mPrimaryRecipientList : &readCtx->mCCRecipientList;
break;
case VT_ZDM_PARAM_ATTACHMENT_COUNT:
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
VtSecureArchiveParamEntryCount, getInfo);
break;
case VT_ZDM_PARAM_REMAINING_OUTPUT_SIZE:
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
VtSecureArchiveParamRemainingOutputSize, getInfo);
break;
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,
VtVerifyStack verifyStack,
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,
verifyStack, 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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -