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

📄 cert.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 Mon May 17 09:25:53 1999
 *
 ******************************************************************/


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

#include "cert_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 noticeNumbers_SEQ_OF
 ******************************************************************/

size_t PKISizeofnoticeNumbers_SEQ_OFInternal(
    PKInoticeNumbers_SEQ_OF *asnstruct,
    int outerSizeFlag,
    int expTaggedFlag)
{
    long i, lth;
    size_t body_size = 0;

    if (asnstruct == NULL)
        return 0;

    lth = asnstruct->n ;
    if (lth > PKIMAX_noticeNumbers_SEQ_OF)
        lth = PKIMAX_noticeNumbers_SEQ_OF;	/* clamp it */
    for (i=0; i<lth; i++)
        body_size += PKISizeofINTEGERInternal((asnstruct->elt)[i], PKITRUE, PKIFALSE);

    if (outerSizeFlag == PKITRUE)
        body_size = PKITagged(body_size, 1);

    if (expTaggedFlag == PKITRUE)
        body_size = PKITagged(body_size, 1); /* this is seq like */

    return body_size;
} /* PKISizeofnoticeNumbers_SEQ_OFInternal */

void PKIDropInPlacenoticeNumbers_SEQ_OF(
    PKICONTEXT *ctx,
    PKInoticeNumbers_SEQ_OF *f)
{
    long i, lth;

    if (ctx == NULL) return;
    if (f == NULL) return;

    lth = f->n ;
    if (lth > PKIMAX_noticeNumbers_SEQ_OF)
        lth = PKIMAX_noticeNumbers_SEQ_OF ;	/* clamp it */
    for (i=0;i<lth;i++) {
        PKIFreeINTEGER(ctx, (f->elt)[i]);
        (f->elt)[i] = NULL;
    }
} /* PKIDropInPlacenoticeNumbers_SEQ_OF */

size_t PKIPacknoticeNumbers_SEQ_OFInternal(
    PKICONTEXT *ctx,
    unsigned char *buf,
    size_t buflen,
    PKInoticeNumbers_SEQ_OF *asnstruct,
    unsigned char tag,
    int *erret )
{
    size_t bytesused;
    size_t tagsize;
    size_t datasize;
    long numElem;
    int i;

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

    if (ctx == NULL) {
        PKIERR(PKIErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) return 0;

    /* make sure there aren't too many elements */
    numElem = asnstruct->n;
    if (numElem > PKIMAX_noticeNumbers_SEQ_OF) {
        PKIERR(PKIErrPackSEQOFArrayTooLong);
        return 0;
    }

    /* lth of the block body */
    datasize = PKISizeofnoticeNumbers_SEQ_OF(ctx, asnstruct, PKIFALSE);
    tagsize = 1 + PKILengthSize(datasize);
    if (datasize+tagsize > buflen) {
        PKIERR(PKIErrPackBufferTooShort);
        return 0;
    }

    /* this is a SEQ_OF */
    bytesused = PKIPutTag(buf, (unsigned char)(tag|0x20), datasize);
    if (bytesused != tagsize) {
        PKIERR(PKIErrPackOverrun);
        return bytesused;
    }
    datasize += tagsize;

    for (i=0; i<numElem; i++) {
        bytesused += PKIPackINTEGERInternal(ctx, buf+bytesused, buflen-bytesused,
                        (asnstruct->elt)[i],
                        PKIID_INTEGER, erret);
        if (bytesused > datasize || *erret != 0)
            break;
    }

    if (bytesused < datasize && *erret == 0)
        PKIERR(PKIErrPackUnderrun)
    else if (bytesused > datasize && *erret == 0)
        PKIERR(PKIErrPackOverrun);

    return bytesused;
} /* PKIPacknoticeNumbers_SEQ_OFInternal */

size_t PKIUnpkInPlacenoticeNumbers_SEQ_OF(
     PKICONTEXT *ctx,
     PKInoticeNumbers_SEQ_OF *asnstruct,
     const unsigned char *buf,
     size_t buflen,
     unsigned char tag,
     int *erret)
{
    size_t bytesused = 0;
    size_t datasize;
    size_t localsize;
    int i ;
    int indef = 0;

    PKITRACE_PRINT_FN((tag|0x20), 0x30, "SEQUENCE OF", "noticeNumbers_SEQ_OF");

    if (erret == NULL) return 0;

    if (ctx == NULL) {
        PKIERR(PKIErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) {
        PKIERR(PKIErrUnpackNoStructure);
        return 0;
    }

    if (buf == NULL) {
        PKIERR(PKIErrUnpackNoBlockPtr);
        return 0;
    }

    if (buflen <= 0) return 0; /* out of bytes, no action */

    if ( (*buf & 0xDF) != (tag & 0xDF) )
        return 0; /* not my kind of block */
    if ( (*buf & 0x20) != 0x20) {
        PKIERR(PKIErrUnpackInvalidEncoding);
        return 0;
    }
    bytesused ++; /* consume the tag byte */

    PKITRACE_INCR_LEVEL;

    bytesused += PKIGetLength(buf+bytesused, &datasize);
    if ((int)datasize == -1) {
        localsize = buflen;
        indef = 1;
    }
    else {
        localsize = bytesused + datasize;
        if (localsize > buflen) {
            PKIERR(PKIErrUnpackOverrun);
            asnstruct->n = -1 ; /* note where (-1 treated as 0) */
            PKITRACE_DECR_LEVEL;
            return 0;
        }
    }

    for (i=0; (i < PKIMAX_noticeNumbers_SEQ_OF) && (bytesused < localsize); i++) {

        /* if this is indef length and we have EOC, done */
        if (indef && *(buf+bytesused) == 0x00 &&
                     *(buf+bytesused+1) == 0x00 )
            break;

        if (asnstruct->elt[i] == NULL)
            asnstruct->elt[i] = PKINewINTEGER(ctx);
        if (asnstruct->elt[i] == NULL) {
            PKIERR(PKIErrOutOfMemory);
            break;
        }
        asnstruct->n = i+1 ; /* note the new element */
        bytesused += PKIUnpkInPlaceINTEGER(ctx, asnstruct->elt[i], buf+bytesused,
                            localsize-bytesused, PKIID_INTEGER, erret);
        if (*erret != 0)
            break;
    } /* for */

    if (indef) {
        if ( *(buf+bytesused) != 0x00 &&
             *(buf+bytesused+1) != 0x00 ) {
            PKIERR(PKIErrUnpackInvalidEncoding);
        }
        else
            bytesused += 2;
    }

    PKITRACE_DECR_LEVEL;
    if (bytesused > localsize && *erret == 0)
        PKIERR(PKIErrUnpackOverrun);
    if (!indef && bytesused < localsize && *erret == 0)
        PKIERR(PKIErrUnpackUnderrun);

    return bytesused;
} /* PKIUnpkInPlacenoticeNumbers_SEQ_OF */

size_t PKIUnpacknoticeNumbers_SEQ_OFInternal(
    PKICONTEXT *ctx,
    PKInoticeNumbers_SEQ_OF **asnstruct,
    const unsigned char *buf,
    size_t buflen,
    unsigned char tag,
    int *erret)
{
    size_t bytesused;
    PKInoticeNumbers_SEQ_OF *local = NULL;

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

    if (ctx == NULL) {
        PKIERR(PKIErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) {
        PKIERR(PKIErrUnpackNoStructure);
        return 0;
    }
    *asnstruct = NULL;

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

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

    local = PKINewnoticeNumbers_SEQ_OF(ctx); /* carve a block for it */
    bytesused = PKIUnpkInPlacenoticeNumbers_SEQ_OF(ctx, local, buf, buflen, tag, erret);
    if (*erret != 0) {
        if (local != NULL) PKIFreenoticeNumbers_SEQ_OF(ctx, local);
        return 0;
    }
    *asnstruct = local;
    return bytesused;
} /* PKIUnpacknoticeNumbers_SEQ_OFInternal */


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

size_t PKISizeofAlgorithmIdentifierInternal(
    PKIAlgorithmIdentifier *asnstruct,
    int outerSizeFlag,
    int expTaggedFlag)
{
    size_t body_size = 0;

    if (asnstruct == NULL)
        return 0;

    body_size =
            PKISizeofOBJECT_IDInternal(&asnstruct->algorithm, PKITRUE, PKIFALSE)
          + PKISizeofANYInternal(asnstruct->parameters, PKITRUE, PKIFALSE) ;

    if (outerSizeFlag == PKITRUE)
        body_size = PKITagged(body_size, 1);

    if (expTaggedFlag == PKITRUE)
        body_size = PKITagged(body_size, 1); /* this is seq like */

    return body_size;

} /* PKISizeofAlgorithmIdentifierInternal */

void PKIDropInPlaceAlgorithmIdentifier(
    PKICONTEXT *ctx,
    PKIAlgorithmIdentifier *f)
{
    if (ctx == NULL)
        return;

    if (f == NULL) return ;
    PKIDropInPlaceOBJECT_ID(ctx, &(f->algorithm));
    PKIFreeANY(ctx, f->parameters);
    f->parameters = NULL;
} /* PKIDropInPlaceAlgorithmIdentifier */

size_t PKIPackAlgorithmIdentifierInternal(
    PKICONTEXT *ctx,
    unsigned char *buf,
    size_t buflen,
    PKIAlgorithmIdentifier *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) {
        PKIERR(PKIErrBadContext);
        return 0;
    }
    if (asnstruct == NULL) return 0;

    /* lth of the block body */
    datasize = PKISizeofAlgorithmIdentifier(ctx, asnstruct, PKIFALSE);
    tagsize = 1 + PKILengthSize(datasize);
    if (datasize+tagsize > buflen) {
        PKIERR(PKIErrPackBufferTooShort);
        return 0;
    }

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

  do {

    /* field algorithm of AlgorithmIdentifier */
    bytesused += PKIPackOBJECT_IDInternal(ctx, buf+bytesused, buflen-bytesused,
                       &(asnstruct->algorithm), PKIID_OBJECT_ID, erret);
    if (bytesused > datasize || *erret != 0)
        break;

    /* field parameters of AlgorithmIdentifier */
    if (asnstruct->parameters != NULL) { /* optional */
        bytesused += PKIPackANYInternal(ctx, buf+bytesused, buflen-bytesused,
                          asnstruct->parameters, PKIID_ANY, erret );
        if (bytesused > datasize || *erret != 0)
            break;
    }

  } while(0);

    if (bytesused < datasize && *erret == 0)
        PKIERR(PKIErrPackUnderrun)
    else if (bytesused > datasize && *erret == 0)
        PKIERR(PKIErrPackOverrun)

    return bytesused;
} /* PKIPackAlgorithmIdentifierInternal */

size_t PKIUnpkInPlaceAlgorithmIdentifier(
    PKICONTEXT *ctx,
    PKIAlgorithmIdentifier *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;

    PKITRACE_PRINT_FN((tag|0x20), 0x30, "SEQUENCE", "AlgorithmIdentifier" );

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

    if (ctx == NULL) {
        PKIERR(PKIErrBadContext);
        return 0;
    }

    if (asnstruct == NULL) {
        PKIERR(PKIErrUnpackNoStructure);
        return 0;
    }

    if (buf == NULL) {
        PKIERR(PKIErrUnpackNoBlockPtr);
        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) {
        PKIERR(PKIErrUnpackInvalidEncoding);
        return 0;
    }

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

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

    PKITRACE_INCR_LEVEL;
  do {

    /* field algorithm of AlgorithmIdentifier */
    bytesused += PKIUnpkInPlaceOBJECT_ID(ctx, &(asnstruct->algorithm), buf+bytesused,
                        localsize-bytesused, PKIID_OBJECT_ID, erret);
    if (bytesused > localsize || *erret != 0)
        break;

    /* field parameters of AlgorithmIdentifier */
    if (!indef && bytesused >= localsize) {
        PKITRACE_DECR_LEVEL;
        return bytesused;
    }
    if (indef && *(buf+bytesused) == 0x00 &&
                 *(buf+bytesused+1) == 0x00) {
        PKITRACE_DECR_LEVEL;
        bytesused += 2;
        return bytesused;
    }
    if (asnstruct->parameters != NULL)
        PKIFreeANY(ctx, asnstruct->parameters);
    bytesused += PKIUnpackANYInternal(ctx, &(asnstruct->parameters),
                    buf+bytesused, localsize-bytesused, PKIID_ANY, erret);
    if (bytesused > localsize || *erret != 0)
        break;

    if (indef) {
        if ( *(buf+bytesused) != 0x00 &&
             *(buf+bytesused+1) != 0x00 ) {
            PKIERR(PKIErrUnpackInvalidEncoding);

⌨️ 快捷键说明

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