Example #1
0
//
// Create a new attachment for this module
//
CSSM_HANDLE Module::attach(const CSSM_VERSION &version,
                           uint32 subserviceId,
                           CSSM_SERVICE_TYPE subserviceType,
                           const CSSM_API_MEMORY_FUNCS &memoryOps,
                           CSSM_ATTACH_FLAGS attachFlags,
                           CSSM_KEY_HIERARCHY keyHierarchy,
                           CSSM_FUNC_NAME_ADDR *functionTable,
                           uint32 functionTableSize)
{
    StLock<Mutex> _(mLock);
    
    // check if the module can do this kind of service
    if (!supportsService(subserviceType))
        CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK);

    Attachment *attachment = cssm.attachmentMakerFor(subserviceType)->make(this,
                                   version,
                                   subserviceId, subserviceType,
                                   memoryOps,
                                   attachFlags,
                                   keyHierarchy,
                                   functionTable, functionTableSize);

    try {
        // add to module's attachment map
        attachmentMap.insert(AttachmentMap::value_type(attachment->handle(), attachment));
    } catch (...) {
        delete attachment;
        throw;
    }

    // all done
    return attachment->handle();
}