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

📄 sm2readtype.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "securemail.h"
#include "errorctx.h"
#include "vtassert.h"

static void VoltSecureMail2ReadLocalCtxDestroy(
  Pointer obj,
  Pointer ctx
)
{
  VoltObject* voltObj = (VoltObject*) obj;
  VtLibCtx libCtx;
  VoltSecureMail2ReadCtx* readCtx = (VoltSecureMail2ReadCtx*) ctx;

  if ((obj == (Pointer)0) || (ctx == (Pointer)0))
    return;

  libCtx = (VtLibCtx) voltObj->libraryCtx;

  Z2Free(readCtx->pendingInput);
  Z2Free(readCtx->pendingData);
  Z2Free(readCtx->pendingHeaders);
  Z2Free(readCtx->pendingOutput);
  Z2Free(readCtx->characterSet);
  Z2Free(readCtx->contentType);
  Z2Free(readCtx->originalCharacterSet);
  
  Z2Free(ctx);
}

int VtSecureMail2ImplRead(
   VtSecureMailObject *object,
   Pointer info,
   unsigned int flag
   )
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VtSecureMailObject smObj;
  VoltSecureMail2ReadCtx* readCtx;
  VtReadSecureMail2Info* smReadInfo = (VtReadSecureMail2Info*)info;
  VtReadPkcs7Info p7ReadInfo;
  VtBase64Info base64Info;
  VtDERCoderArray* coderArray;
  VtSchemaDecodeArray* decoderArray;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)

  VT_ASSERT(object != (VtSecureMailObject*)0);
  VT_ASSERT(*object != (VtSecureMailObject)0);
  
  VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)

  do
  {
    if ((object == (VtSecureMailObject*)0) ||
        (*object == (VtSecureMailObject)0))
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      break;
    }
    
    smObj = *object;
    libCtx = smObj->voltObject.libraryCtx;
    VT_ASSERT(libCtx != (VtLibCtx)0);
  
    /* Make sure it's being called correctly */
    if (flag != VOLT_SECURE_MAIL_SET_TYPE_FLAG)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_TYPE;
      break;
    }
    
    /* Make sure the object is empty. */
    if ((smObj->state != 0) || (smObj->localCtx != (Pointer)0))
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_INVALID_SECURE_MAIL_OBJ;
      break;
    }
    
    /* Allocate the local context */
    readCtx = (VoltSecureMail2ReadCtx*)
      Z3Malloc(sizeof(VoltSecureMail2ReadCtx));
    if (readCtx == (VoltSecureMail2ReadCtx*)0)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_MEMORY;
      break;
    }
    
    Z2Memset(readCtx, 0, sizeof(VoltSecureMail2ReadCtx));

    Z2Memset(&p7ReadInfo, 0, sizeof(p7ReadInfo));
    
    if (smReadInfo != (VtReadSecureMail2Info*)0)
    {
      p7ReadInfo.derCoders = smReadInfo->derCoders;
      p7ReadInfo.derCoderCount = smReadInfo->derCoderCount;
      p7ReadInfo.decoders = smReadInfo->decoders;
      p7ReadInfo.decoderCount = smReadInfo->decoderCount;
      p7ReadInfo.mpCtx = smReadInfo->mpCtx;
    }
    
    if ((p7ReadInfo.derCoders == (VtDerCoder**)0) ||
        (p7ReadInfo.derCoderCount == 0))
    {
      coderArray = (VtDERCoderArray*) VoltGetLibCtxInfo(libCtx,
        VOLT_LIB_CTX_INFO_TYPE_DER_CODERS);

      if (coderArray == (VtDERCoderArray *)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NO_DER_CODERS;
        break;
      }
      
      p7ReadInfo.derCoderCount = coderArray->derCoderCount;
      p7ReadInfo.derCoders = coderArray->derCoders;
    }
    
    if ((p7ReadInfo.decoders == (VtIdentitySchemaDecode**)0) ||
        (p7ReadInfo.decoderCount == 0))
    {
      decoderArray = (VtSchemaDecodeArray*) VoltGetLibCtxInfo(libCtx,
        VOLT_LIB_CTX_INFO_TYPE_SCHEMA_DECODES);

      if (decoderArray == (VtSchemaDecodeArray *)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NO_SCHEMA_DECODERS;
        break;
      }
      
      p7ReadInfo.decoders = decoderArray->decoders;
      p7ReadInfo.decoderCount = decoderArray->decoderCount;
    }
    
    if (p7ReadInfo.mpCtx == (VtMpIntCtx)0)
    {
      p7ReadInfo.mpCtx = (VtMpIntCtx) VoltGetLibCtxInfo(libCtx,
         VOLT_LIB_CTX_INFO_TYPE_MP_CTX);

      if (p7ReadInfo.mpCtx == (VtMpIntCtx)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NO_MATH_LIBRARY;
        break;
      }
      
      /* Paranoid programming check.*/
      if (VOLT_OBJECT_TYPE_NOT_EQUAL(p7ReadInfo.mpCtx, VOLT_OBJECT_TYPE_MP_INT_CTX))
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_INVALID_MP_INT_CTX;
        break;
      }
    }

    VOLT_SET_ERROR_TYPE(errorType, 0)

    /* Build the PKCS7 objects. */
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCreatePkcs7Object(libCtx, VtPkcs7ImplReadSignedData,
      (Pointer)&p7ReadInfo, &smObj->p7SignedData);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCreatePkcs7Object(libCtx, VtPkcs7ImplReadEnvelopedData,
      (Pointer)&p7ReadInfo, &smObj->p7EnvelopedData);
    if (status != 0)
      break;

    /* Build the Base64 object. */
    base64Info.base64BlockSize = 64;
    base64Info.newLineCharacter = VT_BASE64_NEW_LINE_CR_LF;
    base64Info.errorCheck = VT_BASE64_NO_ERROR_CHECK;
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCreateAlgorithmObject(libCtx, VtAlgorithmImplBase64,
      (Pointer)&base64Info, &smObj->base64);
    if (status != 0)
      break;

    smObj->formatType = VOLT_MESSAGE_FORMAT_SECURE_MAIL_2;
    smObj->state = VOLT_SECURE_MAIL_STATE_READ_SET;
    smObj->localCtx = (Pointer)readCtx;
    smObj->LocalCtxDestroy = VoltSecureMail2ReadLocalCtxDestroy;
    smObj->ReadInit = VoltSecureMail2ReadInit;
    smObj->ReadUpdate = VoltSecureMail2ReadUpdate;
    smObj->ReadFinal = VoltSecureMail2ReadFinal;
    smObj->Verify = VoltSecureMail2Verify;
  }
  while (0);

  if (status != 0)
  {
    VoltSecureMail2ReadLocalCtxDestroy((Pointer)smObj, (Pointer)readCtx);

    VOLT_LOG_ERROR(libCtx, status, errorType,
      fnctLine, "VtSecureMail2ImplRead", (char *)0)
  }
  
  return status;
}

⌨️ 快捷键说明

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