📄 smwritetype.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 VtSecureMailImplWrite (
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 };
unsigned char *beginMsg = VOLT_SECURE_MAIL_BEGIN_MESSAGE;
unsigned char *beginBlk = VOLT_SECURE_MAIL_BEGIN_BLOCK;
unsigned char *endBlk = VOLT_SECURE_MAIL_END_BLOCK;
unsigned char *endMsg = VOLT_SECURE_MAIL_END_MESSAGE;
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_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;
/* Build the P7 objects.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreatePkcs7Object (
(VtLibCtx)libCtx, VtPkcs7ImplWriteSignedDSA, (Pointer)0,
&(obj->p7SignedData));
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreatePkcs7Object (
(VtLibCtx)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 (
obj->voltObject.libraryCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_NEW_LINE]));
if (status != 0)
break;
temp.data = beginMsg;
temp.len = Z2Strlen (beginMsg);
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCopyItemDataAlloc (
obj->voltObject.libraryCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG]));
if (status != 0)
break;
temp.data = beginBlk;
temp.len = Z2Strlen (beginBlk);
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCopyItemDataAlloc (
obj->voltObject.libraryCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_BLK]));
if (status != 0)
break;
temp.data = endBlk;
temp.len = Z2Strlen (endBlk);
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCopyItemDataAlloc (
obj->voltObject.libraryCtx, 0, 0, &temp,
&(writeCtx->itemArray[VOLT_WRITE_SM_ITEM_END_BLK]));
if (status != 0)
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;
obj->formatType = VOLT_MESSAGE_FORMAT_SECURE_MAIL;
obj->state = VOLT_SECURE_MAIL_STATE_WRITE_SET;
obj->WriteInit = VoltSecureMailWriteInit;
obj->WriteUpdate = VoltSecureMailWriteUpdate;
obj->WriteFinal = VoltSecureMailWriteFinal;
obj->GetEncodeDecodeSize = VoltBase64GetEncodeDecodeSize;
obj->localCtx = (Pointer)buffer;
obj->LocalCtxDestroy = VoltWriteSecureMailCtxDestroy;
} while (0);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If error, free what we allocated.
*/
VoltWriteSecureMailCtxDestroy ((Pointer)obj, (Pointer)writeCtx);
VOLT_LOG_ERROR_INFO (
0, *object, status, 0, errorType,
(char *)0, "VtSecureMailImplWrite", fnctLine, (char *)0)
return (status);
}
void VoltWriteSecureMailCtxDestroy (
Pointer obj,
Pointer ctx
)
{
unsigned int index;
VoltObject *voltObj = (VoltObject *)obj;
VoltLibCtx *libCtx;
VoltSecureMailWriteCtx *writeCtx;
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
writeCtx = (VoltSecureMailWriteCtx *)ctx;
/* Free memory in all the VtItem's.
*/
for (index = 0; index < VOLT_WRITE_SM_ITEM_COUNT; ++index)
{
if (writeCtx->itemArray[index].data != (unsigned char *)0)
Z2Free (writeCtx->itemArray[index].data);
}
if (writeCtx->fileName.data != (unsigned char *)0)
Z2Free (writeCtx->fileName.data);
Z2Free(writeCtx->contentType);
Z2Free(writeCtx->characterSet);
Z2Free(writeCtx->originalCharacterSet);
Z2Free(writeCtx->templateCharset);
Z2Free (ctx);
}
int VtSecureMailParamDataLen (
VtSecureMailObject secureMailObj,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int *dataLen;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureMailObj;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* This Param cannot get info.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_MAIL_SET_TYPE_FLAG)
break;
/* The SecureMail object must not be set with dataLen yet.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if (obj->dataLen != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if ((obj->state & VOLT_SECURE_MAIL_STATE_WRITE) == 0)
break;
/* The state must be VOLT_SECURE_MAIL_STATE_WRITE_SET.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
break;
/* The info should be an unsigned int.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
dataLen = (unsigned int *)info;
obj->dataLen = *dataLen;
#if VT_64_BIT_LENGTH == 64
obj->dataLen64 = (VtUInt64)(obj->dataLen);
#endif
status = 0;
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, secureMailObj, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VtSecureMailParamDataLen", fnctLine, (char *)0)
return (status);
}
#if VT_64_BIT_LENGTH == 64
int VtSecureMailParamDataLen64 (
VtSecureMailObject secureMailObj,
Pointer info,
unsigned int flag
)
{
int status;
VtUInt64 *dataLen;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureMailObj;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* This Param cannot get info.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_MAIL_SET_TYPE_FLAG)
break;
/* The SecureMail object must not be set with dataLen yet.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
if (obj->dataLen != 0)
break;
if (obj->dataLen64 != (VtUInt64)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if ((obj->state & VOLT_SECURE_MAIL_STATE_WRITE) == 0)
break;
/* The state must be VOLT_SECURE_MAIL_STATE_WRITE_SET.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
break;
/* The info should be a VtUInt64
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
dataLen = (VtUInt64 *)info;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -