]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/cssmcred.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // cssmcred - enhanced PodWrappers and construction aids for ACL credentials
25 #include <Security/utilities.h>
26 #include <Security/cssmlist.h>
27 #include <Security/cssmalloc.h>
37 // PodWrappers for samples and sample groups
39 class CssmSample
: public PodWrapper
<CssmSample
, CSSM_SAMPLE
> {
41 CssmSample(const TypedList
&list
)
42 { TypedSample
= list
; Verifier
= NULL
; }
43 CssmSample(const TypedList
&list
, const CssmSubserviceUid
&ver
)
44 { TypedSample
= list
; Verifier
= &ver
; }
46 TypedList
&value() { return TypedList::overlay(TypedSample
); }
47 const TypedList
&value() const { return TypedList::overlay(TypedSample
); }
48 operator TypedList
& () { return value(); }
49 operator const TypedList
& () const { return value(); }
51 const CssmSubserviceUid
*verifier() const { return CssmSubserviceUid::overlay(Verifier
); }
52 const CssmSubserviceUid
* &verifier() { return CssmSubserviceUid::overlayVar(Verifier
); }
55 class SampleGroup
: public PodWrapper
<SampleGroup
, CSSM_SAMPLEGROUP
> {
57 uint32
length() const { return NumberOfSamples
; }
59 const CssmSample
&operator [] (uint32 n
) const
60 { assert(n
< length()); return CssmSample::overlay(Samples
[n
]); }
65 // The PodWrapper for the top-level CSSM credentials structure
67 class AccessCredentials
: public PodWrapper
<AccessCredentials
, CSSM_ACCESS_CREDENTIALS
> {
69 AccessCredentials() { clearPod(); }
71 const char *tag() const { return EntryTag
; }
73 SampleGroup
&samples() { return SampleGroup::overlay(Samples
); }
74 const SampleGroup
&samples() const { return SampleGroup::overlay(Samples
); }
77 static const AccessCredentials
&null
; // all null credential
79 // turn NULL into a null credential if needed
80 static const AccessCredentials
*needed(const CSSM_ACCESS_CREDENTIALS
*cred
)
81 { return cred
? overlay(cred
) : &null
; }
86 // An AccessCredentials object with some construction help.
87 // Note that this is NOT a PodWrapper.
89 class AutoCredentials
: public AccessCredentials
{
91 AutoCredentials(CssmAllocator
&alloc
);
92 AutoCredentials(CssmAllocator
&alloc
, uint32 nSamples
);
94 CssmAllocator
&allocator
;
96 CssmSample
&sample(uint32 n
) { return getSample(n
); }
98 CssmSample
&operator += (const CssmSample
&sample
)
99 { return getSample(samples().length()) = sample
; }
100 TypedList
&operator += (const TypedList
&exhibit
)
101 { return (getSample(samples().length()) = exhibit
).value(); }
105 CssmSample
&getSample(uint32 n
);
107 CssmSample
*sampleArray
;
113 // Walkers for the CSSM API structure types.
114 // Note that there are irrational "const"s strewn about the credential sub-structures.
115 // They make it essentially impossible to incrementally construction them without
116 // violating them. Since we know what we're doing, we do.
118 namespace DataWalkers
121 // CssmSample (with const override)
122 template <class Action
>
123 void walk(Action
&operate
, CssmSample
&sample
)
125 walk(operate
, sample
.value());
126 if (sample
.verifier())
127 walk(operate
, sample
.verifier());
130 template <class Action
>
131 void walk(Action
&operate
, const CssmSample
&sample
)
132 { walk(operate
, const_cast<CssmSample
&>(sample
)); }
135 template <class Action
>
136 void walk(Action
&operate
, SampleGroup
&samples
)
138 operate(samples
.Samples
, samples
.length() * sizeof(CssmSample
));
139 for (uint32 n
= 0; n
< samples
.length(); n
++)
140 walk(operate
, samples
[n
]);
144 template <class Action
>
145 AccessCredentials
*walk(Action
&operate
, AccessCredentials
* &cred
)
148 //@@@ ignoring BaseCerts
149 walk(operate
, cred
->samples());
150 //@@@ ignoring challenge callback
154 template <class Action
>
155 CSSM_ACCESS_CREDENTIALS
*walk(Action
&operate
, CSSM_ACCESS_CREDENTIALS
* &cred
)
156 { return walk(operate
, AccessCredentials::overlayVar(cred
)); }
159 } // end namespace DataWalkers
161 } // end namespace Security