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

📄 pgpx509cert.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************
 *
 * This file was generated by TIS/ASN1COMP Ver. 4.2, an ASN.1 compiler.
 * TIS/ASN1COMP is Copyright (c) 1998, TIS Labs at Network Associates, Inc.
 *
 * This file was AUTOMATICALLY GENERATED on Tue May 18 17:09:44 1999
 *
 ******************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "pgpX509Cert_asn.h"

/*******************************************************************
 *
 * Code for internal routines
 *
 *  DropInPlaceXXX:  drops the contents of a block, in place
 *
 *  _PackXXX: packs up a structure into an ASN.1 block
 *
 *  UnpkInPlaceXXX:  unpacks an ASN.1 block into a structure in place
 *
 *  _unPackXXX: carves a structure block and unpacks into it
 *
 ******************************************************************/


/******************************************************************
 * Routines for AlgorithmIdentifier
 ******************************************************************/

size_t pgpasn_SizeofAlgorithmIdentifierInternal(
    PGPASN_AlgorithmIdentifier *asnstruct,
    int outerSizeFlag,
    int expTaggedFlag)
{
    size_t body_size = 0;

    if (asnstruct == NULL)
        return 0;

    body_size =
            pgpasn_SizeofOBJECT_IDInternal(&asnstruct->algorithm, PGPASN_TRUE, PGPASN_FALSE)
          + pgpasn_SizeofANYInternal(asnstruct->parameters, PGPASN_TRUE, PGPASN_FALSE) ;

    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_SizeofAlgorithmIdentifierInternal */

void pgpasn_DropInPlaceAlgorithmIdentifier(
    PGPASN_CONTEXT *ctx,
    PGPASN_AlgorithmIdentifier *f)
{
    if (ctx == NULL)
        return;

    if (f == NULL) return ;
    pgpasn_DropInPlaceOBJECT_ID(ctx, &(f->algorithm));
    pgpasn_FreeANY(ctx, f->parameters);
    f->parameters = NULL;
} /* pgpasn_DropInPlaceAlgorithmIdentifier */

size_t pgpasn_PackAlgorithmIdentifierInternal(
    PGPASN_CONTEXT *ctx,
    unsigned char *buf,
    size_t buflen,
    PGPASN_AlgorithmIdentifier *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_SizeofAlgorithmIdentifier(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 algorithm of AlgorithmIdentifier */
    bytesused += pgpasn_PackOBJECT_IDInternal(ctx, buf+bytesused, buflen-bytesused,
                       &(asnstruct->algorithm), PGPASN_ID_OBJECT_ID, erret);
    if (bytesused > datasize || *erret != 0)
        break;

    /* field parameters of AlgorithmIdentifier */
    if (asnstruct->parameters != NULL) { /* optional */
        bytesused += pgpasn_PackANYInternal(ctx, buf+bytesused, buflen-bytesused,
                          asnstruct->parameters, 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_PackAlgorithmIdentifierInternal */

size_t pgpasn_UnpkInPlaceAlgorithmIdentifier(
    PGPASN_CONTEXT *ctx,
    PGPASN_AlgorithmIdentifier *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", "AlgorithmIdentifier" );

    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 algorithm of AlgorithmIdentifier */
    bytesused += pgpasn_UnpkInPlaceOBJECT_ID(ctx, &(asnstruct->algorithm), buf+bytesused,
                        localsize-bytesused, PGPASN_ID_OBJECT_ID, erret);
    if (bytesused > localsize || *erret != 0)
        break;

    /* field parameters of AlgorithmIdentifier */
    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;
    }
    if (asnstruct->parameters != NULL)
        pgpasn_FreeANY(ctx, asnstruct->parameters);
    bytesused += pgpasn_UnpackANYInternal(ctx, &(asnstruct->parameters),
                    buf+bytesused, localsize-bytesused, PGPASN_ID_ANY, erret);
    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_UnpkInPlaceAlgorithmIdentifier */

size_t pgpasn_UnpackAlgorithmIdentifierInternal(
    PGPASN_CONTEXT *ctx,
    PGPASN_AlgorithmIdentifier **asnstruct,
    const unsigned char *buf,
    size_t buflen,
    unsigned char tag,
    int *erret)
{
    size_t bytesused;
    PGPASN_AlgorithmIdentifier *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_NewAlgorithmIdentifier(ctx); /* carve a block for it */
    bytesused = pgpasn_UnpkInPlaceAlgorithmIdentifier(ctx, local, buf, buflen, tag, erret);
    if (*erret != 0) {
        if (local != NULL) pgpasn_FreeAlgorithmIdentifier(ctx, local);
        return 0;
    }
    *asnstruct = local;
    return bytesused;
} /* pgpasn_UnpackAlgorithmIdentifierInternal */


/******************************************************************
 * Routines for AttributeTypeAndValue
 ******************************************************************/

size_t pgpasn_SizeofAttributeTypeAndValueInternal(
    PGPASN_AttributeTypeAndValue *asnstruct,
    int outerSizeFlag,
    int expTaggedFlag)
{
    size_t body_size = 0;

    if (asnstruct == NULL)
        return 0;

    body_size =
            pgpasn_SizeofAttributeTypeInternal(&asnstruct->type, PGPASN_TRUE, PGPASN_FALSE)
          + pgpasn_SizeofAttributeValueInternal(&asnstruct->value, PGPASN_TRUE, PGPASN_FALSE) ;

    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_SizeofAttributeTypeAndValueInternal */

void pgpasn_DropInPlaceAttributeTypeAndValue(
    PGPASN_CONTEXT *ctx,
    PGPASN_AttributeTypeAndValue *f)
{
    if (ctx == NULL)
        return;

    if (f == NULL) return ;
    pgpasn_DropInPlaceAttributeType(ctx, &(f->type));
    pgpasn_DropInPlaceAttributeValue(ctx, &(f->value));
} /* pgpasn_DropInPlaceAttributeTypeAndValue */

size_t pgpasn_PackAttributeTypeAndValueInternal(
    PGPASN_CONTEXT *ctx,
    unsigned char *buf,
    size_t buflen,
    PGPASN_AttributeTypeAndValue *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_SizeofAttributeTypeAndValue(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 type of AttributeTypeAndValue */
    bytesused += pgpasn_PackAttributeTypeInternal(ctx, buf+bytesused, buflen-bytesused,
                       &(asnstruct->type), PGPASN_ID_AttributeType, erret);
    if (bytesused > datasize || *erret != 0)
        break;

    /* field value of AttributeTypeAndValue */
    bytesused += pgpasn_PackAttributeValueInternal(ctx, buf+bytesused, buflen-bytesused,
                       &(asnstruct->value), PGPASN_ID_AttributeValue, 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_PackAttributeTypeAndValueInternal */

size_t pgpasn_UnpkInPlaceAttributeTypeAndValue(
    PGPASN_CONTEXT *ctx,
    PGPASN_AttributeTypeAndValue *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", "AttributeTypeAndValue" );

    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;

⌨️ 快捷键说明

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