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

📄 zdm2read.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 3 页
字号:
              {
                VOLT_SET_FNCT_LINE(fnctLine)
                status = VtDecodeUpdate(base64Decoder, (VtRandomObject)0,
                  startData, endData - startData, dataBuffer,
                  dataBufferSize, &dataSize);
              }
            }
            
            if (status != 0)
              break;
            
            status = VtSecureArchiveReadUpdate(readCtx->mSecureArchive,
              dataBuffer, dataSize, &bytesConsumed, (unsigned char*)0,
              0, (unsigned int*)0);
            if (status != 0)
              break;
              
            VT_ASSERT(bytesConsumed == dataSize);
            
            endData = (unsigned char*)0;
          }
        }
      
        if (foundEndTag || (status != 0))
          break;
      }
      
      copySrc = messageBuffer + dataLength - copyDataLength;
      if (startData > copySrc)
      {
        copyDataLength -= (startData - copySrc);
        copySrc = startData;
      }
      
      Z2Memcpy(messageBuffer, copySrc, copyDataLength);
    }
    while (!foundEndTag);
    
    if (readCtx->mOwnsInputStream)
      VtDestroyStreamObject(&readCtx->mInputStream);

    readCtx->mMessageUnwrapped = 1;
  }
  while (0);
  
  VtDestroyAlgorithmObject(&base64Decoder);
  Z2Free(messageBuffer);
  Z2Free(dataBuffer);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine,"VoltZDM2UnwrapMessage", (unsigned char*)0)
    
  return status;
}

static int VoltZDM2InitSecureArchive(
  VtZDMObject zdmObj
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltZDM2ReadLocalCtx* readCtx;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VT_ASSERT(zdmObj != (VtZDMObject)0);

  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  do
  {
    if (!readCtx->mMessageUnwrapped)
    {
      if (readCtx->mInputStream == (VtStreamObject)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_INVALID_CALL_ORDER;
        break;
      }
      
      if (readCtx->mOwnsInputStream)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtStreamSetPosition(readCtx->mInputStream,
          0, VT_STREAM_FROM_START);
        if (status != 0)
          break;
      }
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltZDM2UnwrapMessage(zdmObj);
      if (status != 0)
        break;
    }
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VoltZDM2InitInsecureAttributes(zdmObj);
    if (status != 0)
      break;
    
    readCtx->mSecureArchiveInited = 1;
  }
  while (0);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine,"VoltZDM2InitSecureArchive", (unsigned char*)0)
    
  return status;
}

static int VoltZDM2ReadSetParam(
  VtZDMObject zdmObj,
  int paramSelector,
  Pointer setInfo
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltZDM2ReadLocalCtx* readCtx;
  VtZDMCurrentEntryInfo* zdmCurrentEntryInfo;
  VtSecureArchiveCurrentEntryInfo saCurrentEntryInfo;
  VtZDMRecipientIndexInfo* zdmRecipientIndexInfo;
  VtSecureArchiveRecipientIndexInfo saRecipientIndexInfo;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VT_ASSERT(zdmObj != (VtZDMObject)0);

  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);

  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  switch (paramSelector)
  {
    case VT_ZDM_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;
      }
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtSetSecureArchiveParam(readCtx->mSecureArchive,
        VtSecureArchiveParamBufferType, setInfo);
      break;
    
    case VT_ZDM_PARAM_INPUT_STREAM:
      
      /* This param should be called before calling ReadInit */
      if (readCtx->mReadInitCalled)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_INVALID_CALL_ORDER;
        break;
      }
      
      readCtx->mInputStream = (VtStreamObject)setInfo;
      readCtx->mOwnsInputStream = 0;
      break;
      
    case VT_ZDM_PARAM_RECIPIENT_INDEX:
    
      if (!readCtx->mReadInitCalled)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_INVALID_CALL_ORDER;
        break;
      }
      
      zdmRecipientIndexInfo = (VtZDMRecipientIndexInfo*)setInfo;
      
      saRecipientIndexInfo.index = zdmRecipientIndexInfo->index;
      saRecipientIndexInfo.policyCtx = zdmRecipientIndexInfo->policyCtx;
      saRecipientIndexInfo.storageCtx = zdmRecipientIndexInfo->storageCtx;
      saRecipientIndexInfo.transportCtx = zdmRecipientIndexInfo->transportCtx;
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtSetSecureArchiveParam(readCtx->mSecureArchive,
        VtSecureArchiveParamRecipientIndex,
        (Pointer)&saRecipientIndexInfo);
      break;
    
    case VT_ZDM_PARAM_CURRENT_ENTRY:
      
      if (!readCtx->mSecureArchiveInited)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VoltZDM2InitSecureArchive(zdmObj);
        if (status != 0)
          break;
      }
      
      zdmCurrentEntryInfo = (VtZDMCurrentEntryInfo*)setInfo;
      
      switch (zdmCurrentEntryInfo->type)
      {
        case VT_ZDM_CURRENT_ENTRY_MESSAGE_BODY:
          saCurrentEntryInfo.type = VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX;
          break;
        case VT_ZDM_CURRENT_ENTRY_ATTACHMENT:
          saCurrentEntryInfo.type = VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE;
          saCurrentEntryInfo.index = zdmCurrentEntryInfo->index;
          break;
        case VT_ZDM_CURRENT_ENTRY_DONE:
          saCurrentEntryInfo.type = VT_SECURE_ARCHIVE_CURRENT_ENTRY_DONE;
          break;
        default:
          VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VT_ERROR_INVALID_ZDM_ENTRY;
          break;
      }
      
      if (status != 0)
        break;
        
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtSetSecureArchiveParam(readCtx->mSecureArchive,
        VtSecureArchiveParamCurrentEntry, (Pointer)&saCurrentEntryInfo);
      if (status != 0)
        break;
      
      readCtx->mCurrentEntryType = zdmCurrentEntryInfo->type;
      
      break;
    
    case VT_ZDM_PARAM_MESSAGE_FORMAT:
    
      readCtx->mMessageFormat = *(unsigned int*)setInfo;
      break;
    
    case VT_ZDM_PARAM_SURRENDER_CALLBACK:
    
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtSetSecureArchiveParam(readCtx->mSecureArchive,
        VtSecureArchiveParamSurrenderCallback, setInfo);
      break;
      
    default:
    
      VOLT_SET_FNCT_LINE(fnctLine)
      VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
      status = VT_ERROR_INVALID_ZDM_OBJ;
      break;
  }
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine,"VoltZDM2ReadSetParam", (unsigned char*)0)
    
  return status;
}

static int VoltZDM2ReadGetParam(
   VtZDMObject zdmObj,
   int paramSelector,
   Pointer *getInfo
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltZDM2ReadLocalCtx* readCtx;
  VtSecureArchiveAttributeInfo attributeInfo;
  VtDataNodeObject node;
  VtSecureArchiveParam* saParam;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VT_ASSERT(zdmObj != (VtZDMObject)0);

  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  readCtx = (VoltZDM2ReadLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(readCtx != (VoltZDM2ReadLocalCtx*)0);

  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  do
  {
    /* First check to see if it's a valid param to get */
    switch (paramSelector)
    {
      case VT_ZDM_PARAM_SIGNER_LIST:
      case VT_ZDM_PARAM_MESSAGE_TIME:
      case VT_ZDM_PARAM_RECIPIENT_LIST:
      case VT_ZDM_PARAM_RECIPIENT_INFO_LIST:
      case VT_ZDM_PARAM_SUBJECT_LINE:
      case VT_ZDM_PARAM_CHARACTER_SET:
      case VT_ZDM_PARAM_ORIGINAL_CHARACTER_SET:
      case VT_ZDM_PARAM_CONTENT_TYPE:
      case VT_ZDM_PARAM_REPLY_TO:
      case VT_ZDM_PARAM_MESSAGE_ID:
      case VT_ZDM_PARAM_INSECURE_MESSAGE_ID:
      case VT_ZDM_PARAM_FILE_NAME:
      case VT_ZDM_PARAM_FILE_SIZE:
      case VT_ZDM_PARAM_PRIMARY_EMAIL_LIST:
      case VT_ZDM_PARAM_CC_EMAIL_LIST:
      case VT_ZDM_PARAM_ATTACHMENT_COUNT:
      case VT_ZDM_PARAM_REMAINING_OUTPUT_SIZE:
        break;
        
      default:
      
        VOLT_SET_FNCT_LINE(fnctLine)
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        status = VT_ERROR_INVALID_GET;
        break;
    }
    
    if (status != 0)
      break;
      
    if (!readCtx->mSecureArchiveInited)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltZDM2InitSecureArchive(zdmObj);
      if (status != 0)
      {
        if (status != VT_ERROR_INVALID_CALL_ORDER)
          status = VT_ERROR_GET_INFO_UNAVAILABLE;
        break;
      }
    }
    
    switch (paramSelector)
    {
      case VT_ZDM_PARAM_SIGNER_LIST:
      
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamSignerList, getInfo);
        break;
        
      case VT_ZDM_PARAM_MESSAGE_TIME:
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamSigningTime, getInfo);
        break;
        
      case VT_ZDM_PARAM_RECIPIENT_LIST:
      
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamRecipientList, getInfo);
        break;
        
      case VT_ZDM_PARAM_RECIPIENT_INFO_LIST:

        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamRecipientInfoList, getInfo);
        break;

      case VT_ZDM_PARAM_SUBJECT_LINE:
      
        attributeInfo.name = VoltZDM2SubjectAttributeName;
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamArchiveAttribute, (Pointer*)&attributeInfo);
        if (status != 0)
          break;
        *(const unsigned char**)getInfo = attributeInfo.value;
        break;
     
      case VT_ZDM_PARAM_CHARACTER_SET:
      case VT_ZDM_PARAM_ORIGINAL_CHARACTER_SET:
      case VT_ZDM_PARAM_CONTENT_TYPE:
      
        if (paramSelector == VT_ZDM_PARAM_CHARACTER_SET)
          attributeInfo.name = VoltZDM2CharacterSetAttributeName;
        else if (paramSelector == VT_ZDM_PARAM_ORIGINAL_CHARACTER_SET)
          attributeInfo.name = VoltZDM2OriginalCharacterSetAttributeName;
        else
          attributeInfo.name = VoltZDM2ContentTypeAttributeName;
        
        if (readCtx->mCurrentEntryType == VT_ZDM_CURRENT_ENTRY_ATTACHMENT)
          saParam = VtSecureArchiveParamEntryAttribute;
        else
          saParam = VtSecureArchiveParamArchiveAttribute;
          
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          saParam, (Pointer*)&attributeInfo);
        if (status == VT_ERROR_DATA_NODE_NOT_FOUND)
          status = VT_ERROR_ATTRIBUTE_NOT_SET;
        if (status != 0)
          break;
        *(const unsigned char**)getInfo = attributeInfo.value;
        break;
        
      case VT_ZDM_PARAM_REPLY_TO:
      
        attributeInfo.name = VoltZDM2ReplyToAttributeName;
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamArchiveAttribute, (Pointer*)&attributeInfo);
        if (status != 0)
          break;
        *(const unsigned char**)getInfo = attributeInfo.value;
        break;
        
      case VT_ZDM_PARAM_MESSAGE_ID:

        attributeInfo.name = VoltZDM2MessageIDAttributeName;
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamArchiveAttribute, (Pointer*)&attributeInfo);
        if (status != 0)
          break;
        *(const unsigned char**)getInfo = attributeInfo.value;
        break;
        
      case VT_ZDM_PARAM_INSECURE_MESSAGE_ID:

        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtDataNodeResolveChild(readCtx->mInsecureAttributes,
          VoltZDM2MessageIDAttributeName, 0, &node);
        if (status != 0)
          break;
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtDataNodeGetStringValue(node, (const unsigned char**)getInfo);
        break;
        
      case VT_ZDM_PARAM_FILE_NAME:
      
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamFileName, getInfo);
        break;
        
      case VT_ZDM_PARAM_FILE_SIZE:
      
        if (readCtx->mCurrentEntryType != VT_ZDM_CURRENT_ENTRY_ATTACHMENT)
        {
          VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VT_ERROR_INVALID_CALL_ORDER;
          break;
        }
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamFileSize, getInfo);
        break;
        
      case VT_ZDM_PARAM_PRIMARY_EMAIL_LIST:
      case VT_ZDM_PARAM_CC_EMAIL_LIST:

        if (!readCtx->mEmailRecipientsInited)
        {
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VoltZDM2InitEmailRecipients(zdmObj);
          if (status != 0)
            break;
        }
        
        VT_ASSERT(readCtx->mEmailRecipientsInited);
        
        *(VtZDMEmailRecipientList**)getInfo =
          (paramSelector == VT_ZDM_PARAM_PRIMARY_EMAIL_LIST) ?
          &readCtx->mPrimaryRecipientList : &readCtx->mCCRecipientList;
        break;
      
      case VT_ZDM_PARAM_ATTACHMENT_COUNT:
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamEntryCount, getInfo);
        break;
      
      case VT_ZDM_PARAM_REMAINING_OUTPUT_SIZE:
      
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtGetSecureArchiveParam(readCtx->mSecureArchive,
          VtSecureArchiveParamRemainingOutputSize, getInfo);
        break;
        

⌨️ 快捷键说明

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