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

📄 sm2read.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 4 页
字号:
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  VT_ASSERT(secureMailObj != (VtSecureMailObject)0);
  VT_ASSERT(inputRead != (unsigned int*)0);
  VT_ASSERT(pendingInputLength != (unsigned int*)0);
  
  *inputRead = inputLength;
  *pendingInputLength = 0;
  
  if (inputLength == 0)
    return 0;
    
  readCtx = (VoltSecureMail2ReadCtx*)secureMailObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
  libCtx = secureMailObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  
  do
  {
    isHTML = (readCtx->wrapperType == VOLT_SECURE_MAIL_WRAPPER_TYPE_HTML);
    
    maxTagLength = Z2Strlen(VoltZDM2MessageBlockStartTagPrefix) +
      Z2Strlen(VoltZDM2MessageBlockStartTagSuffix) +
      VOLT_ZDM2_MAX_VERSION_NUMBER_LENGTH;
    if (isHTML)
      maxTagLength += 7; // Add 7 for the "<!--" and "-->" HTML comments

    p = input;
    end = input + inputLength;
    
    p = VoltSecureMail2SkipWhitespace(p, end);

    if (p + maxTagLength > end)
    {
      *pendingInputLength = end - p;
      break;
    }
    
    foundTag = 0;
    for (i = VOLT_SECURE_MAIL_2_BEGIN_VERSION;
      i <= VOLT_SECURE_MAIL_2_END_VERSION; i++)
    {
      Z2Free(tag);
      
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VoltZDM2FormatMessageTag(libCtx,
        VoltZDM2MessageBlockStartTagPrefix,
        VoltZDM2MessageBlockStartTagSuffix, (unsigned char*)0,
        i, isHTML, &tag);
      if (status != 0)
        break;
      
      tagLength = Z2Strlen(tag);
      
      if (VoltCaseInsensitiveCompareBuffers(p, tagLength,
        tag, tagLength, libCtx) == 0)
      {
        secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_HEADER_2;
        *inputRead = p + tagLength - input;
        secureMailObj->version = i;
        foundTag = 1;
        break;
      }
    }
    if ((status != 0) || foundTag)
      break;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
    status = VT_ERROR_INVALID_SECURE_MAIL_MSG;
    readCtx->wrapperType = VOLT_SECURE_MAIL_WRAPPER_TYPE_INVALID;
    secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_COMPLETE;
  }
  while (0);
  
  Z2Free(tag);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VoltSecureMail2FindMessageStart", (unsigned char*)0)
  
  return status;
}

static int VoltSecureMail2FindSecureStart(
  VtSecureMailObject secureMailObj,
  const unsigned char *input,
  unsigned int inputLength,
  unsigned int* inputRead,
  unsigned int* pendingInputLength
)
{
  int status = 0;
  VoltSecureMail2ReadCtx* readCtx = (VoltSecureMail2ReadCtx*)0;
  VtLibCtx libCtx = (VtLibCtx)0;
  int foundTag = 0;
  unsigned char* tag = (unsigned char*)0;
  unsigned int tagLength;
  const unsigned char* p;
  const unsigned char* end;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  VT_ASSERT(secureMailObj != (VtSecureMailObject)0);
  VT_ASSERT(inputRead != (unsigned int*)0);
  VT_ASSERT(pendingInputLength != (unsigned int*)0);
  
  *inputRead = inputLength;
  *pendingInputLength = 0;
  
  if (inputLength == 0)
    return 0;
      
  readCtx = (VoltSecureMail2ReadCtx*)secureMailObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
  libCtx = secureMailObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  
  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VoltZDM2FormatMessageTag(libCtx,
      VoltZDM2SecureBlockStartTagPrefix,
      VoltZDM2SecureBlockStartTagSuffix, (unsigned char*)0,
      secureMailObj->version, 0, &tag);
    if (status != 0)
      break;
    
    tagLength = Z2Strlen(tag);
    
    p = input;
    end = input + inputLength;
    
    while (p + tagLength <= end)
    {
      if (VoltCaseInsensitiveCompareBuffers(p, tagLength,
        tag, tagLength, libCtx) == 0)
      {
        foundTag = 1;
        break;
      }
      p++;
    }
    
    if (foundTag)
    {
      secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_B64;
      *inputRead = p + tagLength - input;
    }
    else
    {
      *pendingInputLength = tagLength - 1;
    }
  }
  while (0);
  
  Z2Free(tag);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VoltSecureMail2FindSecureStart", (unsigned char*)0)
  
  return status;
}

static int VoltSecureMail2ReadSecureEnd(
  VtSecureMailObject secureMailObj,
  const unsigned char *input,
  unsigned int inputLength,
  unsigned int* inputRead,
  unsigned int* pendingInputLength
)
{
  int status = 0;
  VoltSecureMail2ReadCtx* readCtx = (VoltSecureMail2ReadCtx*)0;
  VtLibCtx libCtx = (VtLibCtx)0;
  unsigned char* tag = (unsigned char*)0;
  unsigned int tagLength;
  const unsigned char* p;
  const unsigned char* end;
  int isHTML;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  VT_ASSERT(secureMailObj != (VtSecureMailObject)0);
  VT_ASSERT(inputRead != (unsigned int*)0);
  VT_ASSERT(pendingInputLength != (unsigned int*)0);
  
  *inputRead = inputLength;
  *pendingInputLength = 0;
  
  if (inputLength == 0)
    return 0;
    
  readCtx = (VoltSecureMail2ReadCtx*)secureMailObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
  libCtx = secureMailObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  
  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VoltZDM2FormatMessageTag(libCtx,
      VoltZDM2SecureBlockEndTagPrefix,
      VoltZDM2SecureBlockEndTagSuffix, (unsigned char*)0,
      secureMailObj->version, 0, &tag);
    if (status != 0)
      break;
    
    tagLength = Z2Strlen(tag);
    
    p = input;
    end = input + inputLength;
    
    p = VoltSecureMail2SkipWhitespace(p, end);

    if (p + tagLength > end)
    {
      *pendingInputLength = end - p;
      break;
    }
    
    if (VoltCaseInsensitiveCompareBuffers(p, tagLength,
      tag, tagLength, libCtx) == 0)
    {
      isHTML = (readCtx->wrapperType == VOLT_SECURE_MAIL_WRAPPER_TYPE_HTML);
      secureMailObj->state = isHTML ? VOLT_SECURE_MAIL_STATE_READ_COMMENT_END :
        VOLT_SECURE_MAIL_STATE_READ_FOOTER_2;
      *inputRead = p + tagLength - input;
      break;
    }
    
    VOLT_SET_FNCT_LINE(fnctLine)
    VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
    status = VT_ERROR_INVALID_SECURE_MAIL_MSG;
    readCtx->wrapperType = VOLT_SECURE_MAIL_WRAPPER_TYPE_INVALID;
    secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_COMPLETE;
  }
  while (0);
  
  Z2Free(tag);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VoltSecureMail2ReadSecureEnd", (unsigned char*)0)
  
  return status;
}

static int VoltSecureMail2ReadCommentEnd(
  VtSecureMailObject secureMailObj,
  const unsigned char *input,
  unsigned int inputLength,
  unsigned int* inputRead,
  unsigned int* pendingInputLength
)
{
  int status = 0;
  VoltSecureMail2ReadCtx* readCtx = (VoltSecureMail2ReadCtx*)0;
  VtLibCtx libCtx = (VtLibCtx)0;
  const unsigned char* p;
  const unsigned char* end;
  const unsigned char* commentEnd = "-->";
  int commentLength;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  
  VT_ASSERT(secureMailObj != (VtSecureMailObject)0);
  VT_ASSERT(inputRead != (unsigned int*)0);
  VT_ASSERT(pendingInputLength != (unsigned int*)0);
  
  *inputRead = inputLength;
  *pendingInputLength = 0;
  
  if (inputLength == 0)
    return 0;
    
  readCtx = (VoltSecureMail2ReadCtx*)secureMailObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
  libCtx = secureMailObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  
  do
  {
    commentLength = Z2Strlen(commentEnd);
    
    p = input;
    end = input + inputLength;
    
    p = VoltSecureMail2SkipWhitespace(p, end);

    if (p + commentLength > end)
    {
      *pendingInputLength = end - p;
      break;
    }
    
    if (VoltCaseInsensitiveCompareBuffers(p, commentLength,
      commentEnd, commentLength, libCtx) == 0)
    {
      secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_FOOTER_2;
      *inputRead = p + commentLength - input;
      break;
    }
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VT_ERROR_INVALID_SECURE_MAIL_MSG;
    readCtx->wrapperType = VOLT_SECURE_MAIL_WRAPPER_TYPE_INVALID;
    secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_COMPLETE;
  }
  while (0);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, VT_ERROR_TYPE_PRIMARY,
    fnctLine, "VoltSecureMail2ReadCommentEnd", (unsigned char*)0)
  
  return status;
}

static int VoltSecureMail2ReadMessageEnd(
  VtSecureMailObject secureMailObj,
  const unsigned char *input,
  unsigned int inputLength,
  unsigned int* inputRead,
  unsigned int* pendingInputLength
)
{
  int status = 0;
  VoltSecureMail2ReadCtx* readCtx = (VoltSecureMail2ReadCtx*)0;
  VtLibCtx libCtx = (VtLibCtx)0;
  int isHTML;
  unsigned char* tag = (unsigned char*)0;
  unsigned int tagLength;
  const unsigned char* p;
  const unsigned char* end;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  VT_ASSERT(secureMailObj != (VtSecureMailObject)0);
  VT_ASSERT(inputRead != (unsigned int*)0);
  VT_ASSERT(pendingInputLength != (unsigned int*)0);
  
  *inputRead = inputLength;
  *pendingInputLength = 0;
  
  if (inputLength == 0)
    return 0;
    
  readCtx = (VoltSecureMail2ReadCtx*)secureMailObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
  libCtx = secureMailObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  
  do
  {
    isHTML = (readCtx->wrapperType == VOLT_SECURE_MAIL_WRAPPER_TYPE_HTML);
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VoltZDM2FormatMessageTag(libCtx,
      VoltZDM2MessageBlockEndTagPrefix,
      VoltZDM2MessageBlockEndTagSuffix, (unsigned char*)0,
      secureMailObj->version, isHTML, &tag);
    if (status != 0)
      break;
    
    tagLength = Z2Strlen(tag);
    
    p = input;
    end = input + inputLength;
    
    p = VoltSecureMail2SkipWhitespace(p, end);

    if (p + tagLength > end)
    {
      *pendingInputLength = end - p;
      break;
    }
    
    if (VoltCaseInsensitiveCompareBuffers(p, tagLength,
      tag, tagLength, libCtx) == 0)
    {
      secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_COMPLETE;
      *inputRead = p + tagLength - input;
      break;
    }
    
    VOLT_SET_FNCT_LINE(fnctLine)
    VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
    status = VT_ERROR_INVALID_SECURE_MAIL_MSG;
    readCtx->wrapperType = VOLT_SECURE_MAIL_WRAPPER_TYPE_INVALID;
    secureMailObj->state = VOLT_SECURE_MAIL_STATE_READ_COMPLETE;
  }
  while (0);
  
  Z2Free(tag);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VoltSecureMail2ReadMessageEnd", (unsigned char*)0)
  
  return status;
}

static int VoltSecureMail2ProcessHeaders(
  VtSecureMailObject secureMailObj,
  const unsigned char* headers
)
{
  int status = 0;
  VoltSecureMail2ReadCtx* readCtx = (VoltSecureMail2ReadCtx*)0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VtDataNodeObject attributesNode = (VtDataNodeObject)0;
  VtDataNodeObject node;
  const unsigned char* str;
  const unsigned char* p;
  const unsigned char* end;
  unsigned char label[100];
  unsigned int labelLength;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  VT_ASSERT(secureMailObj != (VtSecureMailObject)0);
  
  readCtx = (VoltSecureMail2ReadCtx*)secureMailObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
  libCtx = secureMailObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  
  do
  {
    p = headers;
    end = headers + Z2Strlen(headers);
    
    p = VoltSecureMail2SkipWhitespace(p, end);

⌨️ 快捷键说明

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