Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
atav.c File Reference
#include "nssbase.h"
#include "asn1.h"
#include "pki1.h"

Go to the source code of this file.

Classes

struct  NSSATAVStr
struct  atav_holder
struct  nss_attribute_data_str

Functions

NSS_IMPLEMENT NSSATAV * NSSATAV_CreateFromBER (NSSArena *arenaOpt, NSSBER *berATAV)
NSS_IMPLEMENT NSSATAV * NSSATAV_CreateFromUTF8 (NSSArena *arenaOpt, NSSUTF8 *stringATAV)
NSS_IMPLEMENT NSSATAV * NSSATAV_Create (NSSArena *arenaOpt, const NSSOID *oid, const void *data, PRUint32 length)
NSS_IMPLEMENT PRStatus NSSATAV_Destroy (NSSATAV *atav)
NSS_IMPLEMENT NSSDERNSSATAV_GetDEREncoding (NSSATAV *atav, NSSArena *arenaOpt)
NSS_IMPLEMENT NSSUTF8NSSATAV_GetUTF8Encoding (NSSATAV *atav, NSSArena *arenaOpt)
NSS_IMPLEMENT const NSSOID * NSSATAV_GetType (NSSATAV *atav)
NSS_IMPLEMENT NSSUTF8NSSATAV_GetValue (NSSATAV *atav, NSSArena *arenaOpt)
NSS_IMPLEMENT PRStatus NSSATAV_Compare (NSSATAV *atav1, NSSATAV *atav2, PRBool *equalp)
NSS_IMPLEMENT NSSATAV * NSSATAV_Duplicate (NSSATAV *atav, NSSArena *arenaOpt)
static nssStringType nss_attr_underlying_string_form (nssStringType type, void *data)
static NSSUTF8nss_attr_to_utf8 (NSSArena *arenaOpt, const NSSOID *oid, NSSItem *item, nssStringType *stringForm)
NSS_IMPLEMENT NSSATAV * nssATAV_CreateFromBER (NSSArena *arenaOpt, const NSSBER *berATAV)
static PRBool nss_atav_utf8_string_is_hex (const NSSUTF8 *s)
static NSSUTF8 nss_atav_fromhex (NSSUTF8 *d)
NSS_IMPLEMENT NSSATAV * nssATAV_CreateFromUTF8 (NSSArena *arenaOpt, const NSSUTF8 *stringATAV)
NSS_IMPLEMENT NSSATAV * nssATAV_Create (NSSArena *arenaOpt, const NSSOID *oid, const void *data, PRUint32 length)
NSS_IMPLEMENT PRStatus nssATAV_Destroy (NSSATAV *atav)
NSS_IMPLEMENT NSSDERnssATAV_GetDEREncoding (NSSATAV *atav, NSSArena *arenaOpt)
NSS_IMPLEMENT NSSUTF8nssATAV_GetUTF8Encoding (NSSATAV *atav, NSSArena *arenaOpt)
NSS_IMPLEMENT const NSSOID * nssATAV_GetType (NSSATAV *atav)
NSS_IMPLEMENT NSSUTF8nssATAV_GetValue (NSSATAV *atav, NSSArena *arenaOpt)
NSS_IMPLEMENT PRStatus nssATAV_Compare (NSSATAV *atav1, NSSATAV *atav2, PRBool *equalp)
NSS_IMPLEMENT NSSATAV * nssATAV_Duplicate (NSSATAV *atav, NSSArena *arenaOpt)

Variables

static const nssASN1Template nss_atav_template []
static struct nss_attribute_data_str []
PRUint32 nss_attribute_data_quantity
const NSSError NSS_ERROR_INTERNAL_ERROR

Class Documentation

struct NSSATAVStr

Definition at line 87 of file atav.c.

Class Members
NSSBER ber
const NSSOID * oid
nssStringType stringForm
NSSUTF8 * value
struct atav_holder

Definition at line 663 of file atav.c.

Class Members
NSSBER oid
NSSBER value
struct nss_attribute_data_str

Definition at line 680 of file atav.c.

Class Members
PRUint32 maxStringLength
PRUint32 minStringLength
const NSSOID ** oid
nssStringType stringType

Function Documentation

static NSSUTF8 nss_atav_fromhex ( NSSUTF8 d) [static]

Definition at line 969 of file atav.c.

{
  NSSUTF8 rv;

  if( d[0] <= '9' ) {
    rv = (d[0] - '0') * 16;
  } else if( d[0] >= 'a' ) {
    rv = (d[0] - 'a' + 10) * 16;
  } else {
    rv = (d[0] - 'A' + 10);
  }

  if( d[1] <= '9' ) {
    rv += (d[1] - '0');
  } else if( d[1] >= 'a' ) {
    rv += (d[1] - 'a' + 10);
  } else {
    rv += (d[1] - 'A' + 10);
  }

  return rv;
}

Here is the caller graph for this function:

static PRBool nss_atav_utf8_string_is_hex ( const NSSUTF8 s) [static]

Definition at line 947 of file atav.c.

{
  /* All hex digits are ASCII, so this works */
  PRUint8 *p = (PRUint8 *)s;

  for( ; (PRUint8)0 != *p; p++ ) {
    if( (('0' <= *p) && (*p <= '9')) ||
        (('A' <= *p) && (*p <= 'F')) ||
        (('a' <= *p) && (*p <= 'f')) ) {
      continue;
    } else {
      return PR_FALSE;
    }
  }

  return PR_TRUE;
}

Here is the caller graph for this function:

static NSSUTF8* nss_attr_to_utf8 ( NSSArena *  arenaOpt,
const NSSOID *  oid,
NSSItem *  item,
nssStringType *  stringForm 
) [static]

Definition at line 767 of file atav.c.

{
  NSSUTF8 *rv = (NSSUTF8 *)NULL;
  PRUint32 i;
  const struct nss_attribute_data_str *which = 
    (struct nss_attribute_data_str *)NULL;
  PRUint32 len = 0;

  for( i = 0; i < nss_attribute_data_quantity; i++ ) {
    if( *(nss_attribute_data[ i ].oid) == oid ) {
      which = &nss_attribute_data[i];
      break;
    }
  }

  if( (struct nss_attribute_data_str *)NULL == which ) {
    /* Unknown OID.  Encode it as hex. */
    PRUint8 *c;
    PRUint8 *d = (PRUint8 *)item->data;
    PRUint32 amt = item->size;

    if( item->size >= 0x7FFFFFFF ) {
      nss_SetError(NSS_ERROR_INVALID_STRING);
      return (NSSUTF8 *)NULL;
    }

    len = 1 + (item->size * 2) + 1; /* '#' + hex + '\0' */
    rv = (NSSUTF8 *)nss_ZAlloc(arenaOpt, len);
    if( (NSSUTF8 *)NULL == rv ) {
      return (NSSUTF8 *)NULL;
    }

    c = (PRUint8 *)rv;
    *c++ = '#'; /* XXX fgmr check this */
    while( amt > 0 ) {
      static char hex[16] = "0123456789ABCDEF";
      *c++ = hex[ ((*d) & 0xf0) >> 4 ];
      *c++ = hex[ ((*d) & 0x0f)      ];
    }

    /* *c = '\0'; nss_ZAlloc, remember */

    *stringForm = nssStringType_Unknown; /* force exact comparison */
  } else {
    PRStatus status;
    rv = nssUTF8_CreateFromBER(arenaOpt, which->stringType, 
                               (NSSBER *)item);

    if( (NSSUTF8 *)NULL == rv ) {
      return (NSSUTF8 *)NULL;
    }

    len = nssUTF8_Length(rv, &status);
    if( PR_SUCCESS != status || len == 0 ) {
      nss_ZFreeIf(rv);
      return (NSSUTF8 *)NULL;
    }

    *stringForm = nss_attr_underlying_string_form(which->stringType,
                                                  item->data);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nssStringType nss_attr_underlying_string_form ( nssStringType  type,
void data 
) [static]

Definition at line 729 of file atav.c.

{
  if( nssStringType_DirectoryString == type ) {
    PRUint8 tag = *(PRUint8 *)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"?
       */
      return nssStringType_TeletexString;
    case 19:
      return nssStringType_PrintableString;
    case 28:
      return nssStringType_UniversalString;
    case 30:
      return nssStringType_BMPString;
    case 12:
      return nssStringType_UTF8String;
    default:
      return nssStringType_Unknown;
    }
  }

  return type;
}

Here is the caller graph for this function:

NSS_IMPLEMENT PRStatus NSSATAV_Compare ( NSSATAV *  atav1,
NSSATAV *  atav2,
PRBool equalp 
)

Definition at line 503 of file atav.c.

{
  nss_ClearErrorStack();

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav1) ) {
    return PR_FAILURE;
  }

  if( PR_SUCCESS != nssATAV_verifyPointer(atav2) ) {
    return PR_FAILURE;
  }

  if( (PRBool *)NULL == equalp ) {
    nss_SetError(NSS_ERROR_INVALID_ARGUMENT);
    return PR_FAILURE;
  }
#endif /* DEBUG */

  return nssATAV_Compare(atav1, atav2, equalp);
}

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus nssATAV_Compare ( NSSATAV *  atav1,
NSSATAV *  atav2,
PRBool equalp 
)

Definition at line 1662 of file atav.c.

{
  nssStringType comparison;
  PRUint32 len1;
  PRUint32 len2;
  PRStatus status;

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav1) ) {
    return PR_FAILURE;
  }

  if( PR_SUCCESS != nssATAV_verifyPointer(atav2) ) {
    return PR_FAILURE;
  }

  if( (PRBool *)NULL == equalp ) {
    nss_SetError(NSS_ERROR_INVALID_ARGUMENT);
    return PR_FAILURE;
  }
#endif /* DEBUG */

  if( atav1->oid != atav2->oid ) {
    *equalp = PR_FALSE;
    return PR_SUCCESS;
  }

  if( atav1->stringForm != atav2->stringForm ) {
    if( (nssStringType_PrintableString == atav1->stringForm) ||
        (nssStringType_PrintableString == atav2->stringForm) ) {
      comparison = nssStringType_PrintableString;
    } else if( (nssStringType_PHGString == atav1->stringForm) ||
               (nssStringType_PHGString == atav2->stringForm) ) {
      comparison = nssStringType_PHGString;
    } else {
      comparison = atav1->stringForm;
    }
  } else {
    comparison = atav1->stringForm;
  }

  switch( comparison ) {
  case nssStringType_DirectoryString:
    nss_SetError(NSS_ERROR_INTERNAL_ERROR);
    return PR_FAILURE;
  case nssStringType_TeletexString:
    break;
  case nssStringType_PrintableString:
    *equalp = nssUTF8_PrintableMatch(atav1->value, atav2->value, &status);
    return status;
    /* Case-insensitive, with whitespace reduction */
    break;
  case nssStringType_UniversalString:
    break;
  case nssStringType_BMPString:
    break;
  case nssStringType_GeneralString:
    /* what to do here? */
    break;
  case nssStringType_UTF8String:
    break;
  case nssStringType_PHGString:
    /* Case-insensitive (XXX fgmr, actually see draft-11 pg. 21) */
    *equalp = nssUTF8_CaseIgnoreMatch(atav1->value, atav2->value, &status);
    return status;
  case nssStringType_Unknown:
    break;
  }
  
  len1 = nssUTF8_Size(atav1->value, &status);
  if( PR_SUCCESS != status ) {
    return PR_FAILURE;
  }

  len2 = nssUTF8_Size(atav2->value, &status);
  if( PR_SUCCESS != status ) {
    return PR_FAILURE;
  }

  if( len1 != len2 ) {
    *equalp = PR_FALSE;
    return PR_SUCCESS;
  }

  *equalp = nsslibc_memequal(atav1->value, atav2->value, len1, &status);
  return status;
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* NSSATAV_Create ( NSSArena *  arenaOpt,
const NSSOID *  oid,
const void data,
PRUint32  length 
)

Definition at line 257 of file atav.c.

{
  nss_ClearErrorStack();

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

  if( PR_SUCCESS != nssOID_verifyPointer(oid) ) {
    return (NSSATAV *)NULL;
  }

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

  return nssATAV_Create(arenaOpt, oid, data, length);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* nssATAV_Create ( NSSArena *  arenaOpt,
const NSSOID *  oid,
const void data,
PRUint32  length 
)

Definition at line 1333 of file atav.c.

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

  if( PR_SUCCESS != nssOID_verifyPointer(oid) ) {
    return (NSSATAV *)NULL;
  }

  if( (const void *)NULL == data ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (NSSATAV *)NULL;
  }
#endif /* NSSDEBUG */

  /* XXX fgmr-- oops, forgot this one */
  return (NSSATAV *)NULL;
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* NSSATAV_CreateFromBER ( NSSArena *  arenaOpt,
NSSBER berATAV 
)

Definition at line 150 of file atav.c.

{
  nss_ClearErrorStack();

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

  /* 
   * NSSBERs can be created by the user, 
   * so no pointer-tracking can be checked.
   */

  if( (NSSBER *)NULL == berATAV ) {
    nss_SetError(NSS_ERROR_INVALID_BER);
    return (NSSATAV *)NULL;
  }

  if( (void *)NULL == berATAV->data ) {
    nss_SetError(NSS_ERROR_INVALID_BER);
    return (NSSATAV *)NULL;
  }
#endif /* DEBUG */

  return nssATAV_CreateFromBER(arenaOpt, berATAV);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* nssATAV_CreateFromBER ( NSSArena *  arenaOpt,
const NSSBER berATAV 
)

Definition at line 857 of file atav.c.

{
  atav_holder holder;
  PRStatus status;
  NSSATAV *rv;

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

  /* 
   * NSSBERs can be created by the user, 
   * so no pointer-tracking can be checked.
   */

  if( (NSSBER *)NULL == berATAV ) {
    nss_SetError(NSS_ERROR_INVALID_BER);
    return (NSSATAV *)NULL;
  }

  if( (void *)NULL == berATAV->data ) {
    nss_SetError(NSS_ERROR_INVALID_BER);
    return (NSSATAV *)NULL;
  }
#endif /* NSSDEBUG */

  status = nssASN1_DecodeBER(arenaOpt, &holder, 
                             nss_atav_template, berATAV);
  if( PR_SUCCESS != status ) {
    return (NSSATAV *)NULL;
  }

  rv = nss_ZNEW(arenaOpt, NSSATAV);
  if( (NSSATAV *)NULL == rv ) {
    nss_ZFreeIf(holder.oid.data);
    nss_ZFreeIf(holder.value.data);
    return (NSSATAV *)NULL;
  }

  rv->oid = nssOID_CreateFromBER(&holder.oid);
  if( (NSSOID *)NULL == rv->oid ) {
    nss_ZFreeIf(rv);
    nss_ZFreeIf(holder.oid.data);
    nss_ZFreeIf(holder.value.data);
    return (NSSATAV *)NULL;
  }

  nss_ZFreeIf(holder.oid.data);

  rv->ber.data = nss_ZAlloc(arenaOpt, berATAV->size);
  if( (void *)NULL == rv->ber.data ) {
    nss_ZFreeIf(rv);
    nss_ZFreeIf(holder.value.data);
    return (NSSATAV *)NULL;
  }

  rv->ber.size = berATAV->size;
  (void)nsslibc_memcpy(rv->ber.data, berATAV->data, berATAV->size);

  rv->value = nss_attr_to_utf8(arenaOpt, rv->oid, &holder.value,
                               &rv->stringForm);
  if( (NSSUTF8 *)NULL == rv->value ) {
    nss_ZFreeIf(rv->ber.data);
    nss_ZFreeIf(rv);
    nss_ZFreeIf(holder.value.data);
    return (NSSATAV *)NULL;
  }

  nss_ZFreeIf(holder.value.data);

#ifdef DEBUG
  if( PR_SUCCESS != atav_add_pointer(rv) ) {
    nss_ZFreeIf(rv->ber.data);
    nss_ZFreeIf(rv->value);
    nss_ZFreeIf(rv);
    return (NSSATAV *)NULL;
  }
#endif /* DEBUG */

  return rv;
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* NSSATAV_CreateFromUTF8 ( NSSArena *  arenaOpt,
NSSUTF8 stringATAV 
)

Definition at line 205 of file atav.c.

{
  nss_ClearErrorStack();

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

  /*
   * NSSUTF8s can be created by the user,
   * so no pointer-tracking can be checked.
   */

  if( (NSSUTF8 *)NULL == stringATAV ) {
    nss_SetError(NSS_ERROR_INVALID_UTF8);
    return (NSSATAV *)NULL;
  }
#endif /* DEBUG */

  return nssATAV_CreateFromUTF8(arenaOpt, stringATAV);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* nssATAV_CreateFromUTF8 ( NSSArena *  arenaOpt,
const NSSUTF8 stringATAV 
)

Definition at line 1018 of file atav.c.

{
  char *c;
  NSSUTF8 *type;
  NSSUTF8 *value;
  PRUint32 i;
  const NSSOID *oid = (NSSOID *)NULL;
  NSSATAV *rv;
  NSSItem xitem;

  xitem.data = (void *)NULL;

  for( c = (char *)stringATAV; '\0' != *c; c++ ) {
    if( '=' == *c ) {
#ifdef PEDANTIC
      /*
       * Theoretically, one could have an '=' in an 
       * attribute string alias.  We don't, yet, though.
       */
      if( (char *)stringATAV == c ) {
        nss_SetError(NSS_ERROR_INVALID_STRING);
        return (NSSATAV *)NULL;
      } else {
        if( '\\' == c[-1] ) {
          continue;
        }
      }
#endif /* PEDANTIC */
      break;
    }
  }

  if( '\0' == *c ) {
    nss_SetError(NSS_ERROR_INVALID_UTF8);
    return (NSSATAV *)NULL;
  } else {
    c++;
    value = (NSSUTF8 *)c;
  }

  i = ((NSSUTF8 *)c - stringATAV);
  type = (NSSUTF8 *)nss_ZAlloc((NSSArena *)NULL, i);
  if( (NSSUTF8 *)NULL == type ) {
    return (NSSATAV *)NULL;
  }

  (void)nsslibc_memcpy(type, stringATAV, i-1);

  c = (char *)stringATAV;
  if( (('0' <= *c) && (*c <= '9')) || ('#' == *c) ) {
    oid = nssOID_CreateFromUTF8(type);
    if( (NSSOID *)NULL == oid ) {
      nss_ZFreeIf(type);
      return (NSSATAV *)NULL;
    }
  } else {
    for( i = 0; i < nss_attribute_type_alias_count; i++ ) {
      PRStatus status;
      const nssAttributeTypeAliasTable *e = &nss_attribute_type_aliases[i];
      PRBool match = nssUTF8_CaseIgnoreMatch(type, e->alias, &status);
      if( PR_SUCCESS != status ) {
        nss_ZFreeIf(type);
        return (NSSATAV *)NULL;
      }
      if( PR_TRUE == match ) {
        oid = *(e->oid);
        break;
      }
    }

    if( (NSSOID *)NULL == oid ) {
      nss_ZFreeIf(type);
      nss_SetError(NSS_ERROR_UNKNOWN_ATTRIBUTE);
      return (NSSATAV *)NULL;
    }
  }

  nss_ZFreeIf(type);
  type = (NSSUTF8 *)NULL;

  rv = nss_ZNEW(arenaOpt, NSSATAV);
  if( (NSSATAV *)NULL == rv ) {
    return (NSSATAV *)NULL;
  }

  rv->oid = oid;

  if( '#' == *value ) { /* XXX fgmr.. was it '#'?  or backslash? */
    PRUint32 size;
    PRUint32 len;
    NSSUTF8 *c;
    NSSUTF8 *d;
    PRStatus status;
    /* It's in hex */

    value++;
    if( PR_TRUE != nss_atav_utf8_string_is_hex(value) ) {
      (void)nss_ZFreeIf(rv);
      nss_SetError(NSS_ERROR_INVALID_STRING);
      return (NSSATAV *)NULL;
    }

    size = nssUTF8_Size(value, &status);
    if( PR_SUCCESS != status ) {
      /* 
       * Only returns an error on bad pointer (nope) or string
       * too long.  The defined limits for known attributes are
       * small enough to fit in PRUint32, and when undefined we
       * get to apply our own practical limits.  Ergo, I say the 
       * string is invalid.
       */
      (void)nss_ZFreeIf(rv);
      nss_SetError(NSS_ERROR_INVALID_STRING);
      return (NSSATAV *)NULL;
    }

    if( ((size-1) & 1) ) {
      /* odd length */
      (void)nss_ZFreeIf(rv);
      nss_SetError(NSS_ERROR_INVALID_STRING);
      return (NSSATAV *)NULL;
    }

    len = (size-1)/2;

    rv->value = (NSSUTF8 *)nss_ZAlloc(arenaOpt, len+1);
    if( (NSSUTF8 *)NULL == rv->value ) {
      (void)nss_ZFreeIf(rv);
      return (NSSATAV *)NULL;
    }

    xitem.size = len;
    xitem.data = (void *)rv->value;

    for( c = rv->value, d = value; len--; c++, d += 2 ) {
      *c = nss_atav_fromhex(d);
    }

    *c = 0;
  } else {
    PRStatus status;
    PRUint32 i, len;
    PRUint8 *s;

    /*
     * XXX fgmr-- okay, this is a little wasteful, and should
     * probably be abstracted out a bit.  Later.
     */

    rv->value = nssUTF8_Duplicate(value, arenaOpt);
    if( (NSSUTF8 *)NULL == rv->value ) {
      (void)nss_ZFreeIf(rv);
      return (NSSATAV *)NULL;
    }

    len = nssUTF8_Size(rv->value, &status);
    if( PR_SUCCESS != status ) {
      (void)nss_ZFreeIf(rv->value);
      (void)nss_ZFreeIf(rv);
      return (NSSATAV *)NULL;
    }

    s = (PRUint8 *)rv->value;
    for( i = 0; i < len; i++ ) {
      if( '\\' == s[i] ) {
        (void)nsslibc_memcpy(&s[i], &s[i+1], len-i-1);
      }
    }
  }

  /* Now just BER-encode the baby and we're through.. */
  {
    const struct nss_attribute_data_str *which = 
      (struct nss_attribute_data_str *)NULL;
    PRUint32 i;
    NSSArena *a;
    NSSDER *oidder;
    NSSItem *vitem;
    atav_holder ah;
    NSSDER *status;

    for( i = 0; i < nss_attribute_data_quantity; i++ ) {
      if( *(nss_attribute_data[ i ].oid) == rv->oid ) {
        which = &nss_attribute_data[i];
        break;
      }
    }

    a = NSSArena_Create();
    if( (NSSArena *)NULL == a ) {
      (void)nss_ZFreeIf(rv->value);
      (void)nss_ZFreeIf(rv);
      return (NSSATAV *)NULL;
    }

    oidder = nssOID_GetDEREncoding(rv->oid, (NSSDER *)NULL, a);
    if( (NSSDER *)NULL == oidder ) {
      (void)NSSArena_Destroy(a);
      (void)nss_ZFreeIf(rv->value);
      (void)nss_ZFreeIf(rv);
      return (NSSATAV *)NULL;
    }

    if( (struct nss_attribute_data_str *)NULL == which ) {
      /*
       * We'll just have to take the user data as an octet stream.
       */
      if( (void *)NULL == xitem.data ) {
        /*
         * This means that an ATTR entry has been added to oids.txt,
         * but no corresponding entry has been added to the array
         * ns_attribute_data[] above.
         */
        nss_SetError(NSS_ERROR_INTERNAL_ERROR);
        (void)NSSArena_Destroy(a);
        (void)nss_ZFreeIf(rv->value);
        (void)nss_ZFreeIf(rv);
        return (NSSATAV *)NULL;
      }

      vitem = nssASN1_EncodeItem(a, (NSSDER *)NULL, &xitem, 
                                 nssASN1Template_OctetString, NSSASN1DER);
      if( (NSSItem *)NULL == vitem ) {
        (void)NSSArena_Destroy(a);
        (void)nss_ZFreeIf(rv->value);
        (void)nss_ZFreeIf(rv);
        return (NSSATAV *)NULL;
      }

      rv->stringForm = nssStringType_Unknown;
    } else {
      PRUint32 length = 0;
      PRStatus stat;
      
      length = nssUTF8_Length(rv->value, &stat);
      if( PR_SUCCESS != stat ) {
        (void)NSSArena_Destroy(a);
        (void)nss_ZFreeIf(rv->value);
        (void)nss_ZFreeIf(rv);
        return (NSSATAV *)NULL;
      }

      if( ((0 != which->minStringLength) && 
           (length < which->minStringLength)) ||
          ((0 != which->maxStringLength) &&
           (length > which->maxStringLength)) ) {
        nss_SetError(NSS_ERROR_INVALID_STRING);
        (void)NSSArena_Destroy(a);
        (void)nss_ZFreeIf(rv->value);
        (void)nss_ZFreeIf(rv);
        return (NSSATAV *)NULL;
      }

      vitem = nssUTF8_GetDEREncoding(a, which->stringType, rv->value);
      if( (NSSItem *)NULL == vitem ) {
        (void)NSSArena_Destroy(a);
        (void)nss_ZFreeIf(rv->value);
        (void)nss_ZFreeIf(rv);
        return (NSSATAV *)NULL;
      }

      if( nssStringType_DirectoryString == which->stringType ) {
        rv->stringForm = nssStringType_UTF8String;
      } else {
        rv->stringForm = which->stringType;
      }
    }

    ah.oid = *oidder;
    ah.value = *vitem;

    status = nssASN1_EncodeItem(arenaOpt, &rv->ber, &ah, 
                                nss_atav_template, NSSASN1DER);

    if( (NSSDER *)NULL == status ) {
      (void)NSSArena_Destroy(a);
      (void)nss_ZFreeIf(rv->value);
      (void)nss_ZFreeIf(rv);
      return (NSSATAV *)NULL;
    }

    (void)NSSArena_Destroy(a);
  }

  return rv;
}

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus NSSATAV_Destroy ( NSSATAV *  atav)

Definition at line 306 of file atav.c.

{
  nss_ClearErrorStack();

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

  return nssATAV_Destroy(atav);
}

Here is the call graph for this function:

NSS_IMPLEMENT PRStatus nssATAV_Destroy ( NSSATAV *  atav)

Definition at line 1381 of file atav.c.

{
#ifdef NSSDEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return PR_FAILURE;
  }
#endif /* NSSDEBUG */

  (void)nss_ZFreeIf(atav->ber.data);
  (void)nss_ZFreeIf(atav->value);

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

  return PR_SUCCESS;
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* NSSATAV_Duplicate ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 549 of file atav.c.

{
  nss_ClearErrorStack();

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSATAV *)NULL;
  }

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

  return nssATAV_Duplicate(atav, arenaOpt);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSATAV* nssATAV_Duplicate ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 1775 of file atav.c.

{
  NSSATAV *rv;

#ifdef NSSDEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSATAV *)NULL;
  }

  if( (NSSArena *)NULL != arenaOpt ) {
    if( PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
      return (NSSATAV *)NULL;
    }
  }
#endif /* NSSDEBUG */

  rv = nss_ZNEW(arenaOpt, NSSATAV);
  if( (NSSATAV *)NULL == rv ) {
    return (NSSATAV *)NULL;
  }

  rv->oid = atav->oid;
  rv->stringForm = atav->stringForm;
  rv->value = nssUTF8_Duplicate(atav->value, arenaOpt);
  if( (NSSUTF8 *)NULL == rv->value ) {
    (void)nss_ZFreeIf(rv);
    return (NSSATAV *)NULL;
  }

  rv->ber.data = nss_ZAlloc(arenaOpt, atav->ber.size);
  if( (void *)NULL == rv->ber.data ) {
    (void)nss_ZFreeIf(rv->value);
    (void)nss_ZFreeIf(rv);
    return (NSSATAV *)NULL;
  }

  rv->ber.size = atav->ber.size;
  if( NULL == nsslibc_memcpy(rv->ber.data, atav->ber.data, 
                                   atav->ber.size) ) {
    (void)nss_ZFreeIf(rv->ber.data);
    (void)nss_ZFreeIf(rv->value);
    (void)nss_ZFreeIf(rv);
    return (NSSATAV *)NULL;
  }

  return rv;
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSDER* NSSATAV_GetDEREncoding ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 341 of file atav.c.

{
  nss_ClearErrorStack();

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSDER *)NULL;
  }

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

  return nssATAV_GetDEREncoding(atav, arenaOpt);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSDER* nssATAV_GetDEREncoding ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 1423 of file atav.c.

{
  NSSDER *rv;

#ifdef NSSDEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSDER *)NULL;
  }
#endif /* NSSDEBUG */

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

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

  rv->size = atav->ber.size;
  if( NULL == nsslibc_memcpy(rv->data, atav->ber.data, rv->size) ) {
    (void)nss_ZFreeIf(rv->data);
    (void)nss_ZFreeIf(rv);
    return (NSSDER *)NULL;
  }

  return rv;
}

Here is the call graph for this function:

NSS_IMPLEMENT const NSSOID* NSSATAV_GetType ( NSSATAV *  atav)

Definition at line 424 of file atav.c.

{
  nss_ClearErrorStack();

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSOID *)NULL;
  }
#endif /* DEBUG */

  return nssATAV_GetType(atav);
}

Here is the call graph for this function:

NSS_IMPLEMENT const NSSOID* nssATAV_GetType ( NSSATAV *  atav)

Definition at line 1592 of file atav.c.

{
#ifdef NSSDEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSOID *)NULL;
  }
#endif /* NSSDEBUG */

  return atav->oid;
}
NSS_IMPLEMENT NSSUTF8* NSSATAV_GetUTF8Encoding ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 385 of file atav.c.

{
  nss_ClearErrorStack();

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSUTF8 *)NULL;
  }

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

  return nssATAV_GetUTF8Encoding(atav, arenaOpt);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSUTF8* nssATAV_GetUTF8Encoding ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 1479 of file atav.c.

{
  NSSUTF8 *rv;
  PRUint32 i;
  const NSSUTF8 *alias = (NSSUTF8 *)NULL;
  NSSUTF8 *oid;
  NSSUTF8 *value;
  PRUint32 oidlen;
  PRUint32 valuelen;
  PRUint32 totallen;
  PRStatus status;

#ifdef NSSDEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSUTF8 *)NULL;
  }
#endif /* NSSDEBUG */

  for( i = 0; i < nss_attribute_type_alias_count; i++ ) {
    if( *(nss_attribute_type_aliases[i].oid) == atav->oid ) {
      alias = nss_attribute_type_aliases[i].alias;
      break;
    }
  }

  if( (NSSUTF8 *)NULL == alias ) {
    oid = nssOID_GetUTF8Encoding(atav->oid, (NSSArena *)NULL);
    if( (NSSUTF8 *)NULL == oid ) {
      return (NSSUTF8 *)NULL;
    }

    oidlen = nssUTF8_Size(oid, &status);
    if( PR_SUCCESS != status ) {
      (void)nss_ZFreeIf(oid);
      return (NSSUTF8 *)NULL;
    }
  } else {
    oidlen = nssUTF8_Size(alias, &status);
    if( PR_SUCCESS != status ) {
      return (NSSUTF8 *)NULL;
    }
    oid = (NSSUTF8 *)NULL;
  }

  value = nssATAV_GetValue(atav, (NSSArena *)NULL);
  if( (NSSUTF8 *)NULL == value ) {
    (void)nss_ZFreeIf(oid);
    return (NSSUTF8 *)NULL;
  }

  valuelen = nssUTF8_Size(value, &status);
  if( PR_SUCCESS != status ) {
    (void)nss_ZFreeIf(value);
    (void)nss_ZFreeIf(oid);
    return (NSSUTF8 *)NULL;
  }

  totallen = oidlen + valuelen - 1 + 1;
  rv = (NSSUTF8 *)nss_ZAlloc(arenaOpt, totallen);
  if( (NSSUTF8 *)NULL == rv ) {
    (void)nss_ZFreeIf(value);
    (void)nss_ZFreeIf(oid);
    return (NSSUTF8 *)NULL;
  }

  if( (NSSUTF8 *)NULL == alias ) {
    if( (void *)NULL == nsslibc_memcpy(rv, oid, oidlen-1) ) {
      (void)nss_ZFreeIf(rv);
      (void)nss_ZFreeIf(value);
      (void)nss_ZFreeIf(oid);
      return (NSSUTF8 *)NULL;
    }
  } else {
    if( (void *)NULL == nsslibc_memcpy(rv, alias, oidlen-1) ) {
      (void)nss_ZFreeIf(rv);
      (void)nss_ZFreeIf(value);
      return (NSSUTF8 *)NULL;
    }
  }

  rv[ oidlen-1 ] = '=';

  if( (void *)NULL == nsslibc_memcpy(&rv[oidlen], value, valuelen) ) {
    (void)nss_ZFreeIf(rv);
    (void)nss_ZFreeIf(value);
    (void)nss_ZFreeIf(oid);
    return (NSSUTF8 *)NULL;
  }

  return rv;
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSUTF8* NSSATAV_GetValue ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 459 of file atav.c.

{
  nss_ClearErrorStack();

#ifdef DEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSUTF8 *)NULL;
  }

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

  return nssATAV_GetValue(atav, arenaOpt);
}

Here is the call graph for this function:

NSS_IMPLEMENT NSSUTF8* nssATAV_GetValue ( NSSATAV *  atav,
NSSArena *  arenaOpt 
)

Definition at line 1626 of file atav.c.

{
#ifdef NSSDEBUG
  if( PR_SUCCESS != nssATAV_verifyPointer(atav) ) {
    return (NSSUTF8 *)NULL;
  }
#endif /* NSSDEBUG */

  return nssUTF8_Duplicate(atav->value, arenaOpt);
}

Here is the call graph for this function:


Variable Documentation

Initial value:

Definition at line 668 of file atav.c.

Initial value:
 
  (sizeof(nss_attribute_data)/sizeof(nss_attribute_data[0]))

Definition at line 724 of file atav.c.

struct nss_attribute_data_str[] [static]

Definition at line 687 of file atav.c.

Definition at line 52 of file errorval.c.