⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saread.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 5 页
字号:
          break;
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtSetArchiveParam(readCtx->mArchive,
          VtArchiveParamCurrentEntryPath, (Pointer)entryName);
        if (status != 0)
          break;
        
        /* We also need to remember the entry index, so that we can look
          * up entry attributes such as the size and file name
          */
        readCtx->mCurrentEntryIndex = currentEntryInfo->index;
      }
      else if (currentEntryInfo->type == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INSECURE)
      {
        /* Check that caller has passed in a valid entry name */
        if (currentEntryInfo->name == (unsigned char*)0)
        {
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VT_ERROR_INVALID_ASSOCIATED_INFO;
          break;
        }
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VoltSecureArchiveArchiveInit(secureArchiveObj);
        if (status != 0)
          break;
          
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtSetArchiveParam(readCtx->mArchive,
          VtArchiveParamCurrentEntryPath, (Pointer)currentEntryInfo->name);
        if (status != 0)
          break;
      }
      else if ((currentEntryInfo->type != VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX) &&
        (currentEntryInfo->type != VT_SECURE_ARCHIVE_CURRENT_ENTRY_DONE))
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_INVALID_ASSOCIATED_INFO;
        break;
      }
      
      VtDestroyStreamObject(&readCtx->mOutputStream);
      readCtx->mCurrentEntryType = currentEntryInfo->type;
      break;
    
    case VOLT_SECURE_ARCHIVE_PARAM_SURRENDER_CALLBACK:
    
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltSetObjectSurrender (
        (VoltObject *)secureArchiveObj, setInfo, 0, 0, 0);
      break;
       
    default:
    
      VOLT_SET_FNCT_LINE(fnctLine)
      VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
      status = VT_ERROR_INVALID_SET;
      break;
  }
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
     fnctLine,"VoltSecureArchiveReadSetParam", (unsigned char*)0)
    
  return status;
}

static int VoltSecureArchiveReadGetParam(
   VtSecureArchiveObject secureArchiveObj,
   int paramSelector,
   Pointer* getInfo
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureArchiveReadLocalCtx* readCtx;
  VtSecureArchiveAttributeInfo attributeInfo;
  VtSecureArchiveAttributeInfo* attributeInfoPtr;
  long fileSize;
  VtDataNodeObject entryListNode;
  int entryCount;
  VtTime modDate;
  int modDateNameLength;
  unsigned char attributeName[100];
  unsigned char* attributeValue;
  long num;
  int i;
  unsigned int outputSize;
  VtStreamObject stream;
  VtStreamSize position;
  VtStreamSize size;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)

  VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
  VT_ASSERT(getInfo != (Pointer*)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_LIST:
    
      if (readCtx->mEnvelopedData == (VtPkcs7Object)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_GET_INFO_UNAVAILABLE;
        break;
      }
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtGetPkcs7Param(readCtx->mEnvelopedData,
        VtPkcs7ParamRecipientList, (Pointer*)getInfo);
      break;
      
    case VOLT_SECURE_ARCHIVE_PARAM_RECIPIENT_INFO_LIST:

      if (readCtx->mEnvelopedData == (VtPkcs7Object)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_GET_INFO_UNAVAILABLE;
        break;
      }
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtGetPkcs7Param(readCtx->mEnvelopedData,
        VtPkcs7ParamRecipientInfoList, (Pointer*)getInfo);
      break;

    case VOLT_SECURE_ARCHIVE_PARAM_SIGNING_TIME:
    
      if (readCtx->mSignedData == (VtPkcs7Object)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_GET_INFO_UNAVAILABLE;
        break;
      }
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtGetPkcs7Param(readCtx->mSignedData,
        VtPkcs7ParamSigningTime, (Pointer*)getInfo);
      break;
    
    case VOLT_SECURE_ARCHIVE_PARAM_ENTRY_COUNT:
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltSecureArchiveDecryptIndex(secureArchiveObj);
      if (status != 0)
        break;
      
      VT_ASSERT(readCtx->mAttributes != (VtDataNodeObject)0);
      
      status = VtDataNodeLookupChild(readCtx->mAttributes,
        VoltSecureArchiveEntryListAttributeName, &entryListNode);
      if (status != 0)
      {
        /* If there's no entry list node, then there are no entries.
         * This would happen, for example, if you have a ZDM with no
         * attachments.
         */
        entryCount = 0;
        status = 0;
      }
      else
      {
        status = VtDataNodeGetChildCount(entryListNode, &entryCount);
        if (status != 0)
          break;
      }
      
      *(unsigned int*)getInfo = entryCount;
      
      break;
      
    case VOLT_SECURE_ARCHIVE_PARAM_ENTRY_ATTRIBUTE:
    
      attributeInfoPtr = (VtSecureArchiveAttributeInfo*)getInfo;
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltSecureArchiveGetEntryAttribute(secureArchiveObj,
        readCtx->mCurrentEntryIndex, attributeInfoPtr->name,
        &attributeInfoPtr->value);
      break;
      
    case VOLT_SECURE_ARCHIVE_PARAM_ARCHIVE_ATTRIBUTE:
    
      attributeInfoPtr = (VtSecureArchiveAttributeInfo*)getInfo;
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltSecureArchiveGetArchiveAttribute(secureArchiveObj,
        attributeInfoPtr->name, &attributeInfoPtr->value);
      break;
      
    case VOLT_SECURE_ARCHIVE_PARAM_FILE_NAME:
    
      attributeInfo.name = VoltSecureArchiveNameAttributeName;
      attributeInfo.value = (unsigned char*)0;
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltSecureArchiveGetEntryAttribute(secureArchiveObj,
        readCtx->mCurrentEntryIndex, attributeInfo.name,
        &attributeInfo.value);
      if (status != 0)
        break;
        
      *(const unsigned char**)getInfo = attributeInfo.value;
      break;
      
    case VOLT_SECURE_ARCHIVE_PARAM_FILE_SIZE:
    
      attributeInfo.name = VoltSecureArchiveSizeAttributeName;
      attributeInfo.value = (unsigned char*)0;
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltSecureArchiveGetEntryAttribute(secureArchiveObj,
        readCtx->mCurrentEntryIndex, attributeInfo.name,
        &attributeInfo.value);
      if (status != 0)
        break;
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltDecimalStringToNum(attributeInfo.value, &fileSize, libCtx);
      if (status != 0)
        break;

      /* TODO: Should add sanity checks on the fileSize that's returned */
      *(unsigned int*)getInfo = (unsigned int)fileSize;
      break;
      
    case VOLT_SECURE_ARCHIVE_PARAM_MOD_DATE:
    {
      const unsigned char* dateNames[6] = {
        VoltSecureArchiveYearAttributeName,
        VoltSecureArchiveMonthAttributeName,
        VoltSecureArchiveDayAttributeName,
        VoltSecureArchiveHourAttributeName,
        VoltSecureArchiveMinuteAttributeName,
        VoltSecureArchiveSecondAttributeName
      };
      int* dateValues[6] = {
        &modDate.year,
        &modDate.month,
        &modDate.day,
        &modDate.hour,
        &modDate.minute,
        &modDate.second
      };
      
      modDateNameLength = Z2Strlen(VoltSecureArchiveModDateAttributeName);
        
      for (i = 0; i < 6; i++)
      {
        Strcpy(attributeName, (char*) VoltSecureArchiveModDateAttributeName,
          libCtx);
        attributeName[modDateNameLength] = '.';
        Strcpy(attributeName + modDateNameLength + 1,
          (char*) dateNames[i], libCtx);
          
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VoltSecureArchiveGetEntryAttribute(secureArchiveObj,
          readCtx->mCurrentEntryIndex, attributeName, &attributeValue);
        if (status != 0)
          break;
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VoltDecimalStringToNum(attributeValue, &num, libCtx);
        if (status != 0)
          break;
        
        *(dateValues[i]) = (int) num;
      }
      if (status != 0)
        break;
      
      *(VtTime*)getInfo = modDate;
      
      break;
    }
      
    case VOLT_SECURE_ARCHIVE_PARAM_SIGNER_LIST:
    
      if (readCtx->mSignedData == (VtPkcs7Object)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_GET_INFO_UNAVAILABLE;
        break;
      }
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtGetPkcs7Param(readCtx->mSignedData,
        VtPkcs7ParamSignerList, (Pointer*)getInfo);
      break;
    
    case VOLT_SECURE_ARCHIVE_PARAM_ATTRIBUTES_NODE:
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltSecureArchiveDecryptIndex(secureArchiveObj);
      if (status != 0)
        break;
      VT_ASSERT(readCtx->mAttributes != (VtDataNodeObject)0);
      *(VtDataNodeObject*)getInfo = readCtx->mAttributes;
      break;
    
    case VOLT_SECURE_ARCHIVE_PARAM_REMAINING_OUTPUT_SIZE:
    
      stream = (VtStreamObject)0;
      if (readCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX)
      {
        if (readCtx->mIndexDataStream == (VtStreamObject)0)
        {
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VoltSecureArchiveDecryptIndex(secureArchiveObj);
          if (status != 0)
            break;
          VT_ASSERT(readCtx->mIndexDataStream != (VtStreamObject)0);
        }
        stream = readCtx->mIndexDataStream;
      }
      else if (readCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE)
      {
        if (readCtx->mOutputStream == (VtStreamObject)0)
        {
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VoltSecureArchiveDecryptSecureEntry(secureArchiveObj);
          if (status != 0)
            break;
          
          VT_ASSERT(readCtx->mOutputStream != (VtStreamObject)0);
        }
        stream = readCtx->mOutputStream;
      }
      else if (readCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INSECURE)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        #if 0
        //status = VtArchiveReadFinal(readCtx->mArchive, (unsigned char*)0, 0, &outputSize);
        //status = VtGetArchiveParam(readCtx->mArchive,
        //  VtArchiveParamRemainingOutputSize, (Pointer*)&outputSize);
        if (status != 0)
          break;
        *(unsigned char*)getInfo = outputSize;
        #else
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_UNSUPPORTED;
        #endif
        break;
      }
      
      if (stream == (VtStreamObject)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_INVALID_CALL_ORDER;
        break;
      }
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtStreamGetPosition(stream, &position);
      if (status != 0)
        break;
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtStreamGetSize(stream, &size);
      if (status != 0)
        break;
      
      outputSize = size - position;
      *(unsigned int*)getInfo = outputSize;
      break;
      
    default:
    
      VOLT_SET_FNCT_LINE(fnctLine)
      VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
      status = VT_ERROR_INVALID_GET;
      break;
  }
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
     fnctLine,"VoltSecureArchiveReadGetParam", (unsigned char*)0)
    
  return status;
}

static int VoltSecureArchiveReadInit(
   VtSecureArchiveObject secureArchiveObj
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureArchiveReadLocalCtx* readCtx;
  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);

  do
  {
    if (readCtx->mInputStream == (VtStreamObject)0)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltCreateTempBufferStream(libCtx,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -