Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
cmsattr.c File Reference
#include "cmslocal.h"
#include "secasn1.h"
#include "secitem.h"
#include "secoid.h"
#include "pk11func.h"
#include "prtime.h"
#include "secerr.h"

Go to the source code of this file.

Functions

NSSCMSAttribute * NSS_CMSAttribute_Create (PRArenaPool *poolp, SECOidTag oidtag, SECItem *value, PRBool encoded)
SECStatus NSS_CMSAttribute_AddValue (PLArenaPool *poolp, NSSCMSAttribute *attr, SECItem *value)
SECOidTag NSS_CMSAttribute_GetType (NSSCMSAttribute *attr)
SECItem * NSS_CMSAttribute_GetValue (NSSCMSAttribute *attr)
PRBool NSS_CMSAttribute_CompareValue (NSSCMSAttribute *attr, SECItem *av)
static const SEC_ASN1Templatecms_attr_choose_attr_value_template (void *src_or_dest, PRBool encoding)
SECItem * NSS_CMSAttributeArray_Encode (PRArenaPool *poolp, NSSCMSAttribute ***attrs, SECItem *dest)
SECStatus NSS_CMSAttributeArray_Reorder (NSSCMSAttribute **attrs)
NSSCMSAttribute * NSS_CMSAttributeArray_FindAttrByOidTag (NSSCMSAttribute **attrs, SECOidTag oidtag, PRBool only)
SECStatus NSS_CMSAttributeArray_AddAttr (PLArenaPool *poolp, NSSCMSAttribute ***attrs, NSSCMSAttribute *attr)
SECStatus NSS_CMSAttributeArray_SetAttr (PLArenaPool *poolp, NSSCMSAttribute ***attrs, SECOidTag type, SECItem *value, PRBool encoded)

Variables

static const
SEC_ASN1TemplateChooserPtr 
cms_attr_chooser = cms_attr_choose_attr_value_template
const SEC_ASN1Template nss_cms_attribute_template []
const SEC_ASN1Template nss_cms_set_of_attribute_template []

Function Documentation

static const SEC_ASN1Template* cms_attr_choose_attr_value_template ( void src_or_dest,
PRBool  encoding 
) [static]

Definition at line 212 of file cmsattr.c.

{
    const SEC_ASN1Template *theTemplate;
    NSSCMSAttribute *attribute;
    SECOidData *oiddata;
    PRBool encoded;

    PORT_Assert (src_or_dest != NULL);
    if (src_or_dest == NULL)
       return NULL;

    attribute = (NSSCMSAttribute *)src_or_dest;

    if (encoding && (!attribute->values || !attribute->values[0] ||
        attribute->encoded)) {
        /* we're encoding, and the attribute has no value or the attribute
         * value is already encoded. */
        return SEC_ASN1_GET(SEC_AnyTemplate);
    }

    /* get attribute's typeTag */
    oiddata = attribute->typeTag;
    if (oiddata == NULL) {
       oiddata = SECOID_FindOID(&attribute->type);
       attribute->typeTag = oiddata;
    }

    if (oiddata == NULL) {
       /* still no OID tag? OID is unknown then. en/decode value as ANY. */
       encoded = PR_TRUE;
       theTemplate = SEC_ASN1_GET(SEC_AnyTemplate);
    } else {
       switch (oiddata->offset) {
       case SEC_OID_PKCS9_SMIME_CAPABILITIES:
       case SEC_OID_SMIME_ENCRYPTION_KEY_PREFERENCE:
           /* these guys need to stay DER-encoded */
       default:
           /* same goes for OIDs that are not handled here */
           encoded = PR_TRUE;
           theTemplate = SEC_ASN1_GET(SEC_AnyTemplate);
           break;
           /* otherwise choose proper template */
       case SEC_OID_PKCS9_EMAIL_ADDRESS:
       case SEC_OID_RFC1274_MAIL:
       case SEC_OID_PKCS9_UNSTRUCTURED_NAME:
           encoded = PR_FALSE;
           theTemplate = SEC_ASN1_GET(SEC_IA5StringTemplate);
           break;
       case SEC_OID_PKCS9_CONTENT_TYPE:
           encoded = PR_FALSE;
           theTemplate = SEC_ASN1_GET(SEC_ObjectIDTemplate);
           break;
       case SEC_OID_PKCS9_MESSAGE_DIGEST:
           encoded = PR_FALSE;
           theTemplate = SEC_ASN1_GET(SEC_OctetStringTemplate);
           break;
       case SEC_OID_PKCS9_SIGNING_TIME:
           encoded = PR_FALSE;
           theTemplate = SEC_ASN1_GET(CERT_TimeChoiceTemplate);
           break;
         /* XXX Want other types here, too */
       }
    }

    if (encoding) {
       /*
        * If we are encoding and we think we have an already-encoded value,
        * then the code which initialized this attribute should have set
        * the "encoded" property to true (and we would have returned early,
        * up above).  No devastating error, but that code should be fixed.
        * (It could indicate that the resulting encoded bytes are wrong.)
        */
       PORT_Assert (!encoded);
    } else {
       /*
        * We are decoding; record whether the resulting value is
        * still encoded or not.
        */
       attribute->encoded = encoded;
    }
    return theTemplate;
}

Here is the call graph for this function:

SECStatus NSS_CMSAttribute_AddValue ( PLArenaPool poolp,
NSSCMSAttribute *  attr,
SECItem *  value 
)

Definition at line 115 of file cmsattr.c.

{
    SECItem *copiedvalue;
    void *mark;

    PORT_Assert (poolp != NULL);

    mark = PORT_ArenaMark(poolp);

    if (value == NULL) {
       PORT_SetError(SEC_ERROR_INVALID_ARGS);
       goto loser;
    }

    if ((copiedvalue = SECITEM_ArenaDupItem(poolp, value)) == NULL)
       goto loser;

    if (NSS_CMSArray_Add(poolp, (void ***)&(attr->values), (void *)copiedvalue) != SECSuccess)
       goto loser;

    PORT_ArenaUnmark(poolp, mark);
    return SECSuccess;

loser:
    PORT_Assert (mark != NULL);
    PORT_ArenaRelease (poolp, mark);
    return SECFailure;
}

Here is the call graph for this function:

PRBool NSS_CMSAttribute_CompareValue ( NSSCMSAttribute *  attr,
SECItem *  av 
)

Definition at line 189 of file cmsattr.c.

{
    SECItem *value;
    
    if (attr == NULL)
       return PR_FALSE;

    value = NSS_CMSAttribute_GetValue(attr);

    return (value != NULL && value->len == av->len &&
       PORT_Memcmp (value->data, av->data, value->len) == 0);
}

Here is the call graph for this function:

NSSCMSAttribute* NSS_CMSAttribute_Create ( PRArenaPool poolp,
SECOidTag  oidtag,
SECItem *  value,
PRBool  encoded 
)

Definition at line 70 of file cmsattr.c.

{
    NSSCMSAttribute *attr;
    SECItem *copiedvalue;
    void *mark;

    PORT_Assert (poolp != NULL);

    mark = PORT_ArenaMark (poolp);

    attr = (NSSCMSAttribute *)PORT_ArenaZAlloc(poolp, sizeof(NSSCMSAttribute));
    if (attr == NULL)
       goto loser;

    attr->typeTag = SECOID_FindOIDByTag(oidtag);
    if (attr->typeTag == NULL)
       goto loser;

    if (SECITEM_CopyItem(poolp, &(attr->type), &(attr->typeTag->oid)) != SECSuccess)
       goto loser;

    if (value != NULL) {
       if ((copiedvalue = SECITEM_ArenaDupItem(poolp, value)) == NULL)
           goto loser;

       if (NSS_CMSArray_Add(poolp, (void ***)&(attr->values), (void *)copiedvalue) != SECSuccess)
           goto loser;
    }

    attr->encoded = encoded;

    PORT_ArenaUnmark (poolp, mark);

    return attr;

loser:
    PORT_Assert (mark != NULL);
    PORT_ArenaRelease (poolp, mark);
    return NULL;
}

Here is the call graph for this function:

SECOidTag NSS_CMSAttribute_GetType ( NSSCMSAttribute *  attr)

Definition at line 148 of file cmsattr.c.

{
    SECOidData *typetag;

    typetag = SECOID_FindOID(&(attr->type));
    if (typetag == NULL)
       return SEC_OID_UNKNOWN;

    return typetag->offset;
}

Here is the call graph for this function:

SECItem* NSS_CMSAttribute_GetValue ( NSSCMSAttribute *  attr)

Definition at line 167 of file cmsattr.c.

{
    SECItem *value;

    if (attr == NULL)
       return NULL;

    value = attr->values[0];

    if (value == NULL || value->data == NULL || value->len == 0)
       return NULL;

    if (attr->values[1] != NULL)
       return NULL;

    return value;
}
SECStatus NSS_CMSAttributeArray_AddAttr ( PLArenaPool poolp,
NSSCMSAttribute ***  attrs,
NSSCMSAttribute *  attr 
)

Definition at line 397 of file cmsattr.c.

{
    NSSCMSAttribute *oattr;
    void *mark;
    SECOidTag type;

    mark = PORT_ArenaMark(poolp);

    /* find oidtag of attr */
    type = NSS_CMSAttribute_GetType(attr);

    /* see if we have one already */
    oattr = NSS_CMSAttributeArray_FindAttrByOidTag(*attrs, type, PR_FALSE);
    PORT_Assert (oattr == NULL);
    if (oattr != NULL)
       goto loser;   /* XXX or would it be better to replace it? */

    /* no, shove it in */
    if (NSS_CMSArray_Add(poolp, (void ***)attrs, (void *)attr) != SECSuccess)
       goto loser;

    PORT_ArenaUnmark(poolp, mark);
    return SECSuccess;

loser:
    PORT_ArenaRelease(poolp, mark);
    return SECFailure;
}

Here is the call graph for this function:

SECItem* NSS_CMSAttributeArray_Encode ( PRArenaPool poolp,
NSSCMSAttribute ***  attrs,
SECItem *  dest 
)

Definition at line 327 of file cmsattr.c.

Here is the call graph for this function:

NSSCMSAttribute* NSS_CMSAttributeArray_FindAttrByOidTag ( NSSCMSAttribute **  attrs,
SECOidTag  oidtag,
PRBool  only 
)

Definition at line 354 of file cmsattr.c.

{
    SECOidData *oid;
    NSSCMSAttribute *attr1, *attr2;

    if (attrs == NULL)
       return NULL;

    oid = SECOID_FindOIDByTag(oidtag);
    if (oid == NULL)
       return NULL;

    while ((attr1 = *attrs++) != NULL) {
       if (attr1->type.len == oid->oid.len && PORT_Memcmp (attr1->type.data,
                                                     oid->oid.data,
                                                     oid->oid.len) == 0)
           break;
    }

    if (attr1 == NULL)
       return NULL;

    if (!only)
       return attr1;

    while ((attr2 = *attrs++) != NULL) {
       if (attr2->type.len == oid->oid.len && PORT_Memcmp (attr2->type.data,
                                                     oid->oid.data,
                                                     oid->oid.len) == 0)
           break;
    }

    if (attr2 != NULL)
       return NULL;

    return attr1;
}

Here is the call graph for this function:

SECStatus NSS_CMSAttributeArray_Reorder ( NSSCMSAttribute **  attrs)

Definition at line 340 of file cmsattr.c.

Here is the call graph for this function:

SECStatus NSS_CMSAttributeArray_SetAttr ( PLArenaPool poolp,
NSSCMSAttribute ***  attrs,
SECOidTag  type,
SECItem *  value,
PRBool  encoded 
)

Definition at line 430 of file cmsattr.c.

{
    NSSCMSAttribute *attr;
    void *mark;

    mark = PORT_ArenaMark(poolp);

    /* see if we have one already */
    attr = NSS_CMSAttributeArray_FindAttrByOidTag(*attrs, type, PR_FALSE);
    if (attr == NULL) {
       /* not found? create one! */
       attr = NSS_CMSAttribute_Create(poolp, type, value, encoded);
       if (attr == NULL)
           goto loser;
       /* and add it to the list */
       if (NSS_CMSArray_Add(poolp, (void ***)attrs, (void *)attr) != SECSuccess)
           goto loser;
    } else {
       /* found, shove it in */
       /* XXX we need a decent memory model @#$#$!#!!! */
       attr->values[0] = value;
       attr->encoded = encoded;
    }

    PORT_ArenaUnmark (poolp, mark);
    return SECSuccess;

loser:
    PORT_ArenaRelease (poolp, mark);
    return SECFailure;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 296 of file cmsattr.c.

Initial value:
 {
    { SEC_ASN1_SEQUENCE,
         0, NULL, sizeof(NSSCMSAttribute) },
    { SEC_ASN1_OBJECT_ID,
         offsetof(NSSCMSAttribute,type) },
    { SEC_ASN1_DYNAMIC | SEC_ASN1_SET_OF,
         offsetof(NSSCMSAttribute,values),
         &cms_attr_chooser },
    { 0 }
}

Definition at line 298 of file cmsattr.c.

Initial value:

Definition at line 309 of file cmsattr.c.