⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 context.c

📁 Next BIOS Source code : Extensible Firmware Interface
💻 C
📖 第 1 页 / 共 2 页
字号:

    switch (Type & CSSM_ATTRIBUTE_TYPE_MASK) {
        case CSSM_ATTRIBUTE_DATA_UINT32 :{
            Attribute->AttributeLength = sizeof(uint32);
            // The following line generates a warning when compiled as
            // 64-bit code, on the grounds that the 64-bit "Data" gets
            // truncated down to 32 bits.  This is benign in this case
            // since we know the data is actually 32 bits stuffed into
            // a 64-bit variable.
            Attribute->Attribute.Uint32 = (uint32) Data;
        }
        break;

#ifndef CSSM_BIS
        case CSSM_ATTRIBUTE_DATA_CSSM_DATA : {
            Attribute->AttributeLength = sizeof(CSSM_DATA);
            if ((Attribute->Attribute.Data = cssm_CopyDataStruct(Data)) == NULL)
                goto ADD_ATTR_FAIL;
        }
        break;
#endif /* #ifndef CSSM_BIS */

        case CSSM_ATTRIBUTE_DATA_CRYPTO_DATA : {
            CSSM_CRYPTO_DATA_PTR Source = Data;
            CSSM_CRYPTO_DATA_PTR Dest;

            Attribute->AttributeLength = sizeof(CSSM_CRYPTO_DATA); 

            if ((Dest = cssm_malloc(Attribute->AttributeLength, 0)) == NULL)
                goto ADD_ATTR_FAIL;

            *Dest = *Source;

            if (Source->Param) {
                if ((Dest->Param = cssm_CopyDataStruct(Source->Param)) == NULL) {
                    cssm_free (Dest, 0);
                    goto ADD_ATTR_FAIL;
                }
            }

            Attribute->Attribute.Crypto = Dest;
        }
        break;

        case CSSM_ATTRIBUTE_DATA_KEY: {
            CSSM_KEY_PTR Source = Data;
            CSSM_KEY_PTR Dest;

            Attribute->AttributeLength = sizeof(CSSM_KEY);

            if ((Dest = cssm_malloc (Attribute->AttributeLength, 0)) == NULL)
                goto ADD_ATTR_FAIL;

            *Dest = *Source;

            Dest->KeyData.Data = cssm_malloc(Source->KeyData.Length, 0);
            if (!Dest->KeyData.Data) {
                cssm_free (Dest, 0);
                goto ADD_ATTR_FAIL;
            }
            cssm_memcpy (Dest->KeyData.Data, 
                         Source->KeyData.Data, 
                         Source->KeyData.Length);

            Attribute->Attribute.Key = Dest;                
        }
        break;

#ifndef CSSM_BIS
        case CSSM_ATTRIBUTE_DATA_STRING : {
            char *Source = Data;
            char *Dest;

            Attribute->AttributeLength = cssm_strlen(Source);
            
            if ((Dest = cssm_malloc(Attribute->AttributeLength+1, 0)) == NULL)
                goto ADD_ATTR_FAIL;
            cssm_strcpy (Dest, Source);

            Attribute->Attribute.String = Dest;
        }
        break;

        case CSSM_ATTRIBUTE_DATA_DATE: {
            CSSM_DATE_PTR Source = Data;
            CSSM_DATE_PTR Dest;

            Attribute->AttributeLength = sizeof(CSSM_DATE);

            if ((Dest = cssm_malloc (Attribute->AttributeLength, 0)) == NULL)
                goto ADD_ATTR_FAIL;
            cssm_memcpy(Dest, Source, Attribute->AttributeLength);

            Attribute->Attribute.Date = Dest;
        }
        break;

        case CSSM_ATTRIBUTE_DATA_RANGE: {
            CSSM_RANGE_PTR Source = Data;
            CSSM_RANGE_PTR Dest;

            Attribute->AttributeLength = sizeof(CSSM_RANGE);

            if (!Source)
            {
                CSSM_SetError(&CssmGUID, CSSM_INVALID_ATTRIBUTE);
                return CSSM_FAIL;
            }

            if ((Dest = cssm_malloc (Attribute->AttributeLength, 0)) == NULL)
                goto ADD_ATTR_FAIL;
            *Dest = *Source;

            Attribute->Attribute.Range = Dest;
        }
        break;

        case CSSM_ATTRIBUTE_DATA_VERSION: {
            CSSM_VERSION_PTR Source = Data;
            CSSM_VERSION_PTR Dest;

            Attribute->AttributeLength = sizeof(CSSM_VERSION);

            if (!Source)
            {
                CSSM_SetError(&CssmGUID, CSSM_INVALID_ATTRIBUTE);
                return CSSM_FAIL;
            }

            if ((Dest = cssm_malloc (Attribute->AttributeLength, 0)) == NULL)
                goto ADD_ATTR_FAIL;
            *Dest = *Source;

            Attribute->Attribute.Version = Dest;
        }
        break;
#endif /* #ifndef CSSM_BIS */
    }

    return CSSM_OK;

ADD_ATTR_FAIL:
    Attribute->AttributeType = 0;
    Attribute->AttributeLength = 0;
    CSSM_SetError(&CssmGUID, CSSM_MEMORY_ERROR);
    return CSSM_FAIL;
}


/*---------------------------------------------------------------
 *Name: cssm_FreeContext
 *
 *Description:
 *   Free the memory that was allocated for this context
 *
 *Parameters: 
 *   Context (input) - the context to be freed
 *
 *Returns:
 *   None
 *
 *-------------------------------------------------------------*/
void cssm_FreeContext (CSSM_CONTEXT_PTR Context)
{
    CSSM_CONTEXT_ATTRIBUTE_PTR Attributes = Context->ContextAttributes;
    uint32 i;

    /* For each attribute */
    for (i=0; i < Context->NumberOfAttributes; i++, Attributes++) 
    {
        /* If there is something to free */
        if ((Attributes->AttributeType & CSSM_ATTRIBUTE_TYPE_MASK) != 
                                                CSSM_ATTRIBUTE_DATA_UINT32)
        {
            /* Free any buffers inside of the attribute */
            switch (Attributes->AttributeType & CSSM_ATTRIBUTE_TYPE_MASK)
            {
                case CSSM_ATTRIBUTE_DATA_CRYPTO_DATA: 
                    if (Attributes->Attribute.Crypto->Param) 
                    {
                        cssm_free(Attributes->Attribute.Crypto->Param->Data, 0);
                        cssm_free(Attributes->Attribute.Crypto->Param, 0);
                    }
                    break;

                case CSSM_ATTRIBUTE_DATA_KEY : 
                    cssm_free(Attributes->Attribute.Key->KeyData.Data, 0);
                    break;

#ifndef CSSM_BIS
                case CSSM_ATTRIBUTE_DATA_CSSM_DATA:
                    cssm_free(Attributes->Attribute.Data->Data, 0);
                    break;
#endif
            }

            /* Free the attribute */
            cssm_free(Attributes->Attribute.Data, 0);

        } /* endif */
    } /* endfor */

    /* Free the attributes array and context */
    cssm_free (Context->ContextAttributes, 0);
    cssm_free (Context, 0);
}


/*---------------------------------------------------------------
 *Name: cssm_GetContext
 *
 *Description:
 *  Given a context handle, find the context 
 *
 *Parameters: 
 *  CCHandle (input) - the context handle
 *
 *Returns:
 *  NULL - unable to get context
 *  non NULL - pointer to context
 *
 *-------------------------------------------------------------*/
CSSM_CONTEXT_PTR cssm_GetContext (CSSM_CC_HANDLE CCHandle)
{
    cssm_CONTEXT_NODE_PTR TempContext;

    /* Make sure that app has done a CSSM_Init */
    if (cssm_CheckInit () == CSSM_FAIL)
        return NULL;

    /* Clear the error */
    CSSM_ClearError ();

    /* Find the handle in the context list */
    TempContext = ContextHead;
    while (TempContext) {
        if (TempContext->ContextHandle == CCHandle)
            break;
        TempContext = TempContext->Next;
    }

    /* If the handle wasn't found, return an error */
    if (!TempContext) {
        CSSM_SetError (&CssmGUID, CSSM_INVALID_CONTEXT_HANDLE);
        return NULL;
    }

    /* Return */
    return TempContext->Context;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -