]> git.saurik.com Git - apple/security.git/blob - cdsa/cssm/attachfactory.cpp
Security-163.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() : AttachmentMaker(type)
43 {
44 for (unsigned n = 0; n < sizeof(nameTable) / sizeof(nameTable[0]); n++)
45 nameMap.insert(typename NameMap::value_type(nameTable[n], n));
46 }
47
48 Attachment *make(Module *module,
49 const CSSM_VERSION &version,
50 uint32 subserviceId,
51 CSSM_SERVICE_TYPE subserviceType,
52 const CSSM_API_MEMORY_FUNCS &memoryOps,
53 CSSM_ATTACH_FLAGS attachFlags,
54 CSSM_KEY_HIERARCHY keyHierarchy,
55 CSSM_FUNC_NAME_ADDR *FunctionTable,
56 uint32 NumFunctions)
57 {
58 StandardAttachment<type, Table> *attachment =
59 new StandardAttachment<type, Table>(module,
60 nameMap,
61 version,
62 subserviceId,
63 subserviceType,
64 memoryOps,
65 attachFlags,
66 keyHierarchy);
67 attachment->resolveSymbols(FunctionTable, NumFunctions);
68 return attachment;
69 }
70
71 private:
72 typedef typename StandardAttachment<type, Table>::NameMap NameMap;
73 NameMap nameMap;
74 };
75
76
77 //
78 // Implementation of an attachment factory
79 //
80 AttachmentFactory::AttachmentFactory()
81 {
82 // generate explicitly known attachment types
83 factories[CSSM_SERVICE_AC] = new StandardAttachmentMaker<CSSM_SERVICE_AC, CSSM_SPI_AC_FUNCS, ACNameTable>;
84 factories[CSSM_SERVICE_CL] = new StandardAttachmentMaker<CSSM_SERVICE_CL, CSSM_SPI_CL_FUNCS, CLNameTable>;
85 factories[CSSM_SERVICE_CSP] = new StandardAttachmentMaker<CSSM_SERVICE_CSP, CSSM_SPI_CSP_FUNCS, CSPNameTable>;
86 factories[CSSM_SERVICE_DL] = new StandardAttachmentMaker<CSSM_SERVICE_DL, CSSM_SPI_DL_FUNCS, DLNameTable>;
87 factories[CSSM_SERVICE_TP] = new StandardAttachmentMaker<CSSM_SERVICE_TP, CSSM_SPI_TP_FUNCS, TPNameTable>;
88 }
89
90
91 AttachmentMaker *AttachmentFactory::attachmentMakerFor(CSSM_SERVICE_TYPE type) const
92 {
93 AttachFactories::const_iterator it = factories.find(type);
94 if (it == factories.end())
95 CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK);
96 return it->second;
97 }
98
99
100 //
101 // Manage an AttachmentMaker
102 //
103 AttachmentMaker::~AttachmentMaker()
104 {
105 }