📄 sfreadtype.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 "errorctx.h"
int VtSecureFileImplRead (
VtSecureFileObject *object,
Pointer info,
unsigned int flag
)
{
int status;
#if VOLT_ALIGNMENT != 1
unsigned int pad;
#endif
unsigned int index, bufferSize, offset;
unsigned int listToUseCount = 0, decodersToUseCount = 0;
VoltSecureMailObject *obj = (VoltSecureMailObject *)(*object);
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VtReadSecureMailInfo *readInfo;
VtDerCoder **ListToUse = (VtDerCoder **)0;
VtIdentitySchemaDecode **DecodersToUse = (VtIdentitySchemaDecode **)0;
VtDERCoderArray *derCoderArray;
VtSchemaDecodeArray *schemaDecodeArray;
VtMpIntCtx mpCtxToUse = (VtMpIntCtx)0;
unsigned char *buffer = (unsigned char *)0;
VoltSecureMailReadCtx *readCtx;
VtReadPkcs7Info p7Info;
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_FILE_SET_TYPE_FLAG)
break;
/* Make sure the object is empty.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SECURE_FILE_OBJ;
if ( (obj->state != 0) || (obj->localCtx != (Pointer)0) )
break;
/* Check the info. If there's no info, get it from the libCtx.
*/
if (info != (Pointer)0)
{
readInfo = (VtReadSecureMailInfo *)info;
ListToUse = readInfo->derCoders;
listToUseCount = readInfo->derCoderCount;
DecodersToUse = readInfo->decoders;
decodersToUseCount = readInfo->decoderCount;
mpCtxToUse = readInfo->mpCtx;
}
/* If we don't have any DerCoder's get the ones in the libCtx. If
* there are none there, break, that's an error.
*/
if ( (ListToUse == (VtDerCoder **)0) || (listToUseCount == 0) )
{
derCoderArray = (VtDERCoderArray *)VoltGetLibCtxInfo (
obj->voltObject.libraryCtx, VOLT_LIB_CTX_INFO_TYPE_DER_CODERS);
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_DER_CODERS;
if (derCoderArray == (VtDERCoderArray *)0)
break;
ListToUse = derCoderArray->derCoders;
listToUseCount = derCoderArray->derCoderCount;
}
/* If we don't have any SchemaDecode's get the ones in the libCtx.
* If there are none there, break, that's an error.
*/
if ( (DecodersToUse == (VtIdentitySchemaDecode **)0) ||
(decodersToUseCount == 0) )
{
schemaDecodeArray = (VtSchemaDecodeArray *)VoltGetLibCtxInfo (
obj->voltObject.libraryCtx, VOLT_LIB_CTX_INFO_TYPE_SCHEMA_DECODES);
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_SCHEMA_DECODERS;
if (schemaDecodeArray == (VtSchemaDecodeArray *)0)
break;
DecodersToUse = schemaDecodeArray->decoders;
decodersToUseCount = schemaDecodeArray->decoderCount;
}
/* If we don't have an mpCtx, get one from the libCtx. If there is
* not one there, break, that's an error.
*/
if (mpCtxToUse == (VtMpIntCtx)0)
{
mpCtxToUse = (VtMpIntCtx)VoltGetLibCtxInfo (
obj->voltObject.libraryCtx, VOLT_LIB_CTX_INFO_TYPE_MP_CTX);
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_MATH_LIBRARY;
if (mpCtxToUse == (VtMpIntCtx)0)
break;
}
/* Paranoid programming check.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_MP_INT_CTX;
if (VOLT_OBJECT_TYPE_NOT_EQUAL (mpCtxToUse, VOLT_OBJECT_TYPE_MP_INT_CTX))
break;
/* Build a buffer big enough to hold the readCtx, the coder array,
* and the schema decode's. Assume that the array of DerCoder
* pointers will not throw off the pad.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize =
sizeof (VoltSecureMailReadCtx) +
(listToUseCount * sizeof (VtDerCoder *)) +
decodersToUseCount * sizeof (VtIdentitySchemaDecode *);
#if VOLT_ALIGNMENT != 1
/* If the alignment is 1, there's no need to pad. If not, compute
* the pad length.
*/
VOLT_COMPUTE_ALIGN_PAD (
VOLT_ALIGNMENT, sizeof (VoltSecureMailReadCtx), pad)
bufferSize += pad;
#endif
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
/* Locate the pointers.
*/
readCtx = (VoltSecureMailReadCtx *)buffer;
offset = sizeof (VoltSecureMailReadCtx);
#if VOLT_ALIGNMENT != 1
offset += pad;
#endif
/* Copy the DerCoders array.
*/
readCtx->DerCoders = (VtDerCoder **)(buffer + offset);
for (index = 0; index < listToUseCount; ++index)
readCtx->DerCoders[index] = ListToUse[index];
readCtx->derCoderCount = listToUseCount;
/* Copy the schemaDecode's.
*/
offset += listToUseCount * sizeof (VtDerCoder *);
readCtx->Decoders = (VtIdentitySchemaDecode **)(buffer + offset);
for (index = 0; index < decodersToUseCount; ++index)
readCtx->Decoders[index] = DecodersToUse[index];
readCtx->decoderCount = decodersToUseCount;
/* Clone the mpCtx.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)mpCtxToUse, (Pointer *)&(readCtx->mpCtx));
if (status != 0)
break;
/* Initialize the contentMaterialState
*/
readCtx->contentMaterialState = VOLT_CONTENT_MATERIAL_STATE_NONE;
/* Build the P7 objects.
*/
p7Info.derCoders = ListToUse;
p7Info.derCoderCount = listToUseCount;
p7Info.decoders = DecodersToUse;
p7Info.decoderCount = decodersToUseCount;
p7Info.mpCtx = mpCtxToUse;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreatePkcs7Object (
(VtLibCtx)libCtx, VtPkcs7ImplReadSignedData, (Pointer)&p7Info,
&(obj->p7SignedData));
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreatePkcs7Object (
(VtLibCtx)libCtx, VtPkcs7ImplReadEnvelopedData, (Pointer)&p7Info,
&(obj->p7EnvelopedData));
if (status != 0)
break;
obj->state = VOLT_SECURE_MAIL_STATE_READ_SET;
obj->localCtx = (Pointer)readCtx;
obj->LocalCtxDestroy = VoltReadSecureMailCtxDestroy;
obj->ReadInit = VoltSecureFileReadInit;
obj->ReadUpdate = VoltSecureFileReadUpdate;
obj->ReadFinal = VoltSecureFileReadFinal;
obj->Verify = VoltSecureMailVerify;
obj->GetEncodeDecodeSize = VoltCopyGetEncodeDecodeSize;
status = 0;
} while (0);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If there was an error, destroy what we created.
*/
VoltReadSecureMailCtxDestroy ((Pointer)obj, (Pointer)readCtx);
VOLT_LOG_ERROR_INFO (
0, *object, status, 0, errorType,
(char *)0, "VtSecureFileImplRead", fnctLine, (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -