Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
secasn1.h File Reference
#include "plarena.h"
#include "seccomon.h"
#include "secasn1t.h"

Go to the source code of this file.

Functions

SEC_BEGIN_PROTOS
SEC_ASN1DecoderContext * 
SEC_ASN1DecoderStart (PRArenaPool *pool, void *dest, const SEC_ASN1Template *t)
SECStatus SEC_ASN1DecoderUpdate (SEC_ASN1DecoderContext *cx, const char *buf, unsigned long len)
SECStatus SEC_ASN1DecoderFinish (SEC_ASN1DecoderContext *cx)
void SEC_ASN1DecoderAbort (SEC_ASN1DecoderContext *cx, int error)
void SEC_ASN1DecoderSetFilterProc (SEC_ASN1DecoderContext *cx, SEC_ASN1WriteProc fn, void *arg, PRBool no_store)
void SEC_ASN1DecoderClearFilterProc (SEC_ASN1DecoderContext *cx)
void SEC_ASN1DecoderSetNotifyProc (SEC_ASN1DecoderContext *cx, SEC_ASN1NotifyProc fn, void *arg)
void SEC_ASN1DecoderClearNotifyProc (SEC_ASN1DecoderContext *cx)
SECStatus SEC_ASN1Decode (PRArenaPool *pool, void *dest, const SEC_ASN1Template *t, const char *buf, long len)
SECStatus SEC_ASN1DecodeItem (PRArenaPool *pool, void *dest, const SEC_ASN1Template *t, const SECItem *src)
SECStatus SEC_QuickDERDecodeItem (PRArenaPool *arena, void *dest, const SEC_ASN1Template *templateEntry, const SECItem *src)
SEC_ASN1EncoderContext * SEC_ASN1EncoderStart (const void *src, const SEC_ASN1Template *t, SEC_ASN1WriteProc fn, void *output_arg)
SECStatus SEC_ASN1EncoderUpdate (SEC_ASN1EncoderContext *cx, const char *buf, unsigned long len)
void SEC_ASN1EncoderFinish (SEC_ASN1EncoderContext *cx)
void SEC_ASN1EncoderAbort (SEC_ASN1EncoderContext *cx, int error)
void SEC_ASN1EncoderSetNotifyProc (SEC_ASN1EncoderContext *cx, SEC_ASN1NotifyProc fn, void *arg)
void SEC_ASN1EncoderClearNotifyProc (SEC_ASN1EncoderContext *cx)
void SEC_ASN1EncoderSetStreaming (SEC_ASN1EncoderContext *cx)
void SEC_ASN1EncoderClearStreaming (SEC_ASN1EncoderContext *cx)
void sec_ASN1EncoderSetDER (SEC_ASN1EncoderContext *cx)
void sec_ASN1EncoderClearDER (SEC_ASN1EncoderContext *cx)
void SEC_ASN1EncoderSetTakeFromBuf (SEC_ASN1EncoderContext *cx)
void SEC_ASN1EncoderClearTakeFromBuf (SEC_ASN1EncoderContext *cx)
SECStatus SEC_ASN1Encode (const void *src, const SEC_ASN1Template *t, SEC_ASN1WriteProc output_proc, void *output_arg)
SECItem * SEC_ASN1EncodeItem (PRArenaPool *pool, SECItem *dest, const void *src, const SEC_ASN1Template *t)
SECItem * SEC_ASN1EncodeInteger (PRArenaPool *pool, SECItem *dest, long value)
SECItem * SEC_ASN1EncodeUnsignedInteger (PRArenaPool *pool, SECItem *dest, unsigned long value)
SECStatus SEC_ASN1DecodeInteger (SECItem *src, unsigned long *value)
int SEC_ASN1LengthLength (unsigned long len)
int SEC_ASN1EncodeLength (unsigned char *buf, int value)
const SEC_ASN1TemplateSEC_ASN1GetSubtemplate (const SEC_ASN1Template *inTemplate, void *thing, PRBool encoding)
PRBool SEC_ASN1IsTemplateSimple (const SEC_ASN1Template *theTemplate)

Variables

const SEC_ASN1Template SEC_AnyTemplate []
const SEC_ASN1Template SEC_BitStringTemplate []
const SEC_ASN1Template SEC_BMPStringTemplate []
const SEC_ASN1Template SEC_BooleanTemplate []
const SEC_ASN1Template SEC_EnumeratedTemplate []
const SEC_ASN1Template SEC_GeneralizedTimeTemplate []
const SEC_ASN1Template SEC_IA5StringTemplate []
const SEC_ASN1Template SEC_IntegerTemplate []
const SEC_ASN1Template SEC_NullTemplate []
const SEC_ASN1Template SEC_ObjectIDTemplate []
const SEC_ASN1Template SEC_OctetStringTemplate []
const SEC_ASN1Template SEC_PrintableStringTemplate []
const SEC_ASN1Template SEC_T61StringTemplate []
const SEC_ASN1Template SEC_UniversalStringTemplate []
const SEC_ASN1Template SEC_UTCTimeTemplate []
const SEC_ASN1Template SEC_UTF8StringTemplate []
const SEC_ASN1Template SEC_VisibleStringTemplate []
const SEC_ASN1Template SEC_PointerToAnyTemplate []
const SEC_ASN1Template SEC_PointerToBitStringTemplate []
const SEC_ASN1Template SEC_PointerToBMPStringTemplate []
const SEC_ASN1Template SEC_PointerToBooleanTemplate []
const SEC_ASN1Template SEC_PointerToEnumeratedTemplate []
const SEC_ASN1Template SEC_PointerToGeneralizedTimeTemplate []
const SEC_ASN1Template SEC_PointerToIA5StringTemplate []
const SEC_ASN1Template SEC_PointerToIntegerTemplate []
const SEC_ASN1Template SEC_PointerToNullTemplate []
const SEC_ASN1Template SEC_PointerToObjectIDTemplate []
const SEC_ASN1Template SEC_PointerToOctetStringTemplate []
const SEC_ASN1Template SEC_PointerToPrintableStringTemplate []
const SEC_ASN1Template SEC_PointerToT61StringTemplate []
const SEC_ASN1Template SEC_PointerToUniversalStringTemplate []
const SEC_ASN1Template SEC_PointerToUTCTimeTemplate []
const SEC_ASN1Template SEC_PointerToUTF8StringTemplate []
const SEC_ASN1Template SEC_PointerToVisibleStringTemplate []
const SEC_ASN1Template SEC_SequenceOfAnyTemplate []
const SEC_ASN1Template SEC_SequenceOfBitStringTemplate []
const SEC_ASN1Template SEC_SequenceOfBMPStringTemplate []
const SEC_ASN1Template SEC_SequenceOfBooleanTemplate []
const SEC_ASN1Template SEC_SequenceOfEnumeratedTemplate []
const SEC_ASN1Template SEC_SequenceOfGeneralizedTimeTemplate []
const SEC_ASN1Template SEC_SequenceOfIA5StringTemplate []
const SEC_ASN1Template SEC_SequenceOfIntegerTemplate []
const SEC_ASN1Template SEC_SequenceOfNullTemplate []
const SEC_ASN1Template SEC_SequenceOfObjectIDTemplate []
const SEC_ASN1Template SEC_SequenceOfOctetStringTemplate []
const SEC_ASN1Template SEC_SequenceOfPrintableStringTemplate []
const SEC_ASN1Template SEC_SequenceOfT61StringTemplate []
const SEC_ASN1Template SEC_SequenceOfUniversalStringTemplate []
const SEC_ASN1Template SEC_SequenceOfUTCTimeTemplate []
const SEC_ASN1Template SEC_SequenceOfUTF8StringTemplate []
const SEC_ASN1Template SEC_SequenceOfVisibleStringTemplate []
const SEC_ASN1Template SEC_SetOfAnyTemplate []
const SEC_ASN1Template SEC_SetOfBitStringTemplate []
const SEC_ASN1Template SEC_SetOfBMPStringTemplate []
const SEC_ASN1Template SEC_SetOfBooleanTemplate []
const SEC_ASN1Template SEC_SetOfEnumeratedTemplate []
const SEC_ASN1Template SEC_SetOfGeneralizedTimeTemplate []
const SEC_ASN1Template SEC_SetOfIA5StringTemplate []
const SEC_ASN1Template SEC_SetOfIntegerTemplate []
const SEC_ASN1Template SEC_SetOfNullTemplate []
const SEC_ASN1Template SEC_SetOfObjectIDTemplate []
const SEC_ASN1Template SEC_SetOfOctetStringTemplate []
const SEC_ASN1Template SEC_SetOfPrintableStringTemplate []
const SEC_ASN1Template SEC_SetOfT61StringTemplate []
const SEC_ASN1Template SEC_SetOfUniversalStringTemplate []
const SEC_ASN1Template SEC_SetOfUTCTimeTemplate []
const SEC_ASN1Template SEC_SetOfUTF8StringTemplate []
const SEC_ASN1Template SEC_SetOfVisibleStringTemplate []
const SEC_ASN1Template SEC_SkipTemplate []

Function Documentation

SECStatus SEC_ASN1Decode ( PRArenaPool pool,
void dest,
const SEC_ASN1Template t,
const char *  buf,
long  len 
)

Definition at line 2951 of file secasn1d.c.

{
    SEC_ASN1DecoderContext *dcx;
    SECStatus urv, frv;

    dcx = SEC_ASN1DecoderStart (poolp, dest, theTemplate);
    if (dcx == NULL)
       return SECFailure;

    urv = SEC_ASN1DecoderUpdate (dcx, buf, len);
    frv = SEC_ASN1DecoderFinish (dcx);

    if (urv != SECSuccess)
       return urv;

    return frv;
}

Here is the call graph for this function:

SECStatus SEC_ASN1DecodeInteger ( SECItem *  src,
unsigned long value 
)

Definition at line 2520 of file secasn1d.c.

{
    unsigned long v;
    unsigned int i;
    
    if (src == NULL) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return SECFailure;
    }

    if (src->len > sizeof(unsigned long)) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return SECFailure;
    }

    if (src->data == NULL) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       return SECFailure;
    }

    if (src->data[0] & 0x80)
       v = -1;              /* signed and negative - start with all 1's */
    else
       v = 0;

    for (i= 0; i < src->len; i++) {
       /* shift in next byte */
       v <<= 8;
       v |= src->data[i];
    }
    *value = v;
    return SECSuccess;
}

Here is the call graph for this function:

SECStatus SEC_ASN1DecodeItem ( PRArenaPool pool,
void dest,
const SEC_ASN1Template t,
const SECItem *  src 
)

Definition at line 2973 of file secasn1d.c.

{
    return SEC_ASN1Decode (poolp, dest, theTemplate,
                        (const char *)src->data, src->len);
}

Here is the call graph for this function:

void SEC_ASN1DecoderAbort ( SEC_ASN1DecoderContext *  cx,
int  error 
)

Definition at line 2942 of file secasn1d.c.

Here is the call graph for this function:

void SEC_ASN1DecoderClearFilterProc ( SEC_ASN1DecoderContext *  cx)

Definition at line 2914 of file secasn1d.c.

{
    /* check that we are "between" fields here */
    PORT_Assert (cx->during_notify);

    cx->filter_proc = NULL;
    cx->filter_arg = NULL;
    cx->filter_only = PR_FALSE;
}
void SEC_ASN1DecoderClearNotifyProc ( SEC_ASN1DecoderContext *  cx)

Definition at line 2935 of file secasn1d.c.

{
    cx->notify_proc = NULL;
    cx->notify_arg = NULL;  /* not necessary; just being clean */
}
SECStatus SEC_ASN1DecoderFinish ( SEC_ASN1DecoderContext *  cx)

Definition at line 2837 of file secasn1d.c.

{
    SECStatus rv;

    if (cx->status == needBytes) {
       PORT_SetError (SEC_ERROR_BAD_DER);
       rv = SECFailure;
    } else {
       rv = SECSuccess;
    }

    /*
     * XXX anything else that needs to be finished?
     */

    PORT_FreeArena (cx->our_pool, PR_TRUE);

    return rv;
}

Here is the call graph for this function:

void SEC_ASN1DecoderSetFilterProc ( SEC_ASN1DecoderContext *  cx,
SEC_ASN1WriteProc  fn,
void arg,
PRBool  no_store 
)

Definition at line 2900 of file secasn1d.c.

{
    /* check that we are "between" fields here */
    PORT_Assert (cx->during_notify);

    cx->filter_proc = fn;
    cx->filter_arg = arg;
    cx->filter_only = only;
}
void SEC_ASN1DecoderSetNotifyProc ( SEC_ASN1DecoderContext *  cx,
SEC_ASN1NotifyProc  fn,
void arg 
)

Definition at line 2926 of file secasn1d.c.

{
    cx->notify_proc = fn;
    cx->notify_arg = arg;
}
SEC_BEGIN_PROTOS SEC_ASN1DecoderContext* SEC_ASN1DecoderStart ( PRArenaPool pool,
void dest,
const SEC_ASN1Template t 
)

Definition at line 2859 of file secasn1d.c.

{
    PRArenaPool *our_pool;
    SEC_ASN1DecoderContext *cx;

    our_pool = PORT_NewArena (SEC_ASN1_DEFAULT_ARENA_SIZE);
    if (our_pool == NULL)
       return NULL;

    cx = (SEC_ASN1DecoderContext*)PORT_ArenaZAlloc (our_pool, sizeof(*cx));
    if (cx == NULL) {
       PORT_FreeArena (our_pool, PR_FALSE);
       return NULL;
    }

    cx->our_pool = our_pool;
    if (their_pool != NULL) {
       cx->their_pool = their_pool;
#ifdef SEC_ASN1D_FREE_ON_ERROR
       cx->their_mark = PORT_ArenaMark (their_pool);
#endif
    }

    cx->status = needBytes;

    if (sec_asn1d_push_state(cx, theTemplate, dest, PR_FALSE) == NULL
       || sec_asn1d_init_state_based_on_template (cx->current) == NULL) {
       /*
        * Trouble initializing (probably due to failed allocations)
        * requires that we just give up.
        */
       PORT_FreeArena (our_pool, PR_FALSE);
       return NULL;
    }

    return cx;
}

Here is the call graph for this function:

SECStatus SEC_ASN1DecoderUpdate ( SEC_ASN1DecoderContext *  cx,
const char *  buf,
unsigned long  len 
)

Definition at line 2596 of file secasn1d.c.

{
    sec_asn1d_state *state = NULL;
    unsigned long consumed;
    SEC_ASN1EncodingPart what;
    sec_asn1d_state *stateEnd = cx->current;

    if (cx->status == needBytes)
       cx->status = keepGoing;

    while (cx->status == keepGoing) {
       state = cx->current;
       what = SEC_ASN1_Contents;
       consumed = 0;
#ifdef DEBUG_ASN1D_STATES
        printf("\nPLACE = %s, next byte = 0x%02x, %08x[%d]\n",
               (state->place >= 0 && state->place <= notInUse) ?
               place_names[ state->place ] : "(undefined)",
               (unsigned int)((unsigned char *)buf)[ consumed ],
               buf, consumed);
        dump_states(cx);
#endif /* DEBUG_ASN1D_STATES */
       switch (state->place) {
         case beforeIdentifier:
           consumed = sec_asn1d_parse_identifier (state, buf, len);
           what = SEC_ASN1_Identifier;
           break;
         case duringIdentifier:
           consumed = sec_asn1d_parse_more_identifier (state, buf, len);
           what = SEC_ASN1_Identifier;
           break;
         case afterIdentifier:
           sec_asn1d_confirm_identifier (state);
           break;
         case beforeLength:
           consumed = sec_asn1d_parse_length (state, buf, len);
           what = SEC_ASN1_Length;
           break;
         case duringLength:
           consumed = sec_asn1d_parse_more_length (state, buf, len);
           what = SEC_ASN1_Length;
           break;
         case afterLength:
           sec_asn1d_prepare_for_contents (state);
           break;
         case beforeBitString:
           consumed = sec_asn1d_parse_bit_string (state, buf, len);
           break;
         case duringBitString:
           consumed = sec_asn1d_parse_more_bit_string (state, buf, len);
           break;
         case duringConstructedString:
           sec_asn1d_next_substring (state);
           break;
         case duringGroup:
           sec_asn1d_next_in_group (state);
           break;
         case duringLeaf:
           consumed = sec_asn1d_parse_leaf (state, buf, len);
           break;
         case duringSaveEncoding:
           sec_asn1d_reuse_encoding (state);
           if (cx->status == decodeError) {
              /* recursive call has already popped all states from stack.
              ** Bail out quickly.
              */
              return SECFailure;
           }
           if (cx->status == needBytes) {
              /* recursive call wanted more data. Fatal. Clean up below. */
              PORT_SetError (SEC_ERROR_BAD_DER);
              cx->status = decodeError;
           }
           break;
         case duringSequence:
           sec_asn1d_next_in_sequence (state);
           break;
         case afterConstructedString:
           sec_asn1d_concat_substrings (state);
           break;
         case afterExplicit:
         case afterImplicit:
         case afterInline:
         case afterPointer:
           sec_asn1d_absorb_child (state);
           break;
         case afterGroup:
           sec_asn1d_concat_group (state);
           break;
         case afterSaveEncoding:
           /* SEC_ASN1DecoderUpdate has called itself recursively to 
           ** decode SAVEd encoded data, and now is done decoding that.
           ** Return to the calling copy of SEC_ASN1DecoderUpdate.
           */
           return SECSuccess;
         case beforeEndOfContents:
           sec_asn1d_prepare_for_end_of_contents (state);
           break;
         case duringEndOfContents:
           consumed = sec_asn1d_parse_end_of_contents (state, buf, len);
           what = SEC_ASN1_EndOfContents;
           break;
         case afterEndOfContents:
           sec_asn1d_pop_state (state);
           break;
          case beforeChoice:
            state = sec_asn1d_before_choice(state);
            break;
          case duringChoice:
            state = sec_asn1d_during_choice(state);
            break;
          case afterChoice:
            sec_asn1d_after_choice(state);
            break;
         case notInUse:
         default:
           /* This is not an error, but rather a plain old BUG! */
           PORT_Assert (0);
           PORT_SetError (SEC_ERROR_BAD_DER);
           cx->status = decodeError;
           break;
       }

       if (cx->status == decodeError)
           break;

       /* We should not consume more than we have.  */
       PORT_Assert (consumed <= len);
       if (consumed > len) {
           PORT_SetError (SEC_ERROR_BAD_DER);
           cx->status = decodeError;
           break;
       }

       /* It might have changed, so we have to update our local copy.  */
       state = cx->current;

       /* If it is NULL, we have popped all the way to the top.  */
       if (state == NULL) {
           PORT_Assert (consumed == 0);
#if 0  /* XXX I want this here, but it seems that we have situations (like
        * downloading a pkcs7 cert chain from some issuers) that give us a
        * length which is greater than the entire encoding.  So, we cannot
        * have this be an error.
        */
           if (len > 0) {
              PORT_SetError (SEC_ERROR_BAD_DER);
              cx->status = decodeError;
           } else
#endif
              cx->status = allDone;
           break;
       }
       else if (state->theTemplate->kind == SEC_ASN1_SKIP_REST) {
           cx->status = allDone;
           break;
       }
         
       if (consumed == 0)
           continue;

       /*
        * The following check is specifically looking for an ANY
        * that is *not* also an INNER, because we need to save aside
        * all bytes in that case -- the contents parts will get
        * handled like all other contents, and the end-of-contents
        * bytes are added by the concat code, but the outer header
        * bytes need to get saved too, so we do them explicitly here.
        */
       if (state->underlying_kind == SEC_ASN1_ANY
           && !cx->filter_only && (what == SEC_ASN1_Identifier
                                || what == SEC_ASN1_Length)) {
           sec_asn1d_record_any_header (state, buf, consumed);
       }

       /*
        * We had some number of good, accepted bytes.  If the caller
        * has registered to see them, pass them along.
        */
       if (state->top->filter_proc != NULL) {
           int depth;

           depth = state->depth;
           if (what == SEC_ASN1_EndOfContents && !state->indefinite) {
              PORT_Assert (state->parent != NULL
                          && state->parent->indefinite);
              depth--;
              PORT_Assert (depth == state->parent->depth);
           }
           (* state->top->filter_proc) (state->top->filter_arg,
                                    buf, consumed, depth, what);
       }

       state->consumed += consumed;
       buf += consumed;
       len -= consumed;
    }

    if (cx->status == decodeError) {
       while (state != NULL && stateEnd->parent!=state) {
           sec_asn1d_free_child (state, PR_TRUE);
           state = state->parent;
       }
#ifdef SEC_ASN1D_FREE_ON_ERROR     /*
                             * XXX This does not work because we can
                             * end up leaving behind dangling pointers
                             * to stuff that was allocated.  In order
                             * to make this really work (which would
                             * be a good thing, I think), we need to
                             * keep track of every place/pointer that
                             * was allocated and make sure to NULL it
                             * out before we then free back to the mark.     
                             */
       if (cx->their_pool != NULL) {
           PORT_Assert (cx->their_mark != NULL);
           PORT_ArenaRelease (cx->their_pool, cx->their_mark);
       }
#endif
       return SECFailure;
    }

#if 0  /* XXX This is what I want, but cannot have because it seems we
        * have situations (like when downloading a pkcs7 cert chain from
        * some issuers) that give us a total length which is greater than
        * the entire encoding.  So, we have to allow allDone to have a
        * remaining length greater than zero.  I wanted to catch internal
        * bugs with this, noticing when we do not have the right length.
        * Oh well.
        */
    PORT_Assert (len == 0
               && (cx->status == needBytes || cx->status == allDone));
#else
    PORT_Assert ((len == 0 && cx->status == needBytes)
               || cx->status == allDone);
#endif
    return SECSuccess;
}

Here is the call graph for this function:

SECStatus SEC_ASN1Encode ( const void src,
const SEC_ASN1Template t,
SEC_ASN1WriteProc  output_proc,
void output_arg 
)

Definition at line 1457 of file secasn1e.c.

{
    SEC_ASN1EncoderContext *ecx;
    SECStatus rv;

    ecx = SEC_ASN1EncoderStart (src, theTemplate, output_proc, output_arg);
    if (ecx == NULL)
       return SECFailure;

    rv = SEC_ASN1EncoderUpdate (ecx, NULL, 0);

    SEC_ASN1EncoderFinish (ecx);
    return rv;
}

Here is the call graph for this function:

SECItem* SEC_ASN1EncodeInteger ( PRArenaPool pool,
SECItem *  dest,
long  value 
)

Definition at line 1636 of file secasn1e.c.

{
    return sec_asn1e_integer (poolp, dest, (unsigned long) value, PR_FALSE);
}

Here is the call graph for this function:

SECItem* SEC_ASN1EncodeItem ( PRArenaPool pool,
SECItem *  dest,
const void src,
const SEC_ASN1Template t 
)

Definition at line 1557 of file secasn1e.c.

{
    unsigned long encoding_length;
    SECStatus rv;

    PORT_Assert (dest == NULL || dest->data == NULL);

    encoding_length = 0;
    rv = SEC_ASN1Encode (src, theTemplate,
                      sec_asn1e_encode_item_count, &encoding_length);
    if (rv != SECSuccess)
       return NULL;

    dest = sec_asn1e_allocate_item (poolp, dest, encoding_length);
    if (dest == NULL)
       return NULL;

    /* XXX necessary?  This really just checks for a bug in the allocate fn */
    PORT_Assert (dest->data != NULL);
    if (dest->data == NULL)
       return NULL;

    dest->len = 0;
    (void) SEC_ASN1Encode (src, theTemplate, sec_asn1e_encode_item_store, dest);

    PORT_Assert (encoding_length == dest->len);
    return dest;
}

Here is the call graph for this function:

int SEC_ASN1EncodeLength ( unsigned char *  buf,
int  value 
)

Definition at line 436 of file secasn1e.c.

                                                   {
    int lenlen;

    lenlen = SEC_ASN1LengthLength (value);
    if (lenlen == 1) {
       buf[0] = value;
    } else {
       int i;

       i = lenlen - 1;
       buf[0] = 0x80 | i;
       while (i) {
           buf[i--] = value;
           value >>= 8;
       }
        PORT_Assert (value == 0);
    }
    return lenlen;
}

Here is the call graph for this function:

void SEC_ASN1EncoderAbort ( SEC_ASN1EncoderContext *  cx,
int  error 
)

Definition at line 1400 of file secasn1e.c.

Here is the call graph for this function:

void sec_ASN1EncoderClearDER ( SEC_ASN1EncoderContext *  cx)
void SEC_ASN1EncoderClearNotifyProc ( SEC_ASN1EncoderContext *  cx)

Definition at line 1393 of file secasn1e.c.

{
    cx->notify_proc = NULL;
    cx->notify_arg = NULL;  /* not necessary; just being clean */
}
void SEC_ASN1EncoderClearStreaming ( SEC_ASN1EncoderContext *  cx)

Definition at line 1417 of file secasn1e.c.

{
    /* XXX is there a way to check that we are "between" fields here? */

    cx->streaming = PR_FALSE;
}
void SEC_ASN1EncoderClearTakeFromBuf ( SEC_ASN1EncoderContext *  cx)

Definition at line 1440 of file secasn1e.c.

{
    /* we should actually be taking from buf *now* */
    PORT_Assert (cx->from_buf);
    if (! cx->from_buf)            /* if not, just do nothing */
       return;

    cx->from_buf = PR_FALSE;

    if (cx->status == needBytes) {
       cx->status = keepGoing;
       cx->current->place = afterContents;
    }
}
void SEC_ASN1EncoderFinish ( SEC_ASN1EncoderContext *  cx)

Definition at line 1331 of file secasn1e.c.

{
    /*
     * XXX anything else that needs to be finished?
     */

    PORT_FreeArena (cx->our_pool, PR_FALSE);
}

Here is the call graph for this function:

void sec_ASN1EncoderSetDER ( SEC_ASN1EncoderContext *  cx)
void SEC_ASN1EncoderSetNotifyProc ( SEC_ASN1EncoderContext *  cx,
SEC_ASN1NotifyProc  fn,
void arg 
)

Definition at line 1384 of file secasn1e.c.

{
    cx->notify_proc = fn;
    cx->notify_arg = arg;
}
void SEC_ASN1EncoderSetStreaming ( SEC_ASN1EncoderContext *  cx)

Definition at line 1408 of file secasn1e.c.

{
    /* XXX is there a way to check that we are "between" fields here? */

    cx->streaming = PR_TRUE;
}
void SEC_ASN1EncoderSetTakeFromBuf ( SEC_ASN1EncoderContext *  cx)

Definition at line 1426 of file secasn1e.c.

{
    /* 
     * XXX is there a way to check that we are "between" fields here?  this
     * needs to include a check for being in between groups of items in
     * a SET_OF or SEQUENCE_OF.
     */
    PORT_Assert (cx->streaming);

    cx->from_buf = PR_TRUE;
}
SEC_ASN1EncoderContext* SEC_ASN1EncoderStart ( const void src,
const SEC_ASN1Template t,
SEC_ASN1WriteProc  fn,
void output_arg 
)

Definition at line 1342 of file secasn1e.c.

{
    PRArenaPool *our_pool;
    SEC_ASN1EncoderContext *cx;

    our_pool = PORT_NewArena (SEC_ASN1_DEFAULT_ARENA_SIZE);
    if (our_pool == NULL)
       return NULL;

    cx = (SEC_ASN1EncoderContext*)PORT_ArenaZAlloc (our_pool, sizeof(*cx));
    if (cx == NULL) {
       PORT_FreeArena (our_pool, PR_FALSE);
       return NULL;
    }

    cx->our_pool = our_pool;
    cx->output_proc = output_proc;
    cx->output_arg = output_arg;

    cx->status = keepGoing;

    if (sec_asn1e_push_state(cx, theTemplate, src, PR_FALSE) == NULL
       || sec_asn1e_init_state_based_on_template (cx->current) == NULL) {
       /*
        * Trouble initializing (probably due to failed allocations)
        * requires that we just give up.
        */
       PORT_FreeArena (our_pool, PR_FALSE);
       return NULL;
    }

    return cx;
}

Here is the call graph for this function:

SECStatus SEC_ASN1EncoderUpdate ( SEC_ASN1EncoderContext *  cx,
const char *  buf,
unsigned long  len 
)

Definition at line 1260 of file secasn1e.c.

{
    sec_asn1e_state *state;

    if (cx->status == needBytes) {
       cx->status = keepGoing;
    }

    while (cx->status == keepGoing) {
       state = cx->current;
       switch (state->place) {
         case beforeHeader:
           sec_asn1e_write_header (state);
           break;
         case duringContents:
           if (cx->from_buf)
              sec_asn1e_write_contents_from_buf (state, buf, len);
           else
              sec_asn1e_write_contents (state);
           break;
         case duringGroup:
           sec_asn1e_next_in_group (state);
           break;
         case duringSequence:
           sec_asn1e_next_in_sequence (state);
           break;
         case afterContents:
           sec_asn1e_after_contents (state);
           break;
         case afterImplicit:
         case afterInline:
         case afterPointer:
         case afterChoice:
           /*
            * These states are more documentation than anything.
            * They just need to force a pop.
            */
           PORT_Assert (!state->indefinite);
           state->place = afterContents;
           break;
         case notInUse:
         default:
           /* This is not an error, but rather a plain old BUG! */
           PORT_Assert (0);
           cx->status = encodeError;
           break;
       }

       if (cx->status == encodeError)
           break;

       /* It might have changed, so we have to update our local copy.  */
       state = cx->current;

       /* If it is NULL, we have popped all the way to the top.  */
       if (state == NULL) {
           cx->status = allDone;
           break;
       }
    }

    if (cx->status == encodeError) {
       return SECFailure;
    }

    return SECSuccess;
}

Here is the call graph for this function:

SECItem* SEC_ASN1EncodeUnsignedInteger ( PRArenaPool pool,
SECItem *  dest,
unsigned long  value 
)

Definition at line 1643 of file secasn1e.c.

{
    return sec_asn1e_integer (poolp, dest, value, PR_TRUE);
}

Here is the call graph for this function:

const SEC_ASN1Template* SEC_ASN1GetSubtemplate ( const SEC_ASN1Template inTemplate,
void thing,
PRBool  encoding 
)

Definition at line 88 of file secasn1u.c.

{
    const SEC_ASN1Template *subt = NULL;

    PORT_Assert (theTemplate->sub != NULL);
    if (theTemplate->sub != NULL) {
       if (theTemplate->kind & SEC_ASN1_DYNAMIC) {
           SEC_ASN1TemplateChooserPtr chooserp;

           chooserp = *(SEC_ASN1TemplateChooserPtr *) theTemplate->sub;
           if (chooserp) {
              if (thing != NULL)
                  thing = (char *)thing - theTemplate->offset;
              subt = (* chooserp)(thing, encoding);
           }
       } else {
           subt = (SEC_ASN1Template*)theTemplate->sub;
       }
    }
    return subt;
}

Here is the call graph for this function:

Definition at line 111 of file secasn1u.c.

{
    if (!theTemplate) {
       return PR_TRUE; /* it doesn't get any simpler than NULL */
    }
    /* only templates made of one primitive type or a choice of primitive
       types are considered simple */
    if (! (theTemplate->kind & (~SEC_ASN1_TAGNUM_MASK))) {
       return PR_TRUE; /* primitive type */
    }
    if (!theTemplate->kind & SEC_ASN1_CHOICE) {
       return PR_FALSE; /* no choice means not simple */
    }
    while (++theTemplate && theTemplate->kind) {
       if (theTemplate->kind & (~SEC_ASN1_TAGNUM_MASK)) {
           return PR_FALSE; /* complex type */
       }
    }
    return PR_TRUE; /* choice of primitive types */
}
int SEC_ASN1LengthLength ( unsigned long  len)

Definition at line 55 of file secasn1u.c.

{
    int lenlen = 1;

    if (len > 0x7f) {
       do {
           lenlen++;
           len >>= 8;
       } while (len);
    }

    return lenlen;
}
SECStatus SEC_QuickDERDecodeItem ( PRArenaPool arena,
void dest,
const SEC_ASN1Template templateEntry,
const SECItem *  src 
)

Definition at line 886 of file quickder.c.

{
    SECStatus rv = SECSuccess;
    SECItem newsrc;

    if (!arena || !templateEntry || !src)
    {
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
        rv = SECFailure;
    }

    if (SECSuccess == rv)
    {
        newsrc = *src;
        rv = DecodeItem(dest, templateEntry, &newsrc, arena, PR_TRUE);
        if (SECSuccess == rv && newsrc.len)
        {
            rv = SECFailure;
            PORT_SetError(SEC_ERROR_EXTRA_INPUT);
        }
    }

    return rv;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 3005 of file secasn1d.c.

Definition at line 3021 of file secasn1d.c.

Definition at line 3037 of file secasn1d.c.

Definition at line 3053 of file secasn1d.c.

Definition at line 3069 of file secasn1d.c.

Definition at line 3085 of file secasn1d.c.

Definition at line 3101 of file secasn1d.c.

Definition at line 3117 of file secasn1d.c.

Definition at line 3133 of file secasn1d.c.

Definition at line 3149 of file secasn1d.c.

Definition at line 3165 of file secasn1d.c.

Definition at line 3009 of file secasn1d.c.

Definition at line 3025 of file secasn1d.c.

Definition at line 3041 of file secasn1d.c.

Definition at line 3057 of file secasn1d.c.

Definition at line 3073 of file secasn1d.c.

Definition at line 3089 of file secasn1d.c.

Definition at line 3105 of file secasn1d.c.

Definition at line 3121 of file secasn1d.c.

Definition at line 3137 of file secasn1d.c.

Definition at line 3153 of file secasn1d.c.

Definition at line 3169 of file secasn1d.c.

Definition at line 3185 of file secasn1d.c.

Definition at line 3201 of file secasn1d.c.

Definition at line 3217 of file secasn1d.c.

Definition at line 3233 of file secasn1d.c.

Definition at line 3249 of file secasn1d.c.

Definition at line 3265 of file secasn1d.c.

Definition at line 3181 of file secasn1d.c.

Definition at line 3013 of file secasn1d.c.

Definition at line 3029 of file secasn1d.c.

Definition at line 3045 of file secasn1d.c.

Definition at line 3061 of file secasn1d.c.

Definition at line 3077 of file secasn1d.c.

Definition at line 3093 of file secasn1d.c.

Definition at line 3109 of file secasn1d.c.

Definition at line 3125 of file secasn1d.c.

Definition at line 3141 of file secasn1d.c.

Definition at line 3157 of file secasn1d.c.

Definition at line 3173 of file secasn1d.c.

Definition at line 3189 of file secasn1d.c.

Definition at line 3205 of file secasn1d.c.

Definition at line 3221 of file secasn1d.c.

Definition at line 3237 of file secasn1d.c.

Definition at line 3253 of file secasn1d.c.

Definition at line 3269 of file secasn1d.c.

Definition at line 3017 of file secasn1d.c.

Definition at line 3033 of file secasn1d.c.

Definition at line 3049 of file secasn1d.c.

Definition at line 3065 of file secasn1d.c.

Definition at line 3081 of file secasn1d.c.

Definition at line 3097 of file secasn1d.c.

Definition at line 3113 of file secasn1d.c.

Definition at line 3129 of file secasn1d.c.

Definition at line 3145 of file secasn1d.c.

Definition at line 3161 of file secasn1d.c.

Definition at line 3177 of file secasn1d.c.

Definition at line 3193 of file secasn1d.c.

Definition at line 3209 of file secasn1d.c.

Definition at line 3225 of file secasn1d.c.

Definition at line 3241 of file secasn1d.c.

Definition at line 3257 of file secasn1d.c.

Definition at line 3273 of file secasn1d.c.

Definition at line 3285 of file secasn1d.c.

Definition at line 3197 of file secasn1d.c.

Definition at line 3213 of file secasn1d.c.

Definition at line 3229 of file secasn1d.c.

Definition at line 3245 of file secasn1d.c.

Definition at line 3261 of file secasn1d.c.