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

📄 zdm2write.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 5 页
字号:
  
  VT_ASSERT(zdmObj != (VtZDMObject)0);
  VT_ASSERT(recipientsNode != (VtDataNodeObject)0);
  VT_ASSERT(address != (unsigned char*)0);
  
  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  localCtx = (VoltZDM2WriteLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(localCtx != (VoltZDM2WriteLocalCtx*)0);

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCreateDataNodeObject(libCtx,
      VoltZDM2RecipientAttributeName, &recipientNode);
    if (status != 0)
      break;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeResolveChild(recipientNode,
      VoltZDM2AddressAttributeName, 1, &dataNode);
    if (status != 0)
      break;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeSetStringValue(dataNode, address);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeResolveChild(recipientNode,
      VoltZDM2FlagsAttributeName, 1, &dataNode);
    if (status != 0)
      break;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeSetIntegerValue(dataNode, flags);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeInsertChild(recipientsNode, recipientNode,
      VT_DATA_NODE_INSERT_AT_END);
    if (status != 0)
      break;
          
    recipientNode = (VtDataNodeObject)0;
  }
  while (0);
  
  VtDestroyDataNodeObject(&recipientNode);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, 0,
    fnctLine, "VoltZDM2SetEmailRecipientAttributes", (unsigned char*)0)
    
  return status;
}
 
static int VoltZDM2SetEmailRecipientListAttributes(
  VtZDMObject zdmObj
)
{
  int status = 0;
  VoltZDM2WriteLocalCtx* localCtx;
  VtLibCtx libCtx = (VtLibCtx)0;
  unsigned int flags;
  unsigned int i;
  VtDataNodeObject attributesNode;
  VtDataNodeObject recipientsNode;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VT_ASSERT(zdmObj != (VtZDMObject)0);
  
  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  localCtx = (VoltZDM2WriteLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(localCtx != (VoltZDM2WriteLocalCtx*)0);
  
  VOLT_SET_ERROR_TYPE(errorType, 0)

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtGetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamAttributesNode, (Pointer*)&attributesNode);
    if (status != 0)
      break;
    
    VT_ASSERT(attributesNode != (VtDataNodeObject)0);
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeResolveChild(attributesNode,
      VoltZDM2RecipientsAttributeName, 1, &recipientsNode);
    if (status != 0)
      break;
    
    VT_ASSERT(recipientsNode != (VtDataNodeObject)0);
    
    /* Add a recipient node for each of the addresses in the primary
     * recipient list. Also check to see if the address is in the
     * CC recipient list and if so, also set the CC flag.
     */
    for (i = 0; i < localCtx->mPrimaryEmailRecipientList.count; i++)
    {
      flags = VOLT_ZDM_RECIPIENT_FLAGS_PRIMARY;
      if (VoltZDM2EmailRecipientListContains(libCtx,
        &localCtx->mCCEmailRecipientList,
        localCtx->mPrimaryEmailRecipientList.emailList[i]))
      {
        flags |= VOLT_ZDM_RECIPIENT_FLAGS_CC;
      }
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltZDM2SetEmailRecipientAttributes(zdmObj, recipientsNode,
        localCtx->mPrimaryEmailRecipientList.emailList[i], flags);
      if (status != 0)
        break;
    }

    /* Add a recipient node for each of the addresses in the CC
     * recipient list. Only add the ones that aren't also in the
     * primary recipient list, since they were handled in the
     * previous loop.
     */
    for (i = 0; i < localCtx->mCCEmailRecipientList.count; i++)
    {
      if (!VoltZDM2EmailRecipientListContains(libCtx,
        &localCtx->mPrimaryEmailRecipientList,
        localCtx->mCCEmailRecipientList.emailList[i]))
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VoltZDM2SetEmailRecipientAttributes(zdmObj, recipientsNode,
          localCtx->mCCEmailRecipientList.emailList[i], VOLT_ZDM_RECIPIENT_FLAGS_CC);
        if (status != 0)
          break;
      }
    }
  }
  while (0);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VoltZDM2UpdateRecipientAttributes", (unsigned char*)0)
    
  return status;
}

#if 0
static int VoltZDM2DateToStringAlloc(
  VtLibCtx libCtx,
  const VtTime* date,
  unsigned char** buffer
)
{
  int status = 0;
  unsigned char* p;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  
  do
  {
    *buffer = (unsigned char*) Z3Malloc(64);
    if (*buffer == (unsigned char*)0)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_MEMORY;
      break;
    }
    p = *buffer;
  }
  while (0);
  
  if (status != 0)
  {
    Z2Free(*buffer);
    
    VOLT_LOG_ERROR(libCtx, status, errorType, fnctLine,
      "VoltZDM2DateToStringAlloc", (unsigned char*)0)
  }
  
  return status;
}
#endif

static int VoltZDM2UpdateAttributes(
  VtZDMObject zdmObj
)
{
  int status = 0;
  VoltZDM2WriteLocalCtx* localCtx;
  VtLibCtx libCtx = (VtLibCtx)0;
  VtIdentityObject senderID;
  VtItem* senderItem;
  unsigned char* senderAddress = (unsigned char*)0;
  VtSecureArchiveAttributeInfo attributeInfo;
  VtTime currentTime;
  unsigned char timestamp[64];
  unsigned char version[64];
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VT_ASSERT(zdmObj != (VtZDMObject)0);
  
  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  localCtx = (VoltZDM2WriteLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(localCtx != (VoltZDM2WriteLocalCtx*)0);
  VT_ASSERT(localCtx->mSecureArchive != (VtSecureArchiveObject)0);
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtGetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamSignerId, (Pointer*)&senderID);
    if (status != 0)  
      break;
    
    if (senderID != (VtIdentityObject)0)
    {
      /* Extract the sender's email address (i.e. common name) from
       * the identity. The identity param to do that puts the address
       * in a VtItem with no 
       */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtGetIdentityParam(senderID, VtIdentityParamCommonName,
        (Pointer*)&senderItem);
      if (status != 0)
        break;
      
      /* The address data in the senderItem isn't null-terminated,
       * so we copy the address over to a null-terminated string, so
       * we can make the call to the secure archive to set the attribute.
       */
      senderAddress = (unsigned char*) Z3Malloc(senderItem->len + 1);
      if (senderAddress == (unsigned char*)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_MEMORY;
        break;
      }
      Z2Memcpy(senderAddress, senderItem->data, senderItem->len);
      senderAddress[senderItem->len] = 0;
      
      /* Now we can set the attribute in the secure archive */
      attributeInfo.name = VoltZDM2SenderAttributeName;
      attributeInfo.value = senderAddress;

      VOLT_SET_FNCT_LINE(fnctLine)
      status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
        VtSecureArchiveParamArchiveAttribute, (Pointer) &attributeInfo);
      if (status != 0)
        break;
    }
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VoltZDM2SetEmailRecipientListAttributes(zdmObj);
    if (status != 0)
      break;
    
    /* Generate a message ID if one hasn't been set already */
    if (localCtx->mMessageID == (unsigned char*)0)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltZDM2GenerateMessageID(libCtx, localCtx->mRandom,
        &localCtx->mMessageID);
      if (status != 0)
        break;
    }
    
    /* Set the message ID attribute */
    attributeInfo.name = VoltZDM2MessageIDAttributeName;
    attributeInfo.value = localCtx->mMessageID;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamArchiveAttribute, (Pointer) &attributeInfo);
    if (status != 0)
      break;
    
    /* Set the timestamp attribute */
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtGetTime(libCtx, &currentTime);
    if (status != 0)
      break;
    
    VoltConvertVtTimeToUTC(&currentTime, timestamp);
    
    attributeInfo.name = VoltZDM2TimestampAttributeName;
    attributeInfo.value = timestamp;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamArchiveAttribute, (Pointer) &attributeInfo);
    if (status != 0)
      break;
    
    /* Set the version attribute */
    
    status = VoltNumToDecimalString(localCtx->mSupportedVersion,
      version, sizeof(version), libCtx);
    VT_ASSERT(status == 0);

    attributeInfo.name = VoltZDM2VersionAttributeName;
    attributeInfo.value = version;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamArchiveAttribute, (Pointer) &attributeInfo);
    if (status != 0)
      break;
    
    /* Set the compatible version attribute */
    attributeInfo.name = VoltZDM2CompatibleVersionAttributeName;
    attributeInfo.value = version;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamArchiveAttribute, (Pointer) &attributeInfo);
    if (status != 0)
      break;
  }
  while (0);
  
  Z2Free(senderAddress);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, 0,
    fnctLine, "VoltZDM2UpdateAttributes", (unsigned char*)0)
    
  return status;
}

static int VoltZDM2WriteInsecureAttributes(
  VtZDMObject zdmObj
)
{
  int status = 0;
  VoltZDM2WriteLocalCtx* localCtx;
  VtLibCtx libCtx = (VtLibCtx)0;
  VtDataNodeObject insecureAttributes = (VtDataNodeObject)0;
  VtDataNodeObject dataNode;
  VtStreamImplMemoryInfo memInfo;
  VtStreamObject outputStream = (VtStreamObject)0;
  unsigned int formatFlags;
  unsigned char* buffer;
  VtStreamSize size;
  VtSecureArchiveCurrentEntryInfo currentEntryInfo;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)

  VT_ASSERT(zdmObj != (VtZDMObject)0);
  
  libCtx = zdmObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  localCtx = (VoltZDM2WriteLocalCtx*) zdmObj->localCtx;
  VT_ASSERT(localCtx != (VoltZDM2WriteLocalCtx*)0);
  
  VOLT_SET_ERROR_TYPE(errorType, 0)

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCreateDataNodeObject(libCtx,
      VoltZDM2InsecureRootAttributeName, &insecureAttributes);
    if (status != 0)
      break;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeResolveChild(insecureAttributes,
      VoltZDM2MessageIDAttributeName, 1, &dataNode);
    if (status != 0)
      break;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeSetStringValue(dataNode, localCtx->mMessageID);
    if (status != 0)
      break;
    
    Z2Memset(&memInfo, 0, sizeof(memInfo));
    memInfo.flags = VT_STREAM_OPEN_ON_ACCESS;
    memInfo.openMode = VT_STREAM_OPEN_WRITE;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCreateStreamObject(libCtx, VtStreamImplMemory,
      (Pointer)&memInfo, &outputStream);
    if (status != 0)
      break;
    
    formatFlags = VT_DATA_NODE_XML_FORMAT_INDENT_SPACES |
      VT_DATA_NODE_XML_FORMAT_SET_NEW_LINE(VT_DATA_NODE_XML_FORMAT_NEW_LINE_LF) |
      VT_DATA_NODE_XML_FORMAT_SET_SPACES_PER_INDENT(1) |
      VT_DATA_NODE_XML_FORMAT_NEW_LINE_PER_ELEMENT |
      VT_DATA_NODE_XML_FORMAT_INDENT_CHILD_ELEMENTS;
            
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtDataNodeWriteXML(insecureAttributes, formatFlags, outputStream);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtStreamGetBuffer(outputStream, &buffer, &size);
    if (status != 0)
      break;
    
    currentEntryInfo.type = VT_SECURE_ARCHIVE_CURRENT_ENTRY_INSECURE;
    //currentEntryInfo.name = VoltZDM2InsecureAttributesFilePathName;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamCurrentEntry, (Pointer)&currentEntryInfo);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtSetSecureArchiveParam(localCtx->mSecureArchive,
      VtSecureArchiveParamFileName,
      (Pointer)VoltZDM2InsecureAttributesFilePathName);

⌨️ 快捷键说明

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