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