📄 zdmwritetype.c
字号:
break;
temp.data = endMsg;
temp.len = Z2Strlen (endMsg);
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCopyItemDataAlloc (
obj->voltObject.libraryCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_MSG]));
if (status != 0)
break;
/* Clone the senderID.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)(smWriteCtx->senderIdRef), (Pointer *)&(zdmCtx->senderId));
if (status != 0)
break;
/* Clone the RecipientList.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)(smWriteCtx->recipListRef), (Pointer *)&(zdmCtx->recipList));
if (status != 0)
break;
writeCtx->recipListRef = zdmCtx->recipList;
writeCtx->senderIdRef = zdmCtx->senderId;
obj->formatType = VOLT_MESSAGE_FORMAT_ZDM_MAIL;
obj->state = VOLT_ZDM_FROM_SM_STATE_WRITE_SET;
obj->WriteInit = VoltZDMWriteInit;
obj->WriteUpdate = VoltZDMFromSMWriteUpdate;
obj->WriteFinal = VoltZDMFromSMWriteFinal;
obj->GetEncodeDecodeSize = VoltCopyGetEncodeDecodeSize;
obj->localCtx = (Pointer)buffer;
obj->LocalCtxDestroy = VoltWriteZDMFromSMCtxDestroy;
/* Now store this SecureMail object as the localCtx of the
* ZDMObject.
*/
zObj->localCtx = (Pointer)obj;
zObj->LocalCtxDestroy = VoltOldZDMCtxDestroy;
zObj->SetParam = VoltZDMSetParamError;
zObj->GetParam = VoltOldZDMGetParamWrite;
zObj->WriteInit = VoltOldZDMWriteInit;
zObj->WriteUpdate = VoltOldZDMFromSMWriteUpdate;
zObj->WriteFinal = VoltOldZDMFromSMWriteFinal;
} while (0);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If error, free what we allocated.
*/
VoltWriteZDMFromSMCtxDestroy ((Pointer)obj, (Pointer)zdmCtx);
VoltDestroyOldZDMObject ((VoltSecureMailObject **)&obj);
VOLT_LOG_ERROR_INFO (
0, *object, status, 0, errorType,
(char *)0, "VtZDMImplWriteFromSecureMail", fnctLine, (char *)0)
return (status);
}
int VtZDMImplWriteFromSecureFile (
VtZDMObject *object,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int bufferSize;
VoltZDMObject *zObj = (VoltZDMObject *)(*object);
VoltSecureMailObject *obj = (VoltSecureMailObject *)0;
VoltSecureMailObject *smObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(zObj->voltObject.libraryCtx);
VoltZDMFromSecureMailCtx *zdmCtx;
VoltSecureMailWriteCtx *writeCtx = (VoltSecureMailWriteCtx *)0;
VoltSecureMailWriteCtx *smWriteCtx;
unsigned char *buffer = (unsigned char *)0;
VtBase64Info b64Info;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Make sure this is being called appropriately.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_ZDM_SET_TYPE_FLAG)
break;
/* Make sure the object is empty.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ZDM_OBJ;
if (zObj->localCtx != (Pointer)0)
break;
/* Check the info, we're expecting a SecureFile object.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (VOLT_OBJECT_TYPE_NOT_EQUAL (info, VOLT_OBJECT_TYPE_SECURE_FILE))
break;
/* The SecureFile object must be initialized at least.
*/
VOLT_SET_FNCT_LINE (fnctLine)
smObj = (VoltSecureMailObject *)info;
if ( (smObj->state == 0) ||
(smObj->state == VOLT_SECURE_MAIL_STATE_WRITE_SET) )
break;
smWriteCtx = (VoltSecureMailWriteCtx *)(smObj->localCtx);
/* A ZDM object used to be a SecureMail object. However, for ZDMv2,
* we have a VoltZDMObject. This "old" ZDM Impl has to fit inside
* the new ZDMObject framework. What we'll do is build the old
* SecureMail object and place it into the new ZDMObject's localCtx.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCreateObject (
(VtLibCtx)libCtx, (VoltObject **)&obj, sizeof (VoltSecureMailObject),
VOLT_OBJECT_TYPE_ZDM);
if (status != 0)
break;
/* Build the local ctx.
*/
bufferSize = sizeof (VoltZDMFromSecureMailCtx);
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
writeCtx = (VoltSecureMailWriteCtx *)buffer;
zdmCtx = (VoltZDMFromSecureMailCtx *)buffer;
/* Whatever the new line char is in the SecureMail object, copy it
* here.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCopyItemDataAlloc (
obj->voltObject.libraryCtx, 0, 0,
&(smWriteCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE]),
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE]));
if (status != 0)
break;
/* Create the Base64 object. From SecureFile will Base 64 encode
* the input data.
*/
if (obj->base64 != (VtAlgorithmObject)0)
VtDestroyAlgorithmObject (&(obj->base64));
b64Info.base64BlockSize = 76;
b64Info.newLineCharacter = VT_BASE64_NEW_LINE_LF;
if (writeCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE].len == 2)
b64Info.newLineCharacter = VT_BASE64_NEW_LINE_CR_LF;
b64Info.errorCheck = VT_BASE64_NO_ERROR_CHECK;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateAlgorithmObject (
(VtLibCtx)libCtx, VtAlgorithmImplBase64, (Pointer)&b64Info,
&(obj->base64));
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtEncodeInit (obj->base64);
if (status != 0)
break;
/* Clone the senderID.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)(smWriteCtx->senderIdRef), (Pointer *)&(zdmCtx->senderId));
if (status != 0)
break;
/* Clone the RecipientList.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)(smWriteCtx->recipListRef), (Pointer *)&(zdmCtx->recipList));
if (status != 0)
break;
writeCtx->recipListRef = zdmCtx->recipList;
writeCtx->senderIdRef = zdmCtx->senderId;
obj->formatType = VOLT_MESSAGE_FORMAT_ZDM_ATTACHMENT;
obj->state = VOLT_ZDM_FROM_SM_STATE_WRITE_SET;
obj->WriteInit = VoltZDMWriteInit;
obj->WriteUpdate = VoltZDMFromSMWriteUpdate;
obj->WriteFinal = VoltZDMFromSFWriteFinal;
obj->GetEncodeDecodeSize = VoltBase64GetEncodeDecodeSize;
obj->localCtx = (Pointer)buffer;
obj->LocalCtxDestroy = VoltWriteZDMFromSMCtxDestroy;
/* Now store this SecureMail object as the localCtx of the
* ZDMObject.
*/
zObj->localCtx = (Pointer)obj;
zObj->LocalCtxDestroy = VoltOldZDMCtxDestroy;
zObj->SetParam = VoltZDMSetParamError;
zObj->GetParam = VoltOldZDMGetParamWrite;
zObj->WriteInit = VoltOldZDMWriteInit;
zObj->WriteUpdate = VoltOldZDMFromSMWriteUpdate;
zObj->WriteFinal = VoltOldZDMFromSFWriteFinal;
} while (0);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If error, free what we allocated.
*/
VoltWriteZDMFromSMCtxDestroy ((Pointer)obj, (Pointer)writeCtx);
VOLT_LOG_ERROR_INFO (
0, *object, status, 0, errorType,
(char *)0, "VtZDMImplWriteFromSecureFile", fnctLine, (char *)0)
return (status);
}
void VoltWriteZDMFromSMCtxDestroy(
Pointer obj,
Pointer ctx
)
{
VoltObject *voltObj;
VoltLibCtx *libCtx;
VoltZDMFromSecureMailCtx *zdmCtx;
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
voltObj = (VoltObject *)obj;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
zdmCtx = (VoltZDMFromSecureMailCtx *)ctx;
if (zdmCtx->unprocessedData.data != (unsigned char *)0)
Z2Free (zdmCtx->unprocessedData.data);
VtDestroyIdentityObject (&(zdmCtx->senderId));
VtDestroyIdentityList (&(zdmCtx->recipList));
VoltWriteSecureMailCtxDestroy (obj, ctx);
}
void VoltOldZDMCtxDestroy (
Pointer obj,
Pointer ctx
)
{
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
/* The localCtx for a ZDM object, when it is built for the old style
* ZDM, is a SecureMail object. Just call the destructor.
*/
VoltDestroyOldZDMObject ((VoltSecureMailObject **)&ctx);
}
int VoltDestroyOldZDMObject (
VoltSecureMailObject **smObj
)
{
VoltSecureMailObject *obj;
VoltLibCtx *libCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* Do we have anything to destroy?
*/
if (smObj == (VoltSecureMailObject **)0)
return (0);
if (*smObj == (VoltSecureMailObject *)0)
return (0);
obj = *smObj;
/* Paranoid programming check.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (VOLT_OBJECT_TYPE_EQUAL (obj, VOLT_OBJECT_TYPE_ZDM))
{
libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VtDestroyPkcs7Object (&(obj->p7SignedData));
VtDestroyPkcs7Object (&(obj->p7EnvelopedData));
VtDestroyAlgorithmObject (&(obj->base64));
if (obj->contentInfo.data != (unsigned char *)0)
Z2Free (obj->contentInfo.data);
/* If there's a local context destructor, call it.
*/
if (obj->LocalCtxDestroy != (VCtxDestroy)0)
obj->LocalCtxDestroy ((Pointer)obj, (Pointer)(obj->localCtx));
/* Call the general object destructor.
*/
VoltDestroyObject ((VoltObject **)smObj);
return (0);
}
VOLT_LOG_ERROR_INFO (
0, *smObj, VT_ERROR_INVALID_ZDM_OBJ, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VoltDestroyOldZDMObject", fnctLine, (char *)0)
return (VT_ERROR_INVALID_ZDM_OBJ);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -