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

📄 pgpx509cert.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 5 页
字号:

    body_size =
            pgpasn_SizeofContentTypeInternal(&asnstruct->contentType, PGPASN_TRUE, PGPASN_FALSE)
          + pgpasn_SizeofANYInternal(asnstruct->content, PGPASN_TRUE, PGPASN_TRUE) ;

    if (outerSizeFlag == PGPASN_TRUE)
        body_size = PGPASN_Tagged(body_size, 1);

    if (expTaggedFlag == PGPASN_TRUE)
        body_size = PGPASN_Tagged(body_size, 1); /* this is seq like */

    return body_size;

} /* pgpasn_SizeofContentInfoInternal */

void pgpasn_DropInPlaceContentInfo(
    PGPASN_CONTEXT *ctx,
    PGPASN_ContentInfo *f)
{
    if (ctx == NULL)
        return;

    if (f == NULL) return ;
    pgpasn_DropInPlaceContentType(ctx, &(f->contentType));
    pgpasn_FreeANY(ctx, f->content);
    f->content = NULL;
} /* pgpasn_DropInPlaceContentInfo */

size_t pgpasn_PackContentInfoInternal(
    PGPASN_CONTEXT *ctx,
    unsigned char *buf,
    size_t buflen,
    PGPASN_ContentInfo *asnstruct,
    unsigned char tag,
    int *erret)
{
    size_t bytesused;
    size_t tagsize;
    size_t datasize;

    if (erret == NULL) return 0; /* can't report errors */

    if (ctx == NULL) {
        PGPASN_ERR(kPGPASNError_ErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) return 0;

    /* lth of the block body */
    datasize = pgpasn_SizeofContentInfo(ctx, asnstruct, PGPASN_FALSE);
    tagsize = 1 + PGPASN_LengthSize(datasize);
    if (datasize+tagsize > buflen) {
        PGPASN_ERR(kPGPASNError_ErrPackBufferTooShort);
        return 0;
    }

    /* this is a SEQUENCE */
    bytesused = PGPASN_PutTag(buf, (unsigned char)(tag|0x20), datasize);
    if (bytesused != tagsize) {
        PGPASN_ERR(kPGPASNError_ErrPackOverrun);
        return bytesused;
    }
    datasize += tagsize;

  do {

    /* field contentType of ContentInfo */
    bytesused += pgpasn_PackContentTypeInternal(ctx, buf+bytesused, buflen-bytesused,
                       &(asnstruct->contentType), PGPASN_ID_ContentType, erret);
    if (bytesused > datasize || *erret != 0)
        break;

    /* field content of ContentInfo */
    if (asnstruct->content != NULL) { /* optional */
        bytesused += PGPASN_PutTag(buf+bytesused, 0xa0 | 0x00, pgpasn_SizeofANY(ctx, asnstruct->content, PGPASN_TRUE));
        bytesused += pgpasn_PackANYInternal(ctx, buf+bytesused, buflen-bytesused,
                           asnstruct->content, PGPASN_ID_ANY, erret) ;
        if (bytesused > datasize || *erret != 0)
            break;
    }

  } while(0);

    if (bytesused < datasize && *erret == 0)
        PGPASN_ERR(kPGPASNError_ErrPackUnderrun)
    else if (bytesused > datasize && *erret == 0)
        PGPASN_ERR(kPGPASNError_ErrPackOverrun)

    return bytesused;
} /* pgpasn_PackContentInfoInternal */

size_t pgpasn_UnpkInPlaceContentInfo(
    PGPASN_CONTEXT *ctx,
    PGPASN_ContentInfo *asnstruct,
    const unsigned char *buf,
    size_t buflen,
    unsigned char tag,
    int *erret)
{
    size_t bytesused = 0;
    size_t datasize;
    size_t localsize;
    int indef = 0;

    PGPASN_TRACE_PRINT_FN((tag|0x20), 0x30, "SEQUENCE", "ContentInfo" );

    if (erret == NULL) return 0; /* can't report errors */
    *erret = 0;

    if (ctx == NULL) {
        PGPASN_ERR(kPGPASNError_ErrBadContext);
        return 0;
    }

    if (asnstruct == NULL) {
        PGPASN_ERR(kPGPASNError_ErrUnpackNoStructure);
        return 0;
    }

    if (buf == NULL) {
        PGPASN_ERR(kPGPASNError_ErrUnpackNoBlockPtr);
        return 0;
    }

    if (buflen <= 0) return 0; /* no error -- no block */

    if ( (*buf & 0xDF) != (tag & 0xDF) )
        return 0; /* no error code, just no block */
    if ( (*buf & 0x20) != 0x20) {
        PGPASN_ERR(kPGPASNError_ErrUnpackInvalidEncoding);
        return 0;
    }

    /* accept the tag byte */
    bytesused++;

    /* get the block length */
    bytesused += PGPASN_GetLength(buf+bytesused, &datasize);
    if ((int)datasize == -1) {
        localsize = buflen;
        indef = 1;
    }
    else {
        localsize = bytesused + datasize;
        if (localsize > buflen) {
            PGPASN_ERR(kPGPASNError_ErrUnpackOverrun);
            return 0;
        }
    }

    PGPASN_TRACE_INCR_LEVEL;
  do {

    /* field contentType of ContentInfo */
    bytesused += pgpasn_UnpkInPlaceContentType(ctx, &(asnstruct->contentType), buf+bytesused,
                        localsize-bytesused, PGPASN_ID_ContentType, erret);
    if (bytesused > localsize || *erret != 0)
        break;

    /* field content of ContentInfo */
    if (!indef && bytesused >= localsize) {
        PGPASN_TRACE_DECR_LEVEL;
        return bytesused;
    }
    if (indef && *(buf+bytesused) == 0x00 &&
                 *(buf+bytesused+1) == 0x00) {
        PGPASN_TRACE_DECR_LEVEL;
        bytesused += 2;
        return bytesused;
    }
    { /* local declaration block*/
        size_t taggeddatasize;
        size_t taggedlocalsize;
        size_t used;

        used = PGPASN_TakeTag(buf+bytesused, 0xa0 | 0x00,
                          &taggeddatasize);
        bytesused += used;

        if ((int)taggeddatasize == -1 && used != 0) {
            PGPASN_TRACE_PRINT_TAG(0xa0|0x00, 0x00);
            PGPASN_TRACE_INCR_LEVEL;
            if (asnstruct->content != NULL)
                pgpasn_FreeANY(ctx, asnstruct->content);
            bytesused += pgpasn_UnpackANYInternal(ctx, &(asnstruct->content),
                    buf+bytesused, localsize-bytesused, PGPASN_ID_ANY, erret);
            PGPASN_TRACE_DECR_LEVEL;
            if ( *(buf+bytesused) != 0x00 &&
                 *(buf+bytesused+1) != 0x00 ) {
                PGPASN_ERR(kPGPASNError_ErrUnpackInvalidEncoding);
                break;
            }
            bytesused += 2;
        }

        else if (taggeddatasize > 0 && used != 0) {
            taggedlocalsize = bytesused + taggeddatasize;
            PGPASN_TRACE_PRINT_TAG(0xa0|0x00, 0x00);
            PGPASN_TRACE_INCR_LEVEL;
            if (asnstruct->content != NULL)
                pgpasn_FreeANY(ctx, asnstruct->content);
            bytesused += pgpasn_UnpackANYInternal(ctx, &(asnstruct->content),
                       buf+bytesused, localsize-bytesused, PGPASN_ID_ANY, erret);
            PGPASN_TRACE_DECR_LEVEL;
            if (bytesused != taggedlocalsize) {
                PGPASN_ERR(kPGPASNError_ErrUnpackTaggedLth);
                break;
            }
        }
    } /* for the local declaration block */
    if (bytesused > localsize || *erret != 0)
        break;

    if (indef) {
        if ( *(buf+bytesused) != 0x00 &&
             *(buf+bytesused+1) != 0x00 ) {
            PGPASN_ERR(kPGPASNError_ErrUnpackInvalidEncoding);
            break;
        }
        bytesused += 2;
    }
  } while(0);

    PGPASN_TRACE_DECR_LEVEL;
    if (bytesused > localsize && *erret == 0)
        PGPASN_ERR(kPGPASNError_ErrUnpackOverrun);
    if (!indef && bytesused < localsize && *erret == 0)
        PGPASN_ERR(kPGPASNError_ErrUnpackUnderrun);

    return bytesused;
} /* pgpasn_UnpkInPlaceContentInfo */

size_t pgpasn_UnpackContentInfoInternal(
    PGPASN_CONTEXT *ctx,
    PGPASN_ContentInfo **asnstruct,
    const unsigned char *buf,
    size_t buflen,
    unsigned char tag,
    int *erret)
{
    size_t bytesused;
    PGPASN_ContentInfo *local = NULL;

    if (erret == NULL) return 0;
    *erret = 0;

    if (ctx == NULL) {
        PGPASN_ERR(kPGPASNError_ErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) {
        PGPASN_ERR(kPGPASNError_ErrUnpackNoStructure);
        return 0;
    }
    *asnstruct = NULL;

    if (buflen <= 0) return 0; /* no bytes left */

    if ( (*buf & 0xDF) != (tag & 0xDF) ) 
        return 0; /* not correct tag */

    local = pgpasn_NewContentInfo(ctx); /* carve a block for it */
    bytesused = pgpasn_UnpkInPlaceContentInfo(ctx, local, buf, buflen, tag, erret);
    if (*erret != 0) {
        if (local != NULL) pgpasn_FreeContentInfo(ctx, local);
        return 0;
    }
    *asnstruct = local;
    return bytesused;
} /* pgpasn_UnpackContentInfoInternal */


/******************************************************************
 * Routines for DirectoryString
 ******************************************************************/

size_t pgpasn_SizeofDirectoryStringInternal(
    PGPASN_DirectoryString *asnstruct,
    int outerSizeFlag,
    int expTaggedFlag)
{
    size_t body_size = 0;

    if (asnstruct == NULL)
        return 0;

    switch (asnstruct->CHOICE_field_type) {
      case PGPASN_ID_T61String:
      case 0x20|PGPASN_ID_T61String:
        body_size = pgpasn_SizeofT61StringInternal((PGPASN_T61String *)(asnstruct->data), outerSizeFlag, expTaggedFlag);
        break;

      case PGPASN_ID_PrintableString:
      case 0x20|PGPASN_ID_PrintableString:
        body_size = pgpasn_SizeofPrintableStringInternal((PGPASN_PrintableString *)(asnstruct->data), outerSizeFlag, expTaggedFlag);
        break;

      case PGPASN_ID_UniversalString:
      case 0x20|PGPASN_ID_UniversalString:
        body_size = pgpasn_SizeofUniversalStringInternal((PGPASN_UniversalString *)(asnstruct->data), outerSizeFlag, expTaggedFlag);
        break;

      case PGPASN_ID_UTF8String:
      case 0x20|PGPASN_ID_UTF8String:
        body_size = pgpasn_SizeofUTF8StringInternal((PGPASN_UTF8String *)(asnstruct->data), outerSizeFlag, expTaggedFlag);
        break;

      case PGPASN_ID_BMPString:
      case 0x20|PGPASN_ID_BMPString:
        body_size = pgpasn_SizeofBMPStringInternal((PGPASN_BMPString *)(asnstruct->data), outerSizeFlag, expTaggedFlag);
        break;

      case PGPASN_ID_IA5String:
      case 0x20|PGPASN_ID_IA5String:
        body_size = pgpasn_SizeofIA5StringInternal((PGPASN_IA5String *)(asnstruct->data), outerSizeFlag, expTaggedFlag);
        break;

      default:
        break;

    } /* switch */

    return (body_size);
} /* pgpasn_SizeofDirectoryStringInternal */

void pgpasn_DropInPlaceDirectoryString(
    PGPASN_CONTEXT *ctx,
    PGPASN_DirectoryString *f)
{
    if (ctx == NULL) return;
    if (f == NULL) return;

    switch(f->CHOICE_field_type) {

    case PGPASN_ID_T61String:
    case 0x20|PGPASN_ID_T61String:
        pgpasn_FreeT61String(ctx, (PGPASN_T61String *)( f->data ));
        break;
    case PGPASN_ID_PrintableString:
    case 0x20|PGPASN_ID_PrintableString:
        pgpasn_FreePrintableString(ctx, (PGPASN_PrintableString *)( f->data ));
        break;
    case PGPASN_ID_UniversalString:
    case 0x20|PGPASN_ID_UniversalString:
        pgpasn_FreeUniversalString(ctx, (PGPASN_UniversalString *)( f->data ));
        break;
    case PGPASN_ID_UTF8String:
    case 0x20|PGPASN_ID_UTF8String:
        pgpasn_FreeUTF8String(ctx, (PGPASN_UTF8String *)( f->data ));
        break;
    case PGPASN_ID_BMPString:
    case 0x20|PGPASN_ID_BMPString:
        pgpasn_FreeBMPString(ctx, (PGPASN_BMPString *)( f->data ));
        break;
    case PGPASN_ID_IA5String:
    case 0x20|PGPASN_ID_IA5String:
        pgpasn_FreeIA5String(ctx, (PGPASN_IA5String *)( f->data ));
        break;
    default:
        break;
    } /* switch */

} /* pgpasn_DropInPlaceDirectoryString */

size_t pgpasn_PackDirectoryStringInternal(
    PGPASN_CONTEXT *ctx,
    unsigned char *buf,
    size_t buflen,
    PGPASN_DirectoryString *asnstruct,
    unsigned char tag,
    int *erret)
{
    size_t bytesused = 0;
    size_t datasize;

    (void)tag; /* unused */

    if (erret == NULL) return 0; /* can't report errors */

    if (ctx == NULL) {
        PGPASN_ERR(kPGPASNError_ErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) return 0;

    /* lth of the block body */
    datasize = pgpasn_SizeofDirectoryString(ctx, asnstruct, PGPASN_TRUE);
    if (datasize > buflen) {
        PGPASN_ERR(kPGPASNError_ErrPackBufferTooShort);
        return 0;
    }

    switch ( (asnstruct->CHOICE_field_type & 0xDF) ) {

    case PGPASN_ID_T61String:
        bytesused += pgpasn_PackT61StringInternal(ctx, buf+bytesused, buflen-bytesused,
                     (PGPASN_T61String *)(asnstruct->data),
                     PGPASN_ID_T61String,
                     erret);
        break;

    case PGPASN_ID_PrintableString:
        bytesused += pgpasn_PackPrintableStringInternal(ctx, buf+bytesused, buflen-bytesused,
                     (PGPASN_PrintableString *)(asnstruct->data),
                     PGPASN_ID_PrintableString,
                     erret);
        break;

    case PGPASN_ID_UniversalString:
        bytesused += pgpasn_PackUniversalStringInternal(ctx, buf+bytesused, buflen-bytesused,
                     (PGPASN_UniversalString *)(asnstruct->data),
                     PGPASN_ID_UniversalString,
                     erret);
        break;

    case PGPASN_ID_UTF8String:
        bytesused += pgpasn_PackUTF8StringInternal(ctx, buf+bytesused, buflen-bytesused,
                     (PGPASN_UTF8String *)(asnstruct->data),
                     PGPASN_ID_UTF8String,
                     erret);
        break;

    case PGPASN_ID_BMPString:
        bytesused += pgpasn_PackBMPStringInternal(ctx, buf+bytesused, buflen-bytesused,
                     (PGPASN_BMPString *)(asnstruct->data),
                     PGPASN_ID_BMPString,
                     erret);
        break;

    case PGPASN_ID_IA5String:
        bytesused += pgpasn_PackIA5StringInternal(ctx, buf+bytesused, buflen-bytesused,
                     (PGPASN_IA5String *)(asnstruct->data),
                     PGPASN_ID_IA5String,
                     erret);
        break;

⌨️ 快捷键说明

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