📄 pkcs12.c
字号:
/*******************************************************************
*
* This file was generated by TIS/ASN1COMP Ver. 4.1, an ASN.1 compiler.
* TIS/ASN1COMP is Copyright (c) 1998, TIS Labs at Network Associates, Inc.
*
* This file was AUTOMATICALLY GENERATED on Fri Apr 9 20:37:30 1999
*
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pbe12.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 AuthenticatedSafes
******************************************************************/
size_t PKISizeofAuthenticatedSafesInternal(
PKIAuthenticatedSafes *asnstruct,
int outerSizeFlag,
int expTaggedFlag)
{
long i, lth;
size_t body_size = 0;
if (asnstruct == NULL)
return 0;
lth = asnstruct->n ;
if (lth > PKIMAX_AuthenticatedSafes)
lth = PKIMAX_AuthenticatedSafes; /* clamp it */
for (i=0; i<lth; i++)
body_size += PKISizeofContentInfoInternal((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;
} /* PKISizeofAuthenticatedSafesInternal */
void PKIDropInPlaceAuthenticatedSafes(
PKICONTEXT *ctx,
PKIAuthenticatedSafes *f)
{
long i, lth;
if (ctx == NULL) return;
if (f == NULL) return;
lth = f->n ;
if (lth > PKIMAX_AuthenticatedSafes)
lth = PKIMAX_AuthenticatedSafes ; /* clamp it */
for (i=0;i<lth;i++) {
PKIFreeContentInfo(ctx, (f->elt)[i]);
(f->elt)[i] = NULL;
}
} /* PKIDropInPlaceAuthenticatedSafes */
size_t PKIPackAuthenticatedSafesInternal(
PKICONTEXT *ctx,
unsigned char *buf,
size_t buflen,
PKIAuthenticatedSafes *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_AuthenticatedSafes) {
PKIERR(PKIErrPackSEQOFArrayTooLong);
return 0;
}
/* lth of the block body */
datasize = PKISizeofAuthenticatedSafes(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 += PKIPackContentInfoInternal(ctx, buf+bytesused, buflen-bytesused,
(asnstruct->elt)[i],
PKIID_ContentInfo, erret);
if (bytesused > datasize || *erret != 0)
break;
}
if (bytesused < datasize && *erret == 0)
PKIERR(PKIErrPackUnderrun)
else if (bytesused > datasize && *erret == 0)
PKIERR(PKIErrPackOverrun);
return bytesused;
} /* PKIPackAuthenticatedSafesInternal */
size_t PKIUnpkInPlaceAuthenticatedSafes(
PKICONTEXT *ctx,
PKIAuthenticatedSafes *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", "AuthenticatedSafes");
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_AuthenticatedSafes) && (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] = PKINewContentInfo(ctx);
bytesused += PKIUnpkInPlaceContentInfo(ctx, asnstruct->elt[i], buf+bytesused,
localsize-bytesused, PKIID_ContentInfo, erret);
if (*erret != 0 || asnstruct->elt[i] == NULL)
break;
asnstruct->n = i+1 ; /* note the new element */
} /* 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;
} /* PKIUnpkInPlaceAuthenticatedSafes */
size_t PKIUnpackAuthenticatedSafesInternal(
PKICONTEXT *ctx,
PKIAuthenticatedSafes **asnstruct,
const unsigned char *buf,
size_t buflen,
unsigned char tag,
int *erret)
{
size_t bytesused;
PKIAuthenticatedSafes *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 = PKINewAuthenticatedSafes(ctx); /* carve a block for it */
bytesused = PKIUnpkInPlaceAuthenticatedSafes(ctx, local, buf, buflen, tag, erret);
if (*erret != 0) {
if (local != NULL) PKIFreeAuthenticatedSafes(ctx, local);
return 0;
}
*asnstruct = local;
return bytesused;
} /* PKIUnpackAuthenticatedSafesInternal */
/******************************************************************
* Routines for CRLBag
******************************************************************/
size_t PKISizeofCRLBagInternal(
PKICRLBag *asnstruct,
int outerSizeFlag,
int expTaggedFlag)
{
size_t body_size = 0;
if (asnstruct == NULL)
return 0;
body_size =
PKISizeofOBJECT_IDInternal(&asnstruct->crlType, PKITRUE, PKIFALSE)
+ PKISizeofANYInternal(&asnstruct->crl, PKITRUE, PKITRUE) ;
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;
} /* PKISizeofCRLBagInternal */
void PKIDropInPlaceCRLBag(
PKICONTEXT *ctx,
PKICRLBag *f)
{
if (ctx == NULL)
return;
if (f == NULL) return ;
PKIDropInPlaceOBJECT_ID(ctx, &(f->crlType));
PKIDropInPlaceANY(ctx, &(f->crl));
} /* PKIDropInPlaceCRLBag */
size_t PKIPackCRLBagInternal(
PKICONTEXT *ctx,
unsigned char *buf,
size_t buflen,
PKICRLBag *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 = PKISizeofCRLBag(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 crlType of CRLBag */
bytesused += PKIPackOBJECT_IDInternal(ctx, buf+bytesused, buflen-bytesused,
&(asnstruct->crlType), PKIID_OBJECT_ID, erret);
if (bytesused > datasize || *erret != 0)
break;
/* field crl of CRLBag */
bytesused += PKIPutTag(buf+bytesused, 0xa0 | 0x00, PKISizeofANY(ctx, &(asnstruct->crl ), PKITRUE));
bytesused += PKIPackANYInternal(ctx, buf+bytesused, buflen-bytesused,
&(asnstruct->crl), 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;
} /* PKIPackCRLBagInternal */
size_t PKIUnpkInPlaceCRLBag(
PKICONTEXT *ctx,
PKICRLBag *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", "CRLBag" );
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 crlType of CRLBag */
bytesused += PKIUnpkInPlaceOBJECT_ID(ctx, &(asnstruct->crlType), buf+bytesused,
localsize-bytesused, PKIID_OBJECT_ID, erret);
if (bytesused > localsize || *erret != 0)
break;
/* field crl of CRLBag */
{ /* local declaration block*/
size_t taggeddatasize;
size_t taggedlocalsize;
size_t used;
used = PKITakeTag(buf+bytesused, 0xa0 | 0x00,
&taggeddatasize);
bytesused += used;
if ((int)taggeddatasize == -1 && used != 0) {
PKITRACE_PRINT_TAG(0xa0|0x00, 0x00);
PKITRACE_INCR_LEVEL;
bytesused += PKIUnpkInPlaceANY(ctx, &(asnstruct->crl), buf+bytesused,
localsize-bytesused, PKIID_ANY, erret);
PKITRACE_DECR_LEVEL;
if ( *(buf+bytesused) != 0x00 &&
*(buf+bytesused+1) != 0x00 ) {
PKIERR(PKIErrUnpackInvalidEncoding);
break;
}
bytesused += 2;
}
else if (taggeddatasize > 0 && used != 0) {
taggedlocalsize = bytesused + taggeddatasize;
PKITRACE_PRINT_TAG(0xa0|0x00, 0x00);
PKITRACE_INCR_LEVEL;
bytesused += PKIUnpkInPlaceANY(ctx, &(asnstruct->crl), buf+bytesused,
localsize-bytesused, PKIID_ANY, erret);
PKITRACE_DECR_LEVEL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -