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

📄 sm2params.c

📁 IBE是一种非对称密码技术
💻 C
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "securemail.h"
#include "stringutil.h"
#include "vtassert.h"
#include "errorctx.h"

int VtSecureMailParamCharacterSet(
  VtSecureMailObject secureMailObj,
  Pointer info,
  unsigned int flag
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureMailWriteCtx* writeCtx;
  VoltSecureMail2ReadCtx* readCtx;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
    if ((secureMailObj == (VtSecureMailObject)0) ||
        (secureMailObj->formatType != VOLT_MESSAGE_FORMAT_SECURE_MAIL_2))
      break;
    
    libCtx = secureMailObj->voltObject.libraryCtx;
    VT_ASSERT(libCtx != (VtLibCtx)0);

    if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
    {
      writeCtx = (VoltSecureMailWriteCtx*) secureMailObj->localCtx;
      VT_ASSERT(writeCtx != (VoltSecureMailWriteCtx*)0);
      
      /* The SecureMail object must be set to write. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      if (secureMailObj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
        break;

      /* The info must be a UTF-8 string. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_ASSOCIATED_INFO;
      if (info == (Pointer)0)
        break;

      /* Free up existing string */
      if (writeCtx->characterSet != (unsigned char*)0);
      {
        Z2Free(writeCtx->characterSet);
        writeCtx->characterSet = (unsigned char*)0;
      }
      
      /* Copy to writeCtx */
      VOLT_SET_FNCT_LINE(fnctLine)
      VOLT_SET_ERROR_TYPE(errorType, 0)
      status = Strdup(info, (char**)&writeCtx->characterSet, libCtx);
    }
    else if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
    {
      /* If getting, the SecureMail object must be set to read. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      if ((secureMailObj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
        break;
      
      readCtx = (VoltSecureMail2ReadCtx*) secureMailObj->localCtx;
      VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
      
      *(Pointer*)info = readCtx->characterSet;
      
      status = 0;
    }
    else
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_TYPE;
    }
  } while (0);

  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VtSecureMailParamCharacterSet", (unsigned char*)0)

  return status;
}

int VtSecureMailParamOriginalCharacterSet(
  VtSecureMailObject secureMailObj,
  Pointer info,
  unsigned int flag
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureMailWriteCtx* writeCtx;
  VoltSecureMail2ReadCtx* readCtx;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
    if ((secureMailObj == (VtSecureMailObject)0) ||
        (secureMailObj->formatType != VOLT_MESSAGE_FORMAT_SECURE_MAIL_2))
      break;
    
    libCtx = secureMailObj->voltObject.libraryCtx;
    VT_ASSERT(libCtx != (VtLibCtx)0);

    if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
    {
      writeCtx = (VoltSecureMailWriteCtx*) secureMailObj->localCtx;
      VT_ASSERT(writeCtx != (VoltSecureMailWriteCtx*)0);
      
      /* The SecureMail object must be set to write. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      if (secureMailObj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
        break;

      /* The info must be a UTF-8 string. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_ASSOCIATED_INFO;
      if (info == (Pointer)0)
        break;

      /* Free up existing string */
      if (writeCtx->originalCharacterSet != (unsigned char*)0);
      {
        Z2Free(writeCtx->originalCharacterSet);
        writeCtx->originalCharacterSet = (unsigned char*)0;
      }
      
      /* Copy to writeCtx */
      VOLT_SET_FNCT_LINE(fnctLine)
      VOLT_SET_ERROR_TYPE(errorType, 0)
      status = Strdup(info, (char**)&writeCtx->originalCharacterSet, libCtx);
    }
    else if (flag == VOLT_SECURE_MAIL_GET_TYPE_FLAG)
    {
      /* If getting, the SecureMail object must be set to read. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      if ((secureMailObj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
        break;
      
      readCtx = (VoltSecureMail2ReadCtx*) secureMailObj->localCtx;
      VT_ASSERT(readCtx != (VoltSecureMail2ReadCtx*)0);
      
      *(Pointer*)info = readCtx->originalCharacterSet;
      
      status = 0;
    }
    else
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_TYPE;
    }
  } while (0);

  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VtSecureMailParamOriginalCharacterSet", (unsigned char*)0)

  return status;
}

int VtSecureMailParamTemplateCharset(
  VtSecureMailObject secureMailObj,
  Pointer info,
  unsigned int flag
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureMailWriteCtx* writeCtx;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
    if ((secureMailObj == (VtSecureMailObject)0) ||
        (secureMailObj->formatType != VOLT_MESSAGE_FORMAT_SECURE_MAIL_2))
      break;
    
    libCtx = secureMailObj->voltObject.libraryCtx;
    VT_ASSERT(libCtx != (VtLibCtx)0);

    if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
    {
      writeCtx = (VoltSecureMailWriteCtx*) secureMailObj->localCtx;
      VT_ASSERT(writeCtx != (VoltSecureMailWriteCtx*)0);
      
      /* The SecureMail object must be set to write. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      if (secureMailObj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
        break;

      /* The info must be a UTF-8 string. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_ASSOCIATED_INFO;
      if (info == (Pointer)0)
        break;

      /* Free up existing string */
      if (writeCtx->templateCharset != (unsigned char*)0);
      {
        Z2Free(writeCtx->templateCharset);
        writeCtx->templateCharset = (unsigned char*)0;
      }
      
      /* Copy to writeCtx */
      VOLT_SET_FNCT_LINE(fnctLine)
      VOLT_SET_ERROR_TYPE(errorType, 0)
      status = Strdup(info, (char**)&writeCtx->templateCharset, libCtx);
    }
    else
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_GET;
    }
  } while (0);

  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VtSecureMailParamTemplateCharset", (unsigned char*)0)

  return status;
}

int VtSecureMailParamMessageFormat(
  VtSecureMailObject secureMailObj,
  Pointer info,
  unsigned int flag
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureMailWriteCtx* writeCtx;
  unsigned int messageFormat;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
    if ((secureMailObj == (VtSecureMailObject)0) ||
        (secureMailObj->formatType != VOLT_MESSAGE_FORMAT_SECURE_MAIL_2))
      break;
    
    libCtx = secureMailObj->voltObject.libraryCtx;
    VT_ASSERT(libCtx != (VtLibCtx)0);

    if (flag == VOLT_SECURE_MAIL_SET_TYPE_FLAG)
    {
      writeCtx = (VoltSecureMailWriteCtx*) secureMailObj->localCtx;
      VT_ASSERT(writeCtx != (VoltSecureMailWriteCtx*)0);
      
      /* The SecureMail object must be set to write. */
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      if (secureMailObj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
        break;

      status = VT_ERROR_INVALID_ASSOCIATED_INFO;
      
      /* The info must be a pointer to an unsigned int. */
      VOLT_SET_FNCT_LINE(fnctLine)
      if (info == (Pointer)0)
        break;

      messageFormat = *(unsigned int*)info;
      
      /* Check that it's one of the valid values for the format */
      VOLT_SET_FNCT_LINE(fnctLine)
      if ((messageFormat != VT_MESSAGE_FORMAT_SECURE_MAIL_PLAIN) &&
          (messageFormat != VT_MESSAGE_FORMAT_SECURE_MAIL_HTML))
      {
        break;
      }
      
      writeCtx->messageFormat = messageFormat;
      status = 0;
    }
    else
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_GET;
    }
  } while (0);

  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
    fnctLine, "VtSecureMailParamMessageFormat", (unsigned char*)0)

  return status;
}

⌨️ 快捷键说明

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