📄 sawrite.c
字号:
if (VOLT_OBJECT_TYPE_NOT_EQUAL(policyCtx, VOLT_OBJECT_TYPE_POLICY_CTX))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_POLICY_CTX;
break;
}
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetLibCtxParam(libCtx, VtLibCtxParamPolicyCtx, (Pointer*)&policyCtx);
if (status == VT_ERROR_GET_INFO_UNAVAILABLE)
status = 0;
if (status != 0)
break;
}
if (storageCtx != (VtStorageCtx)0)
{
if (VOLT_OBJECT_TYPE_NOT_EQUAL(storageCtx, VOLT_OBJECT_TYPE_STORAGE_CTX))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_STORAGE_CTX;
break;
}
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetLibCtxParam(libCtx, VtLibCtxParamStorageCtx, (Pointer*)&storageCtx);
if (status == VT_ERROR_GET_INFO_UNAVAILABLE)
status = 0;
if (status != 0)
break;
}
if (transportCtx != (VtTransportCtx)0)
{
if (VOLT_OBJECT_TYPE_NOT_EQUAL(transportCtx, VOLT_OBJECT_TYPE_TRANSPORT_CTX))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_TRANSPORT_CTX;
break;
}
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetLibCtxParam(libCtx, VtLibCtxParamTransportCtx, (Pointer*)&transportCtx);
if (status == VT_ERROR_GET_INFO_UNAVAILABLE)
status = 0;
if (status != 0)
break;
}
if (random != (VtRandomObject)0)
{
if (VOLT_OBJECT_TYPE_NOT_EQUAL(random, VOLT_OBJECT_TYPE_RANDOM))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_RANDOM_OBJ;
break;
}
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtGetLibCtxParam(libCtx, VtLibCtxParamRandomObj, (Pointer*)&random);
if (status == VT_ERROR_GET_INFO_UNAVAILABLE)
status = 0;
if (status != 0)
break;
}
/* Stash away the contexts and random objects, so we can use them later
* to init the PKCS7 objects.
*/
localCtx->mPolicyCtx = policyCtx;
localCtx->mStorageCtx = storageCtx;
localCtx->mTransportCtx = transportCtx;
localCtx->mRandom = random;
/* Create the output stream for the archive object */
if (localCtx->mOutputStream == (VtStreamObject)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&localCtx->mBufferTypeInfo, &localCtx->mOutputStream);
if (status != 0)
break;
VT_ASSERT(localCtx->mOutputStream != (VtStreamObject)0);
localCtx->mDestroyOutputStream = 1;
}
/* Create the archive object */
if (localCtx->mArchiveObject == (VtArchiveObject)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateArchiveObject(libCtx, VtArchiveImplZipWrite,
(Pointer)0, &localCtx->mArchiveObject);
if (status != 0)
break;
bufferTypeInfo.bufferType = VT_BUFFER_TYPE_STREAM;
bufferTypeInfo.streamObj = localCtx->mOutputStream;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtSetArchiveParam(localCtx->mArchiveObject,
VtArchiveParamBufferType, (Pointer)&bufferTypeInfo);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtArchiveWriteInit(localCtx->mArchiveObject);
if (status != 0)
break;
}
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, 0,
fnctLine, "VoltSecureArchiveWriteGetParam", (unsigned char*)0)
return status;
}
int VoltSecureArchiveWriteUpdate(
VtSecureArchiveObject secureArchiveObj,
unsigned char *inputData,
unsigned int inputDataLen,
unsigned char *message,
unsigned int bufferSize,
unsigned int *messageLen
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltSecureArchiveWriteLocalCtx* localCtx;
VtCompressObject compressObj = (VtCompressObject)0;
VtStreamObject streamObj = (VtStreamObject)0;
unsigned char* outputBuffer = (unsigned char*)0;
unsigned char* inputPtr;
unsigned int remainingInput;
unsigned int inputConsumed;
unsigned int compressedBytes;
VtStreamSize readSize;
VoltSecureArchiveEntryInfo* secureEntryInfo;
unsigned char compressionString[256];
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VtSecureArchiveObject)0);
libCtx = secureArchiveObj->voltObject.libraryCtx;
localCtx = (VoltSecureArchiveWriteLocalCtx*) secureArchiveObj->localCtx;
do
{
VOLT_SET_ERROR_TYPE(errorType, 0)
if (localCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_DONE)
{
if (localCtx->mOutputType == VOLT_SECURE_ARCHIVE_OUTPUT_TYPE_ARCHIVE)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamRead(localCtx->mOutputStream, message,
bufferSize, &readSize);
if (status != 0)
break;
*messageLen = readSize;
}
else
{
VT_ASSERT(localCtx->mOutputType ==
VOLT_SECURE_ARCHIVE_OUTPUT_TYPE_ENCRYPTED_INDEX);
VT_ASSERT(localCtx->mArchiveObject != (VtArchiveObject)0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VtArchiveReadUpdate(localCtx->mArchiveObject,
(unsigned char*)0, 0, message, bufferSize, messageLen);
if (status != 0)
break;
}
}
else
{
/* Create the stream for the current entry if necessary */
if (localCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX)
{
if (localCtx->mIndexDataStream == (VtStreamObject)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&localCtx->mBufferTypeInfo, &localCtx->mIndexDataStream);
if (status != 0)
break;
}
streamObj = localCtx->mIndexDataStream;
}
else
{
if (localCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE)
{
VT_ASSERT(localCtx->mSecureEntryCount > 0);
secureEntryInfo = localCtx->mSecureEntryInfo +
localCtx->mSecureEntryCount - 1;
}
if (localCtx->mCurrentEntryStream == (VtStreamObject)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&localCtx->mBufferTypeInfo, &localCtx->mCurrentEntryStream);
if (status != 0)
break;
if (localCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE)
{
if (localCtx->mCompressionEnabled)
secureEntryInfo->mCompression = 1;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(localCtx->mCurrentEntryStream,
VoltSecureArchiveCompressionAttributeName,
Z2Strlen(VoltSecureArchiveCompressionAttributeName));
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(localCtx->mCurrentEntryStream, ": ", 2);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltNumToDecimalString(secureEntryInfo->mCompression,
compressionString, sizeof(compressionString), libCtx);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(localCtx->mCurrentEntryStream,
compressionString, Z2Strlen(compressionString));
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(localCtx->mCurrentEntryStream, "\n\n", 2);
if (status != 0)
break;
}
}
streamObj = localCtx->mCurrentEntryStream;
if ((localCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE) &&
localCtx->mCompressionEnabled)
{
/* Create the compress object if we haven't already */
if (localCtx->mCompressObject == (VtCompressObject)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateCompressObject(libCtx, VtCompressImplZlib,
(Pointer)0, &localCtx->mCompressObject);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCompressInit(localCtx->mCompressObject);
if (status != 0)
break;
}
VT_ASSERT(localCtx->mCompressObject != (VtCompressObject)0);
compressObj = localCtx->mCompressObject;
}
}
if (compressObj != (VtCompressObject)0)
{
VT_ASSERT(secureEntryInfo != (VoltSecureArchiveEntryInfo*)0);
secureEntryInfo->mSize += inputDataLen;
outputBuffer = Z3Malloc(VOLT_TEMP_BUFFER_SIZE);
if (outputBuffer == (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
break;
}
inputPtr = inputData;
remainingInput = inputDataLen;
while (remainingInput > 0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCompressUpdate(compressObj, 0, inputPtr,
remainingInput, &inputConsumed, outputBuffer,
VOLT_TEMP_BUFFER_SIZE, &compressedBytes);
if (status != 0)
break;
if (compressedBytes > 0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(streamObj, outputBuffer, compressedBytes);
if (status != 0)
break;
}
inputPtr += inputConsumed;
remainingInput -= inputConsumed;
}
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(streamObj, inputData, inputDataLen);
if (status != 0)
break;
}
}
}
while (0);
Z2Free(outputBuffer);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine, "VoltSecureArchiveWriteUpdate", (unsigned char*)0)
return status;
}
int VoltSecureArchiveWriteFinal(
VtSecureArchiveObject secureArchiveObj,
unsigned char *output,
unsigned int bufferSize,
unsigned int *outputLen
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltSecureArchiveWriteLocalCtx* localCtx;
VtStreamSize position;
VtStreamSize size;
VtStreamSize readSize;
unsigned int remaining;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VtSecureArchiveObject)0);
libCtx = secureArchiveObj->voltObject.libraryCtx;
localCtx = (VoltSecureArchiveWriteLocalCtx*) secureArchiveObj->localCtx;
do
{
VOLT_SET_ERROR_TYPE(errorType, 0)
if (localCtx->mOutputType == VOLT_SECURE_ARCHIVE_OUTPUT_TYPE_ARCHIVE)
{
/* Get the current position and size of the output stream so we
* can see how much data is remaining. Since this is the final
* call, the output buffer that was passed in needs to be big
* enough to hold all of the remaining archive data. Otherwise
* we return VT_ERROR_BUFFER_TOO_SMALL.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamGetPosition(localCtx->mOutputStream, &position);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamGetSize(localCtx->mOutputStream, &size);
if (status != 0)
break;
remaining = size - position;
if (remaining > bufferSize)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
*outputLen = remaining;
status = VT_ERROR_BUFFER_TOO_SMALL;
break;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamRead(localCtx->mOutputStream, output,
bufferSize, &readSize);
*outputLen = (unsigned int) readSize;
}
else
{
VT_ASSERT(localCtx->mOutputType ==
VOLT_SECURE_ARCHIVE_OUTPUT_TYPE_ENCRYPTED_INDEX);
VT_ASSERT(localCtx->mArchiveObject != (VtArchiveObject)0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VtArchiveReadFinal(localCtx->mArchiveObject,
output, bufferSize, outputLen);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -