]> git.saurik.com Git - apple/security.git/blob - cdsa/cssm/attachfactory.cpp
Security-28.tar.gz
[apple/security.git] / cdsa / cssm / attachfactory.cpp
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // attachfactory - industrial grade production of Attachment objects
21 //
22 #ifdef __MWERKS__
23 #define _CPP_ATTACHFACTORY
24 #endif
25 #include "attachfactory.h"
26
27 #include "cspattachment.h"
28 #include <Security/cssmdli.h>
29 #include <Security/cssmcli.h>
30 #include <Security/cssmaci.h>
31 #include <Security/cssmtpi.h>
32 #include "funcnames.gen"
33 #include <map>
34
35
36 //
37 // A template to generate AttachmentMakers for the standard plugin types.
38 //
39 template <CSSM_SERVICE_TYPE type, typename Table, const char *const nameTable[]>
40 class StandardAttachmentMaker : public AttachmentMaker {
41 public:
42 StandardAttachmentMaker();
43
44 Attachment *make(Module *module,
45 const CSSM_VERSION &version,
46 uint32 subserviceId,
47 CSSM_SERVICE_TYPE subserviceType,
48 const CSSM_API_MEMORY_FUNCS &memoryOps,
49 CSSM_ATTACH_FLAGS attachFlags,
50 CSSM_KEY_HIERARCHY keyHierarchy,
51 CSSM_FUNC_NAME_ADDR *FunctionTable,
52 uint32 NumFunctions)
53 {
54 StandardAttachment<type, Table> *attachment =
55 new StandardAttachment<type, Table>(module,
56 nameMap,
57 version,
58 subserviceId,
59 subserviceType,
60 memoryOps,
61 attachFlags,
62 keyHierarchy);
63 attachment->resolveSymbols(FunctionTable, NumFunctions);
64 return attachment;
65 }
66
67 private:
68 typedef StandardAttachment<type, Table>::NameMap NameMap;
69 NameMap nameMap;
70 };
71
72
73 //
74 // The constructor of the StandardAttachmentMaker builds a dictionary
75 // derived from the plugin type's function name tables.
76 //
77 template <CSSM_SERVICE_TYPE type, typename Table, const char *nameTable[]>
78 StandardAttachmentMaker<type, Table, nameTable>::StandardAttachmentMaker()
79 : AttachmentMaker(type)
80 {
81 for (unsigned n = 0; n < sizeof(nameTable) / sizeof(nameTable[0]); n++)
82 nameMap.insert(NameMap::value_type(nameTable[n], n));
83 }
84
85 //
86 // Implementation of an attachment factory
87 //
88 AttachmentFactory::AttachmentFactory()
89 {
90 // generate explicitly known attachment types
91 factories[CSSM_SERVICE_AC] = new StandardAttachmentMaker<CSSM_SERVICE_AC, CSSM_SPI_AC_FUNCS, ACNameTable>;
92 factories[CSSM_SERVICE_CL] = new StandardAttachmentMaker<CSSM_SERVICE_CL, CSSM_SPI_CL_FUNCS, CLNameTable>;
93 factories[CSSM_SERVICE_CSP] = new StandardAttachmentMaker<CSSM_SERVICE_CSP, CSSM_SPI_CSP_FUNCS, CSPNameTable>;
94 factories[CSSM_SERVICE_DL] = new StandardAttachmentMaker<CSSM_SERVICE_DL, CSSM_SPI_DL_FUNCS, DLNameTable>;
95 factories[CSSM_SERVICE_TP] = new StandardAttachmentMaker<CSSM_SERVICE_TP, CSSM_SPI_TP_FUNCS, TPNameTable>;
96 }
97
98
99 AttachmentMaker *AttachmentFactory::attachmentMakerFor(CSSM_SERVICE_TYPE type) const
100 {
101 AttachFactories::const_iterator it = factories.find(type);
102 if (it == factories.end())
103 CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK);
104 return it->second;
105 }
106
107
108 //
109 // Manage an AttachmentMaker
110 //
111 AttachmentMaker::~AttachmentMaker()
112 {
113 }