Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
asn1.c File Reference
#include "asn1m.h"
#include "plarena.h"
#include "secasn1.h"

Go to the source code of this file.

Functions

NSS_IMPLEMENT nssASN1DecodernssASN1Decoder_Create (NSSArena *arenaOpt, void *destination, const nssASN1Template template[])
NSS_IMPLEMENT PRStatus nssASN1Decoder_Update (nssASN1Decoder *decoder, const void *data, PRUint32 amount)
NSS_IMPLEMENT PRStatus nssASN1Decoder_Finish (nssASN1Decoder *decoder)
NSS_IMPLEMENT PRStatus nssASN1Decoder_SetFilter (nssASN1Decoder *decoder, nssASN1DecoderFilterFunction *callback, void *argument, PRBool noStore)
NSS_IMPLEMENT PRStatus nssASN1Decoder_GetFilter (nssASN1Decoder *decoder, nssASN1DecoderFilterFunction **pCallbackOpt, void **pArgumentOpt, PRBool *pNoStoreOpt)
NSS_IMPLEMENT PRStatus nssASN1Decoder_SetNotify (nssASN1Decoder *decoder, nssASN1NotifyFunction *callback, void *argument)
NSS_IMPLEMENT PRStatus nssASN1Decoder_GetNotify (nssASN1Decoder *decoder, nssASN1NotifyFunction **pCallbackOpt, void **pArgumentOpt)
NSS_IMPLEMENT PRStatus nssASN1_Decode (NSSArena *arenaOpt, void *destination, const nssASN1Template template[], const void *berData, PRUint32 amount)
NSS_IMPLEMENT PRStatus nssASN1_DecodeBER (NSSArena *arenaOpt, void *destination, const nssASN1Template template[], const NSSBER *data)
NSS_IMPLEMENT nssASN1EncodernssASN1Encoder_Create (const void *source, const nssASN1Template template[], NSSASN1EncodingType encoding, nssASN1EncoderWriteFunction *sink, void *argument)
NSS_IMPLEMENT PRStatus nssASN1Encoder_Update (nssASN1Encoder *encoder, const void *data, PRUint32 length)
NSS_IMPLEMENT PRStatus nssASN1Encoder_Finish (nssASN1Encoder *encoder)
NSS_IMPLEMENT PRStatus nssASN1Encoder_SetNotify (nssASN1Encoder *encoder, nssASN1NotifyFunction *callback, void *argument)
NSS_IMPLEMENT PRStatus nssASN1Encoder_GetNotify (nssASN1Encoder *encoder, nssASN1NotifyFunction **pCallbackOpt, void **pArgumentOpt)
NSS_IMPLEMENT PRStatus nssASN1Encoder_SetStreaming (nssASN1Encoder *encoder, PRBool streaming)
NSS_EXTERN PRStatus nssASN1Encoder_GetStreaming (nssASN1Encoder *encoder, PRBool *pStreaming)
NSS_IMPLEMENT PRStatus nssASN1Encoder_SetTakeFromBuffer (nssASN1Encoder *encoder, PRBool takeFromBuffer)
NSS_IMPLEMENT PRStatus nssASN1Encoder_GetTakeFromBuffer (nssASN1Encoder *encoder, PRBool *pTakeFromBuffer)
NSS_IMPLEMENT PRStatus nssASN1_Encode (const void *source, const nssASN1Template template[], NSSASN1EncodingType encoding, nssASN1EncoderWriteFunction *sink, void *argument)
static void nssasn1_encode_item_count (void *arg, const char *buf, unsigned long len, int depth, nssASN1EncodingPart data_kind)
static void nssasn1_encode_item_store (void *arg, const char *buf, unsigned long len, int depth, nssASN1EncodingPart data_kind)
NSS_IMPLEMENT NSSDERnssASN1_EncodeItem (NSSArena *arenaOpt, NSSDER *rvOpt, const void *source, const nssASN1Template template[], NSSASN1EncodingType encoding)
NSS_IMPLEMENT PRStatus nssASN1_CreatePRUint32FromBER (NSSBER *encoded, PRUint32 *pResult)
NSS_EXTERN NSSDERnssASN1_GetDERFromPRUint32 (NSSArena *arenaOpt, NSSDER *rvOpt, PRUint32 value)
NSS_IMPLEMENT PRStatus nssASN1_CreatePRInt32FromBER (NSSBER *encoded, PRInt32 *pResult)
NSS_IMPLEMENT NSSDERnssASN1_GetDERFromPRInt32 (NSSArena *arenaOpt, NSSDER *rvOpt, PRInt32 value)
NSS_IMPLEMENT NSSUTF8nssUTF8_CreateFromBER (NSSArena *arenaOpt, nssStringType type, NSSBER *berData)
NSS_EXTERN NSSDERnssUTF8_GetDEREncoding (NSSArena *arenaOpt, nssStringType type, const NSSUTF8 *string)

Variables

const NSSError NSS_ERROR_INTERNAL_ERROR
const nssASN1TemplatenssASN1Template_Any = (nssASN1Template *)SEC_AnyTemplate
const nssASN1TemplatenssASN1Template_BitString = (nssASN1Template *)SEC_BitStringTemplate
const nssASN1TemplatenssASN1Template_BMPString = (nssASN1Template *)SEC_BMPStringTemplate
const nssASN1TemplatenssASN1Template_Boolean = (nssASN1Template *)SEC_BooleanTemplate
const nssASN1TemplatenssASN1Template_Enumerated = (nssASN1Template *)SEC_EnumeratedTemplate
const nssASN1TemplatenssASN1Template_GeneralizedTime = (nssASN1Template *)SEC_GeneralizedTimeTemplate
const nssASN1TemplatenssASN1Template_IA5String = (nssASN1Template *)SEC_IA5StringTemplate
const nssASN1TemplatenssASN1Template_Integer = (nssASN1Template *)SEC_IntegerTemplate
const nssASN1TemplatenssASN1Template_Null = (nssASN1Template *)SEC_NullTemplate
const nssASN1TemplatenssASN1Template_ObjectID = (nssASN1Template *)SEC_ObjectIDTemplate
const nssASN1TemplatenssASN1Template_OctetString = (nssASN1Template *)SEC_OctetStringTemplate
const nssASN1TemplatenssASN1Template_PrintableString = (nssASN1Template *)SEC_PrintableStringTemplate
const nssASN1TemplatenssASN1Template_T61String = (nssASN1Template *)SEC_T61StringTemplate
const nssASN1TemplatenssASN1Template_UniversalString = (nssASN1Template *)SEC_UniversalStringTemplate
const nssASN1TemplatenssASN1Template_UTCTime = (nssASN1Template *)SEC_UTCTimeTemplate
const nssASN1TemplatenssASN1Template_UTF8String = (nssASN1Template *)SEC_UTF8StringTemplate
const nssASN1TemplatenssASN1Template_VisibleString = (nssASN1Template *)SEC_VisibleStringTemplate
const nssASN1TemplatenssASN1Template_PointerToAny = (nssASN1Template *)SEC_PointerToAnyTemplate
const nssASN1TemplatenssASN1Template_PointerToBitString = (nssASN1Template *)SEC_PointerToBitStringTemplate
const nssASN1TemplatenssASN1Template_PointerToBMPString = (nssASN1Template *)SEC_PointerToBMPStringTemplate
const nssASN1TemplatenssASN1Template_PointerToBoolean = (nssASN1Template *)SEC_PointerToBooleanTemplate
const nssASN1TemplatenssASN1Template_PointerToEnumerated = (nssASN1Template *)SEC_PointerToEnumeratedTemplate
const nssASN1TemplatenssASN1Template_PointerToGeneralizedTime = (nssASN1Template *)SEC_PointerToGeneralizedTimeTemplate
const nssASN1TemplatenssASN1Template_PointerToIA5String = (nssASN1Template *)SEC_PointerToIA5StringTemplate
const nssASN1TemplatenssASN1Template_PointerToInteger = (nssASN1Template *)SEC_PointerToIntegerTemplate
const nssASN1TemplatenssASN1Template_PointerToNull = (nssASN1Template *)SEC_PointerToNullTemplate
const nssASN1TemplatenssASN1Template_PointerToObjectID = (nssASN1Template *)SEC_PointerToObjectIDTemplate
const nssASN1TemplatenssASN1Template_PointerToOctetString = (nssASN1Template *)SEC_PointerToOctetStringTemplate
const nssASN1TemplatenssASN1Template_PointerToPrintableString = (nssASN1Template *)SEC_PointerToPrintableStringTemplate
const nssASN1TemplatenssASN1Template_PointerToT61String = (nssASN1Template *)SEC_PointerToT61StringTemplate
const nssASN1TemplatenssASN1Template_PointerToUniversalString = (nssASN1Template *)SEC_PointerToUniversalStringTemplate
const nssASN1TemplatenssASN1Template_PointerToUTCTime = (nssASN1Template *)SEC_PointerToUTCTimeTemplate
const nssASN1TemplatenssASN1Template_PointerToUTF8String = (nssASN1Template *)SEC_PointerToUTF8StringTemplate
const nssASN1TemplatenssASN1Template_PointerToVisibleString = (nssASN1Template *)SEC_PointerToVisibleStringTemplate
const nssASN1TemplatenssASN1Template_SetOfAny = (nssASN1Template *)SEC_SetOfAnyTemplate
const nssASN1TemplatenssASN1Template_SetOfBitString = (nssASN1Template *)SEC_SetOfBitStringTemplate
const nssASN1TemplatenssASN1Template_SetOfBMPString = (nssASN1Template *)SEC_SetOfBMPStringTemplate
const nssASN1TemplatenssASN1Template_SetOfBoolean = (nssASN1Template *)SEC_SetOfBooleanTemplate
const nssASN1TemplatenssASN1Template_SetOfEnumerated = (nssASN1Template *)SEC_SetOfEnumeratedTemplate
const nssASN1TemplatenssASN1Template_SetOfGeneralizedTime = (nssASN1Template *)SEC_SetOfGeneralizedTimeTemplate
const nssASN1TemplatenssASN1Template_SetOfIA5String = (nssASN1Template *)SEC_SetOfIA5StringTemplate
const nssASN1TemplatenssASN1Template_SetOfInteger = (nssASN1Template *)SEC_SetOfIntegerTemplate
const nssASN1TemplatenssASN1Template_SetOfNull = (nssASN1Template *)SEC_SetOfNullTemplate
const nssASN1TemplatenssASN1Template_SetOfObjectID = (nssASN1Template *)SEC_SetOfObjectIDTemplate
const nssASN1TemplatenssASN1Template_SetOfOctetString = (nssASN1Template *)SEC_SetOfOctetStringTemplate
const nssASN1TemplatenssASN1Template_SetOfPrintableString = (nssASN1Template *)SEC_SetOfPrintableStringTemplate
const nssASN1TemplatenssASN1Template_SetOfT61String = (nssASN1Template *)SEC_SetOfT61StringTemplate
const nssASN1TemplatenssASN1Template_SetOfUniversalString = (nssASN1Template *)SEC_SetOfUniversalStringTemplate
const nssASN1TemplatenssASN1Template_SetOfUTCTime = (nssASN1Template *)SEC_SetOfUTCTimeTemplate
const nssASN1TemplatenssASN1Template_SetOfUTF8String = (nssASN1Template *)SEC_SetOfUTF8StringTemplate
const nssASN1TemplatenssASN1Template_SetOfVisibleString = (nssASN1Template *)SEC_SetOfVisibleStringTemplate

Function Documentation

Definition at line 1330 of file asn1.c.

Here is the call graph for this function:

Definition at line 1267 of file asn1.c.

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus nssASN1_Decode ( NSSArena *  arenaOpt,
void destination,
const nssASN1Template  template[],
const void berData,
PRUint32  amount 
)

Definition at line 612 of file asn1.c.

{
  PRStatus rv;
  nssASN1Decoder *decoder;

  /* This call will do our pointer-checking for us! */
  decoder = nssASN1Decoder_Create(arenaOpt, destination, template);
  if( (nssASN1Decoder *)NULL == decoder ) {
    return PR_FAILURE;
  }

  rv = nssASN1Decoder_Update(decoder, berData, amount);
  if( PR_SUCCESS != nssASN1Decoder_Finish(decoder) ) {
    rv = PR_FAILURE;
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT PRStatus nssASN1_DecodeBER ( NSSArena *  arenaOpt,
void destination,
const nssASN1Template  template[],
const NSSBER data 
)

Definition at line 659 of file asn1.c.

{
  return nssASN1_Decode(arenaOpt, destination, template, 
                        data->data, data->size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT PRStatus nssASN1_Encode ( const void source,
const nssASN1Template  template[],
NSSASN1EncodingType  encoding,
nssASN1EncoderWriteFunction sink,
void argument 
)

Definition at line 1091 of file asn1.c.

{
  PRStatus rv;
  nssASN1Encoder *encoder;

  encoder = nssASN1Encoder_Create(source, template, encoding, sink, argument);
  if( (nssASN1Encoder *)NULL == encoder ) {
    return PR_FAILURE;
  }

  rv = nssASN1Encoder_Update(encoder, (const void *)NULL, 0);
  if( PR_SUCCESS != nssASN1Encoder_Finish(encoder) ) {
    rv = PR_FAILURE;
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void nssasn1_encode_item_count ( void arg,
const char *  buf,
unsigned long  len,
int  depth,
nssASN1EncodingPart  data_kind 
) [static]

Definition at line 1124 of file asn1.c.

{
  unsigned long *count;

  count = (unsigned long*)arg;
  PR_ASSERT (count != NULL);

  *count += len;
}

Here is the caller graph for this function:

static void nssasn1_encode_item_store ( void arg,
const char *  buf,
unsigned long  len,
int  depth,
nssASN1EncodingPart  data_kind 
) [static]

Definition at line 1149 of file asn1.c.

{
  NSSItem *dest;

  dest = (NSSItem*)arg;
  PR_ASSERT (dest != NULL);

  memcpy((unsigned char *)dest->data + dest->size, buf, len);
  dest->size += len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT NSSDER* nssASN1_EncodeItem ( NSSArena *  arenaOpt,
NSSDER rvOpt,
const void source,
const nssASN1Template  template[],
NSSASN1EncodingType  encoding 
)

Definition at line 1187 of file asn1.c.

{
  NSSDER *rv;
  PRUint32 len = 0;
  PRStatus status;

#ifdef DEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSDER *)NULL;
    }
  }

  if( (void *)NULL == source ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSDER *)NULL;
  }

  if( (nssASN1Template *)NULL == template ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSDER *)NULL;
  }
#endif /* DEBUG */

  status = nssASN1_Encode(source, template, encoding, 
                          (nssASN1EncoderWriteFunction *)nssasn1_encode_item_count, 
                          &len);
  if( PR_SUCCESS != status ) {
    return (NSSDER *)NULL;
  }

  if( (NSSDER *)NULL == rvOpt ) {
    rv = nss_ZNEW(arenaOpt, NSSDER);
    if( (NSSDER *)NULL == rv ) {
      return (NSSDER *)NULL;
    }
  } else {
    rv = rvOpt;
  }

  rv->size = len;
  rv->data = nss_ZAlloc(arenaOpt, len);
  if( (void *)NULL == rv->data ) {
    if( (NSSDER *)NULL == rvOpt ) {
      nss_ZFreeIf(rv);
    }
    return (NSSDER *)NULL;
  }

  rv->size = 0; /* for nssasn1_encode_item_store */

  status = nssASN1_Encode(source, template, encoding,
                          (nssASN1EncoderWriteFunction *)nssasn1_encode_item_store, 
                          rv);
  if( PR_SUCCESS != status ) {
    nss_ZFreeIf(rv->data);
    if( (NSSDER *)NULL == rvOpt ) {
      nss_ZFreeIf(rv);
    }
    return (NSSDER *)NULL;
  }

  PR_ASSERT(rv->size == len);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT NSSDER* nssASN1_GetDERFromPRInt32 ( NSSArena *  arenaOpt,
NSSDER rvOpt,
PRInt32  value 
)

Definition at line 1346 of file asn1.c.

{
  NSSDER *rv;
  PLArenaPool *hack = (PLArenaPool *)arenaOpt;
  SECItem *item;

#ifdef DEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSDER *)NULL;
    }
  }
#endif /* DEBUG */

  if( (NSSDER *)NULL == rvOpt ) {
    rv = nss_ZNEW(arenaOpt, NSSDER);
    if( (NSSDER *)NULL == rv ) {
      return (NSSDER *)NULL;
    }
  } else {
    rv = rvOpt;
  }

  item = SEC_ASN1EncodeInteger(hack, (SECItem *)rv, value);
  if( (SECItem *)NULL == item ) {
    if( (NSSDER *)NULL == rvOpt ) {
      (void)nss_ZFreeIf(rv);
    }

    nss_SetError(PORT_GetError()); /* ugly */
    return (NSSDER *)NULL;
  }

  /* 
   * I happen to know that these things look alike.. but I'm only
   * doing it for these "temporary" wrappers.  This is an evil thing.
   */
  return (NSSDER *)item;
}

Here is the call graph for this function:

NSS_EXTERN NSSDER* nssASN1_GetDERFromPRUint32 ( NSSArena *  arenaOpt,
NSSDER rvOpt,
PRUint32  value 
)

Definition at line 1283 of file asn1.c.

{
  NSSDER *rv;
  PLArenaPool *hack = (PLArenaPool *)arenaOpt;
  SECItem *item;

#ifdef DEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSDER *)NULL;
    }
  }
#endif /* DEBUG */

  if( (NSSDER *)NULL == rvOpt ) {
    rv = nss_ZNEW(arenaOpt, NSSDER);
    if( (NSSDER *)NULL == rv ) {
      return (NSSDER *)NULL;
    }
  } else {
    rv = rvOpt;
  }

  item = SEC_ASN1EncodeUnsignedInteger(hack, (SECItem *)rv, value);
  if( (SECItem *)NULL == item ) {
    if( (NSSDER *)NULL == rvOpt ) {
      (void)nss_ZFreeIf(rv);
    }

    nss_SetError(PORT_GetError()); /* ugly */
    return (NSSDER *)NULL;
  }

  /* 
   * I happen to know that these things look alike.. but I'm only
   * doing it for these "temporary" wrappers.  This is an evil thing.
   */
  return (NSSDER *)item;
}

Here is the call graph for this function:

NSS_IMPLEMENT nssASN1Decoder* nssASN1Decoder_Create ( NSSArena *  arenaOpt,
void destination,
const nssASN1Template  template[] 
)

Definition at line 253 of file asn1.c.

{
  SEC_ASN1DecoderContext *rv;
  PLArenaPool *hack = (PLArenaPool *)arenaOpt;

#ifdef DEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (nssASN1Decoder *)NULL;
    }
  }

  /* 
   * May destination be NULL?  I'd think so, since one might
   * have only a filter proc.  But if not, check the pointer here.
   */

  if( (nssASN1Template *)NULL == template ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (nssASN1Decoder *)NULL;
  }
#endif /* DEBUG */

  rv = SEC_ASN1DecoderStart(hack, destination, template);
  if( (SEC_ASN1DecoderContext *)NULL == rv ) {
    nss_SetError(PORT_GetError()); /* also evil */
    return (nssASN1Decoder *)NULL;
  }

#ifdef DEBUG
  if( PR_SUCCESS != decoder_add_pointer(rv) ) {
    (void)SEC_ASN1DecoderFinish(rv);
    return (nssASN1Decoder *)NULL;
  }
#endif /* DEBUG */

  return (nssASN1Decoder *)rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 363 of file asn1.c.

{
  PRStatus rv = PR_SUCCESS;
  SECStatus srv;

#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Decoder_verify(decoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  srv = SEC_ASN1DecoderFinish((SEC_ASN1DecoderContext *)decoder);

  if( SECSuccess != srv ) {
    nss_SetError(PORT_GetError()); /* ugly */
    rv = PR_FAILURE;
  }

#ifdef DEBUG
  {
    PRStatus rv2 = decoder_remove_pointer(decoder);
    if( PR_SUCCESS == rv ) {
      rv = rv2;
    }
  }
#endif /* DEBUG */

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT PRStatus nssASN1Decoder_GetFilter ( nssASN1Decoder decoder,
nssASN1DecoderFilterFunction **  pCallbackOpt,
void **  pArgumentOpt,
PRBool pNoStoreOpt 
)

Definition at line 470 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Decoder_verify(decoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (nssASN1DecoderFilterFunction **)NULL != pCallbackOpt ) {
    *pCallbackOpt = (nssASN1DecoderFilterFunction *)NULL;
  }

  if( (void **)NULL != pArgumentOpt ) {
    *pArgumentOpt = (void *)NULL;
  }

  if( (PRBool *)NULL != pNoStoreOpt ) {
    *pNoStoreOpt = PR_FALSE;
  }

  /* Error because it's unimplemented */
  nss_SetError(NSS_ERROR_INTERNAL_ERROR);
  return PR_FAILURE;
}

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus nssASN1Decoder_GetNotify ( nssASN1Decoder decoder,
nssASN1NotifyFunction **  pCallbackOpt,
void **  pArgumentOpt 
)

Definition at line 566 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Decoder_verify(decoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (nssASN1NotifyFunction **)NULL != pCallbackOpt ) {
    *pCallbackOpt = (nssASN1NotifyFunction *)NULL;
  }

  if( (void **)NULL != pArgumentOpt ) {
    *pArgumentOpt = (void *)NULL;
  }

  /* Error because it's unimplemented */
  nss_SetError(NSS_ERROR_INTERNAL_ERROR);
  return PR_FAILURE;
}

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus nssASN1Decoder_SetFilter ( nssASN1Decoder decoder,
nssASN1DecoderFilterFunction callback,
void argument,
PRBool  noStore 
)

Definition at line 418 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Decoder_verify(decoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (nssASN1DecoderFilterFunction *)NULL == callback ) {
     SEC_ASN1DecoderClearFilterProc((SEC_ASN1DecoderContext *)decoder);
  } else {
     SEC_ASN1DecoderSetFilterProc((SEC_ASN1DecoderContext *)decoder,
                                  (SEC_ASN1WriteProc)callback,
                                  argument, noStore);
  }

  /* No error returns defined for those routines */

  return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 520 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Decoder_verify(decoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (nssASN1NotifyFunction *)NULL == callback ) {
    SEC_ASN1DecoderClearNotifyProc((SEC_ASN1DecoderContext *)decoder);
  } else {
    SEC_ASN1DecoderSetNotifyProc((SEC_ASN1DecoderContext *)decoder,
                                 (SEC_ASN1NotifyProc)callback,
                                 argument);
  }

  /* No error returns defined for those routines */

  return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 316 of file asn1.c.

{
  SECStatus rv;

#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Decoder_verify(decoder) ) {
    return PR_FAILURE;
  }

  if( (void *)NULL == data ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return PR_FAILURE;
  }
#endif /* DEBUG */

  rv = SEC_ASN1DecoderUpdate((SEC_ASN1DecoderContext *)decoder, 
                             (const char *)data,
                             (unsigned long)amount);
  if( SECSuccess != rv ) {
    nss_SetError(PORT_GetError()); /* ugly */
    return PR_FAILURE;
  }

  return PR_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 690 of file asn1.c.

{
  SEC_ASN1EncoderContext *rv;

#ifdef DEBUG
  if( (void *)NULL == source ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (nssASN1Encoder *)NULL;
  }

  if( (nssASN1Template *)NULL == template ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (nssASN1Encoder *)NULL;
  }

  if( (nssASN1EncoderWriteFunction *)NULL == sink ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (nssASN1Encoder *)NULL;
  }
#endif /* DEBUG */

  switch( encoding ) {
  case NSSASN1BER:
  case NSSASN1DER:
    break;
  case NSSASN1CER:
  case NSSASN1LWER:
  case NSSASN1PER:
  case NSSASN1UnknownEncoding:
  default:
    nss_SetError(NSS_ERROR_ENCODING_NOT_SUPPORTED);
    return (nssASN1Encoder *)NULL;
  }

  rv = SEC_ASN1EncoderStart((void *)source, template, 
                            (SEC_ASN1WriteProc)sink, argument);
  if( (SEC_ASN1EncoderContext *)NULL == rv ) {
    nss_SetError(PORT_GetError()); /* ugly */
    return (nssASN1Encoder *)NULL;
  }

  if( NSSASN1DER == encoding ) {
    sec_ASN1EncoderSetDER(rv);
  }

#ifdef DEBUG
  if( PR_SUCCESS != encoder_add_pointer(rv) ) {
    (void)SEC_ASN1EncoderFinish(rv);
    return (nssASN1Encoder *)NULL;
  }
#endif /* DEBUG */

  return (nssASN1Encoder *)rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 809 of file asn1.c.

{
  PRStatus rv;

#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  SEC_ASN1EncoderFinish((SEC_ASN1EncoderContext *)encoder);
  rv = PR_SUCCESS; /* no error return defined for that call */

#ifdef DEBUG
  {
    PRStatus rv2 = encoder_remove_pointer(encoder);
    if( PR_SUCCESS == rv ) {
      rv = rv2;
    }
  }
#endif /* DEBUG */

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT PRStatus nssASN1Encoder_GetNotify ( nssASN1Encoder encoder,
nssASN1NotifyFunction **  pCallbackOpt,
void **  pArgumentOpt 
)

Definition at line 902 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (nssASN1NotifyFunction **)NULL != pCallbackOpt ) {
    *pCallbackOpt = (nssASN1NotifyFunction *)NULL;
  }

  if( (void **)NULL != pArgumentOpt ) {
    *pArgumentOpt = (void *)NULL;
  }

  /* Error because it's unimplemented */
  nss_SetError(NSS_ERROR_INTERNAL_ERROR);
  return PR_FAILURE;
}

Here is the call graph for this function:

Definition at line 980 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (PRBool *)NULL != pStreaming ) {
    *pStreaming = PR_FALSE;
  }

  /* Error because it's unimplemented */
  nss_SetError(NSS_ERROR_INTERNAL_ERROR);
  return PR_FAILURE;
}

Here is the call graph for this function:

Definition at line 1053 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (PRBool *)NULL != pTakeFromBuffer ) {
    *pTakeFromBuffer = PR_FALSE;
  }

  /* Error because it's unimplemented */
  nss_SetError(NSS_ERROR_INTERNAL_ERROR);
  return PR_FAILURE;
}

Here is the call graph for this function:

Definition at line 856 of file asn1.c.

{
#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( (nssASN1NotifyFunction *)NULL == callback ) {
    SEC_ASN1EncoderClearNotifyProc((SEC_ASN1EncoderContext *)encoder);
  } else {
    SEC_ASN1EncoderSetNotifyProc((SEC_ASN1EncoderContext *)encoder,
                                 (SEC_ASN1NotifyProc)callback,
                                 argument);
  }

  /* no error return defined for those routines */

  return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 941 of file asn1.c.

{
  SEC_ASN1EncoderContext *cx = (SEC_ASN1EncoderContext *)encoder;

#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( streaming ) {
    SEC_ASN1EncoderSetStreaming(cx);
  } else {
    SEC_ASN1EncoderClearStreaming(cx);
  }

  /* no error return defined for those routines */

  return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 1014 of file asn1.c.

{
  SEC_ASN1EncoderContext *cx = (SEC_ASN1EncoderContext *)encoder;

#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( takeFromBuffer ) {
    SEC_ASN1EncoderSetTakeFromBuf(cx);
  } else {
    SEC_ASN1EncoderClearTakeFromBuf(cx);
  }

  /* no error return defined for those routines */

  return PR_SUCCESS;
}

Here is the call graph for this function:

Definition at line 765 of file asn1.c.

{
  SECStatus rv;

#ifdef DEBUG
  if( PR_SUCCESS != nssASN1Encoder_verify(encoder) ) {
    return PR_FAILURE;
  }

  /*
   * Can data legitimately be NULL?  If not, verify..
   */
#endif /* DEBUG */

  rv = SEC_ASN1EncoderUpdate((SEC_ASN1EncoderContext *)encoder,
                             (const char *)data, 
                             (unsigned long)length);
  if( SECSuccess != rv ) {
    nss_SetError(PORT_GetError()); /* ugly */
    return PR_FAILURE;
  }

  return PR_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT NSSUTF8* nssUTF8_CreateFromBER ( NSSArena *  arenaOpt,
nssStringType  type,
NSSBER berData 
)

Definition at line 1460 of file asn1.c.

{
  NSSUTF8 *rv = NULL;
  PRUint8 tag;
  NSSArena *a;
  NSSItem in;
  NSSItem out;
  PRStatus st;
  const nssASN1Template *templ;

#ifdef NSSDEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSUTF8 *)NULL;
    }
  }

  if( (NSSBER *)NULL == berData ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSUTF8 *)NULL;
  }

  if( (void *)NULL == berData->data ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSUTF8 *)NULL;
  }
#endif /* NSSDEBUG */

  a = NSSArena_Create();
  if( (NSSArena *)NULL == a ) {
    return (NSSUTF8 *)NULL;
  }

  in = *berData;

  /*
   * By the way, at first I succumbed to the temptation to make
   * this an incestuous nested switch statement.  Count yourself
   * lucky I cleaned it up.
   */

  switch( type ) {
  case nssStringType_DirectoryString:
    /*
     * draft-ietf-pkix-ipki-part1-11 says in part:
     *
     * DirectoryString { INTEGER:maxSize } ::= CHOICE {
     *   teletexString           TeletexString (SIZE (1..maxSize)),
     *   printableString         PrintableString (SIZE (1..maxSize)),
     *   universalString         UniversalString (SIZE (1..maxSize)),
     *   bmpString               BMPString (SIZE(1..maxSize)),
     *   utf8String              UTF8String (SIZE(1..maxSize))
     *                       }
     *
     * The tags are:
     *  TeletexString       UNIVERSAL 20
     *  PrintableString     UNIVERSAL 19
     *  UniversalString     UNIVERSAL 28
     *  BMPString           UNIVERSAL 30
     *  UTF8String          UNIVERSAL 12
     *
     * "UNIVERSAL" tags have bits 8 and 7 zero, bit 6 is zero for
     * primitive encodings, and if the tag value is less than 30,
     * the tag value is directly encoded in bits 5 through 1.
     */
    in.data = (void *)&(((PRUint8 *)berData->data)[1]);
    in.size = berData->size-1;
    
    tag = *(PRUint8 *)berData->data;
    switch( tag & nssASN1_TAGNUM_MASK ) {
    case 20:
      /*
       * XXX fgmr-- we have to accept Latin-1 for Teletex; (see
       * below) but is T61 a suitable value for "Latin-1"?
       */
      templ = nssASN1Template_T61String;
      type = nssStringType_TeletexString;
      break;
    case 19:
      templ = nssASN1Template_PrintableString;
      type = nssStringType_PrintableString;
      break;
    case 28:
      templ = nssASN1Template_UniversalString;
      type = nssStringType_UniversalString;
      break;
    case 30:
      templ = nssASN1Template_BMPString;
      type = nssStringType_BMPString;
      break;
    case 12:
      templ = nssASN1Template_UTF8String;
      type = nssStringType_UTF8String;
      break;
    default:
      nss_SetError(NSS_ERROR_INVALID_POINTER); /* "pointer"? */
      (void)NSSArena_Destroy(a);
      return (NSSUTF8 *)NULL;
    }

    break;

  case nssStringType_TeletexString:
    /*
     * XXX fgmr-- we have to accept Latin-1 for Teletex; (see
     * below) but is T61 a suitable value for "Latin-1"?
     */
    templ = nssASN1Template_T61String;
    break;
   
  case nssStringType_PrintableString:
    templ = nssASN1Template_PrintableString;
    break;

  case nssStringType_UniversalString:
    templ = nssASN1Template_UniversalString;
    break;

  case nssStringType_BMPString:
    templ = nssASN1Template_BMPString;
    break;

  case nssStringType_UTF8String:
    templ = nssASN1Template_UTF8String;
    break;

  case nssStringType_PHGString:
    templ = nssASN1Template_IA5String;
    break;

  default:
    nss_SetError(NSS_ERROR_UNSUPPORTED_TYPE);
    (void)NSSArena_Destroy(a);
    return (NSSUTF8 *)NULL;
  }
    
  st = nssASN1_DecodeBER(a, &out, templ, &in);
  
  if( PR_SUCCESS == st ) {
    rv = nssUTF8_Create(arenaOpt, type, out.data, out.size);
  }
  (void)NSSArena_Destroy(a);
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_EXTERN NSSDER* nssUTF8_GetDEREncoding ( NSSArena *  arenaOpt,
nssStringType  type,
const NSSUTF8 string 
)

Definition at line 1612 of file asn1.c.

{
  NSSDER *rv = (NSSDER *)NULL;
  NSSItem str;
  NSSDER *der;
  const nssASN1Template *templ;
  NSSArena *a;

#ifdef NSSDEBUG
  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSDER *)NULL;
    }
  }

  if( (const NSSUTF8 *)NULL == string ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSDER *)NULL;
  }
#endif /* NSSDEBUG */

  str.data = (void *)string;
  str.size = nssUTF8_Size(string, (PRStatus *)NULL);
  if( 0 == str.size ) {
    return (NSSDER *)NULL;
  }

  a = NSSArena_Create();
  if( (NSSArena *)NULL == a ) {
    return (NSSDER *)NULL;
  }

  switch( type ) {
  case nssStringType_DirectoryString:
    {
      NSSDER *utf;
      PRUint8 *c;

      utf = nssASN1_EncodeItem(a, (NSSDER *)NULL, &str, 
                               nssASN1Template_UTF8String,
                               NSSASN1DER);
      if( (NSSDER *)NULL == utf ) {
        (void)NSSArena_Destroy(a);
        return (NSSDER *)NULL;
      }

      rv = nss_ZNEW(arenaOpt, NSSDER);
      if( (NSSDER *)NULL == rv ) {
        (void)NSSArena_Destroy(a);
        return (NSSDER *)NULL;
      }

      rv->size = utf->size + 1;
      rv->data = nss_ZAlloc(arenaOpt, rv->size);
      if( (void *)NULL == rv->data ) {
        (void)nss_ZFreeIf(rv);
        (void)NSSArena_Destroy(a);
        return (NSSDER *)NULL;
      }
      
      c = (PRUint8 *)rv->data;
      (void)nsslibc_memcpy(&c[1], utf->data, utf->size);
      *c = 12; /* UNIVERSAL primitive encoding tag for UTF8String */

      (void)NSSArena_Destroy(a);
      return rv;
    }
  case nssStringType_TeletexString:
    /*
     * XXX fgmr-- we have to accept Latin-1 for Teletex; (see
     * below) but is T61 a suitable value for "Latin-1"?
     */
    templ = nssASN1Template_T61String;
    break;
  case nssStringType_PrintableString:
    templ = nssASN1Template_PrintableString;
    break;

  case nssStringType_UniversalString:
    templ = nssASN1Template_UniversalString;
    break;

  case nssStringType_BMPString:
    templ = nssASN1Template_BMPString;
    break;

  case nssStringType_UTF8String:
    templ = nssASN1Template_UTF8String;
    break;

  case nssStringType_PHGString:
    templ = nssASN1Template_IA5String;
    break;

  default:
    nss_SetError(NSS_ERROR_UNSUPPORTED_TYPE);
    (void)NSSArena_Destroy(a);
    return (NSSDER *)NULL;
  }

  der = nssUTF8_GetDEREncoding(a, type, string);
  if( (NSSItem *)NULL == der ) {
    (void)NSSArena_Destroy(a);
    return (NSSDER *)NULL;
  }

  rv = nssASN1_EncodeItem(arenaOpt, (NSSDER *)NULL, der, templ, NSSASN1DER);
  if( (NSSDER *)NULL == rv ) {
    (void)NSSArena_Destroy(a);
    return (NSSDER *)NULL;
  }

  (void)NSSArena_Destroy(a);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 52 of file errorval.c.

Definition at line 1400 of file asn1.c.

Definition at line 1401 of file asn1.c.

Definition at line 1402 of file asn1.c.

Definition at line 1403 of file asn1.c.

Definition at line 1404 of file asn1.c.

Definition at line 1405 of file asn1.c.

Definition at line 1406 of file asn1.c.

Definition at line 1407 of file asn1.c.

Definition at line 1408 of file asn1.c.

Definition at line 1409 of file asn1.c.

Definition at line 1410 of file asn1.c.

Definition at line 1418 of file asn1.c.

Definition at line 1419 of file asn1.c.

Definition at line 1420 of file asn1.c.

Definition at line 1421 of file asn1.c.

Definition at line 1422 of file asn1.c.

Definition at line 1423 of file asn1.c.

Definition at line 1424 of file asn1.c.

Definition at line 1425 of file asn1.c.

Definition at line 1426 of file asn1.c.

Definition at line 1427 of file asn1.c.

Definition at line 1428 of file asn1.c.

Definition at line 1429 of file asn1.c.

Definition at line 1430 of file asn1.c.

Definition at line 1431 of file asn1.c.

Definition at line 1432 of file asn1.c.

Definition at line 1433 of file asn1.c.

Definition at line 1434 of file asn1.c.

Definition at line 1411 of file asn1.c.

Definition at line 1436 of file asn1.c.

Definition at line 1437 of file asn1.c.

Definition at line 1438 of file asn1.c.

Definition at line 1439 of file asn1.c.

Definition at line 1440 of file asn1.c.

Definition at line 1441 of file asn1.c.

Definition at line 1442 of file asn1.c.

Definition at line 1443 of file asn1.c.

Definition at line 1444 of file asn1.c.

Definition at line 1445 of file asn1.c.

Definition at line 1446 of file asn1.c.

Definition at line 1447 of file asn1.c.

Definition at line 1448 of file asn1.c.

Definition at line 1449 of file asn1.c.

Definition at line 1450 of file asn1.c.

Definition at line 1451 of file asn1.c.

Definition at line 1452 of file asn1.c.

Definition at line 1412 of file asn1.c.

Definition at line 1413 of file asn1.c.

Definition at line 1414 of file asn1.c.

Definition at line 1415 of file asn1.c.

Definition at line 1416 of file asn1.c.