📄 saread.c
字号:
if (status != 0)
break;
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveGetArchiveAttribute", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveGetEntryAttribute(
VtSecureArchiveObject secureArchiveObj,
unsigned int entryIndex,
const unsigned char* name,
const unsigned char** value
)
{
int status = 0;
VtLibCtx libCtx;
unsigned char expression[1000];
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
VT_ASSERT(name != (unsigned char*)0);
VT_ASSERT(value != (unsigned char**)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
libCtx = secureArchiveObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
do
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveFormatEntryExpression(libCtx, entryIndex,
name, expression, sizeof(expression));
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveGetArchiveAttribute(secureArchiveObj,
expression, value);
if (status != 0)
break;
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveGetEntryAttribute", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveSkipPastHeaders(
VtStreamObject stream,
VtLibCtx libCtx
)
{
int status = 0;
unsigned char c;
unsigned char previous = 0;
unsigned int readSize;
int eolCount = 0;
int isCRLF;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VT_ASSERT(stream != (VtStreamObject)0);
VT_ASSERT(libCtx != (VtLibCtx)0);
for (;;)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamRead(stream, &c, 1, &readSize);
if (status != 0)
{
if (eolCount == 2)
status = 0;
break;
}
VT_ASSERT(readSize == 1);
isCRLF = (c == '\n') && (previous == '\r');
if (!isCRLF)
{
if (eolCount == 2)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(stream, -1, VT_STREAM_FROM_POSITION);
break;
}
if ((c == '\r') || (c == '\n'))
eolCount++;
else
eolCount = 0;
}
previous = c;
}
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, 0,
fnctLine,"VoltSecureArchiveSkipPastHeaders", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveDecryptSecureEntry(
VtSecureArchiveObject secureArchiveObj
)
{
int status = 0;
VtLibCtx libCtx;
VoltSecureArchiveReadLocalCtx* readCtx;
long compression = 0;
const unsigned char* compressionString;
VtStreamObject compressedStream = (VtStreamObject)0;
int final = 0;
unsigned int inputBufferSize = 1024;
unsigned int outputBufferSize = 4096;
unsigned char* inputBuffer = (unsigned char*)0;
unsigned char* outputBuffer = (unsigned char*)0;
VtStreamSize inputSize = 0;
unsigned int outputSize;
VtStreamSize inputConsumed = 0;
unsigned int bytesConsumed;
VtCompressObject compressObj = (VtCompressObject)0;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
libCtx = secureArchiveObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);
VT_ASSERT(readCtx->mAttributes != (VtDataNodeObject)0);
VT_ASSERT(readCtx->mOutputStream == (VtStreamObject)0);
do
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveGetEntryAttribute(secureArchiveObj,
readCtx->mCurrentEntryIndex, VoltSecureArchiveCompressionAttributeName,
&compressionString);
if (status == 0)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltDecimalStringToNum(compressionString, &compression, libCtx);
if (status != 0)
break;
if ((compression != 0) && (compression != 1))
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_COMPRESSION_ALG;
break;
}
}
else if (status != VT_ERROR_DATA_NODE_NOT_FOUND)
{
/* VT_ERROR_DATA_NODE_NOT_FOUND means no compression. Any other
* error is a real error.
*/
break;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&readCtx->mBufferTypeInfo, &readCtx->mOutputStream);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveDecryptDataInit(secureArchiveObj);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveDecryptData(secureArchiveObj,
readCtx->mOutputStream, &final);
if (status != 0)
break;
VT_ASSERT(final == 1);
/* Reset the position to the start */
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(readCtx->mOutputStream,
0, VT_STREAM_FROM_START);
if (status != 0)
break;
/* The secure entry data begins with a compression header
* followed by a blank line. We already know what the
* compression is from the headers stored in the index,
* so we don't need to parse the headers. Instead we just
* skip past them to get to the start of the actual data.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveSkipPastHeaders(readCtx->mOutputStream, libCtx);
if (status != 0)
break;
if (compression != 0)
{
compressedStream = readCtx->mOutputStream;
readCtx->mOutputStream = (VtStreamObject)0;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&readCtx->mBufferTypeInfo, &readCtx->mOutputStream);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateCompressObject(libCtx, VtCompressImplZlib,
(Pointer)0, &compressObj);
if (status != 0)
break;
VT_ASSERT(compressObj != (VtCompressObject)0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDecompressInit(compressObj);
if (status != 0)
break;
inputBuffer = (unsigned char*) Z3Malloc(inputBufferSize);
if (inputBuffer == (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
break;
}
outputBuffer = (unsigned char*) Z3Malloc(outputBufferSize);
if (outputBuffer == (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
break;
}
final = 0;
do
{
if (inputConsumed == inputSize)
{
status = VtStreamRead(compressedStream, inputBuffer,
inputBufferSize, &inputSize);
if (status == VT_ERROR_END_OF_STREAM)
final = 1;
else if (status != 0)
break;
inputConsumed = 0;
}
if (final)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDecompressFinal(compressObj, outputBuffer,
outputBufferSize, &outputSize);
if (status != 0)
break;
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDecompressUpdate(compressObj, VT_COMPRESS_FLUSH,
inputBuffer + inputConsumed, inputSize - inputConsumed,
&bytesConsumed, outputBuffer, outputBufferSize, &outputSize);
if (status != 0)
break;
inputConsumed += bytesConsumed;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(readCtx->mOutputStream, outputBuffer, outputSize);
if (status != 0)
break;
}
while (!final);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(readCtx->mOutputStream,
0, VT_STREAM_FROM_START);
if (status != 0)
break;
}
}
while (0);
VtDestroyCompressObject(&compressObj);
VtDestroyStreamObject(&compressedStream);
Z2Free(inputBuffer);
Z2Free(outputBuffer);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveDecryptSecureEntry", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveReadSetParam(
VtSecureArchiveObject secureArchiveObj,
int paramSelector,
Pointer setInfo
)
{
int status = 0;
VtLibCtx libCtx = (VtLibCtx)0;
VoltSecureArchiveReadLocalCtx* readCtx;
VtStreamObject inputStream;
VtSecureArchiveCurrentEntryInfo* currentEntryInfo;
unsigned int length;
unsigned char entryName[100];
VtSecureArchiveRecipientIndexInfo* recipientIndexInfo;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
libCtx = secureArchiveObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);
switch (paramSelector)
{
case VOLT_SECURE_ARCHIVE_PARAM_RECIPIENT_INDEX:
if (setInfo != (Pointer)0)
{
recipientIndexInfo = (VtSecureArchiveRecipientIndexInfo*)setInfo;
readCtx->mRecipientIndexInfo.index = recipientIndexInfo->index;
readCtx->mRecipientIndexInfo.policyCtx = recipientIndexInfo->policyCtx;
readCtx->mRecipientIndexInfo.storageCtx = recipientIndexInfo->storageCtx;
readCtx->mRecipientIndexInfo.transportCtx = recipientIndexInfo->transportCtx;
readCtx->mRecipientIndexInfoValid = 1;
}
else
{
readCtx->mRecipientIndexInfoValid = 0;
}
break;
case VOLT_SECURE_ARCHIVE_PARAM_BUFFER_TYPE:
if (setInfo != (Pointer)0)
{
readCtx->mBufferTypeInfo = *(VtBufferTypeInfo*) setInfo;
}
else
{
Z2Memset(&readCtx->mBufferTypeInfo, 0, sizeof(readCtx->mBufferTypeInfo));
readCtx->mBufferTypeInfo.bufferType = VT_BUFFER_TYPE_MEMORY;
}
break;
case VOLT_SECURE_ARCHIVE_PARAM_INPUT_STREAM:
inputStream = (VtStreamObject)setInfo;
if (VOLT_OBJECT_TYPE_NOT_EQUAL(inputStream, VOLT_OBJECT_TYPE_STREAM))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_INVALID_STREAM;
break;
}
readCtx->mInputStream = inputStream;
break;
case VOLT_SECURE_ARCHIVE_PARAM_CURRENT_ENTRY:
currentEntryInfo = (VtSecureArchiveCurrentEntryInfo*) setInfo;
if ((readCtx->mIndexDataStream == (VtStreamObject)0) &&
((currentEntryInfo->type == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE) ||
(currentEntryInfo->type == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX)))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveDecryptIndex(secureArchiveObj);
if (status != 0)
break;
VT_ASSERT(readCtx->mIndexDataStream != (VtStreamObject)0);
}
if (currentEntryInfo->type == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE)
{
/* The entry name in the archive will be "File_XXX" where XXX is the
* index of the entry. So we need to format the entry name and then
* set the current entry by name in the underlying archive
*/
length = Z2Strlen(VoltSecureArchiveFilePrefixPathName);
VT_ASSERT(length < sizeof(entryName));
Z2Memcpy(entryName, VoltSecureArchiveFilePrefixPathName, length);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltNumToDecimalString(currentEntryInfo->index,
entryName + length, sizeof(entryName) - length, libCtx);
if (status != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -