📄 sm2writetype.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "securemail.h"
#include "p7obj.h"
#include "errorctx.h"
int VtSecureMail2ImplWrite (
VtSecureMailObject *object,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int bufferSize;
VoltSecureMailObject *obj = (VoltSecureMailObject *)(*object);
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltSecureMailWriteCtx *writeCtx = (VoltSecureMailWriteCtx *)0;
unsigned char *buffer = (unsigned char *)0;
VtItem temp;
unsigned char newLineChars[2] = { 0x0D, 0x0A };
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
do
{
/* Make sure this is being called appropriately.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_MAIL_SET_TYPE_FLAG)
break;
/* Make sure the object is empty.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if ((obj->state != 0) || (obj->localCtx != (Pointer)0))
break;
/* Check the info, we're expecting NULL.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info != (Pointer)0)
break;
/* Build the local ctx.
*/
bufferSize = sizeof (VoltSecureMailWriteCtx);
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;
writeCtx->messageFormat = VT_MESSAGE_FORMAT_SECURE_MAIL_HTML_V2;
VOLT_SET_ERROR_TYPE(errorType, 0)
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreatePkcs7Object(libCtx, VtPkcs7ImplWriteSignedDSA,
(Pointer)0, &(obj->p7SignedData));
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreatePkcs7Object(libCtx, VtPkcs7ImplWriteEnvelopeIBE,
(Pointer)0, &(obj->p7EnvelopedData));
if (status != 0)
break;
/* Copy the new line chars and the begin and end messages.
* We may want to change the new line char later, so set it to the
* default.
*/
temp.data = newLineChars;
temp.len = sizeof(newLineChars);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE]));
if (status != 0)
break;
obj->formatType = VOLT_MESSAGE_FORMAT_SECURE_MAIL_2;
obj->state = VOLT_SECURE_MAIL_STATE_WRITE_SET;
obj->WriteInit = VoltSecureMail2WriteInit;
obj->WriteUpdate = VoltSecureMailWriteUpdate;
obj->WriteFinal = VoltSecureMailWriteFinal;
obj->GetEncodeDecodeSize = VoltBase64GetEncodeDecodeSize;
obj->localCtx = (Pointer)buffer;
obj->LocalCtxDestroy = VoltWriteSecureMailCtxDestroy;
} while (0);
/* If there was an error, free up the context */
if (status != 0)
{
VoltWriteSecureMailCtxDestroy ((Pointer)obj, (Pointer)writeCtx);
VOLT_LOG_ERROR(libCtx, status, errorType, fnctLine,
"VtSecureMail2ImplWrite", (unsigned char*)0)
}
return status;
}
int VtSecureMail2ImplWriteFromZDM (
VtSecureMailObject* object,
Pointer info,
unsigned int flag
)
{
int status;
VoltSecureMailObject *obj = (VoltSecureMailObject *)(*object);
VoltLibCtx* libCtx = (VoltLibCtx*) obj->voltObject.libraryCtx;
VoltSecureMailFromZDMWriteCtx* writeCtx = (VoltSecureMailFromZDMWriteCtx*)0;
VtItem temp;
unsigned char newLineChars[2] = { 0x0D, 0x0A };
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
do
{
/* Make sure this is being called appropriately. */
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_MAIL_SET_TYPE_FLAG)
break;
/* Make sure the object is empty. */
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if ((obj->state != 0) || (obj->localCtx != (Pointer)0))
break;
/* Check the info, we're expecting a VtZDMObject. */
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if ((info == (Pointer)0) || VOLT_OBJECT_TYPE_NOT_EQUAL (info, VOLT_OBJECT_TYPE_ZDM))
break;
/* Build the local ctx. */
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
writeCtx = (VoltSecureMailFromZDMWriteCtx*)
Z3Malloc(sizeof(VoltSecureMailFromZDMWriteCtx));
if (writeCtx == (VoltSecureMailFromZDMWriteCtx*)0)
break;
Z2Memset(writeCtx, 0, sizeof(VoltSecureMailFromZDMWriteCtx));
/* Copy the new line chars and the begin and end messages.
* We may want to change the new line char later, so set it to the
* default.
*/
temp.data = newLineChars;
temp.len = sizeof(newLineChars);
VOLT_SET_ERROR_TYPE(errorType, 0)
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCopyItemDataAlloc(libCtx, 0, 0, &temp,
&(writeCtx->baseCtx.itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE]));
if (status != 0)
break;
obj->formatType = VOLT_MESSAGE_FORMAT_SECURE_MAIL_2;
obj->state = VOLT_SECURE_MAIL_STATE_WRITE_SET;
obj->WriteInit = VoltSM2FromZDMWriteInit;
obj->WriteUpdate = VoltSM2FromZDMWriteUpdate;
obj->WriteFinal = VoltSM2FromZDMWriteFinal;
obj->GetEncodeDecodeSize = VoltBase64GetEncodeDecodeSize;
obj->localCtx = (Pointer)writeCtx;
obj->LocalCtxDestroy = VoltWriteSecureMailCtxDestroy;
writeCtx->zdmObj = (VtZDMObject)info;
} while (0);
/* If there was an error, free up the context */
if (status != 0)
{
VoltWriteSecureMailCtxDestroy ((Pointer)obj, (Pointer)writeCtx);
VOLT_LOG_ERROR(libCtx, status, errorType, fnctLine,
"VtSecureMail2ImplWriteFromZDM", (unsigned char*)0)
}
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -