]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/cssmwalkers.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 // cssmwalkers - walkers for standard CSSM datatypes and wrappers
22 #ifndef _H_CSSMWALKERS
23 #define _H_CSSMWALKERS
25 #include <Security/walkers.h>
29 namespace DataWalkers
{
33 // The full set of walkers for CssmData in all its forms.
35 template <class Action
>
36 void walk(Action
&operate
, CssmData
&data
)
39 operate
.blob(data
.Data
, data
.Length
);
42 template <class Action
>
43 CssmData
*walk(Action
&operate
, CssmData
* &data
)
46 operate
.blob(data
->Data
, data
->Length
);
50 template <class Action
>
51 void walk(Action
&operate
, CSSM_DATA
&data
)
52 { walk(operate
, CssmData::overlay(data
)); }
54 template <class Action
>
55 CSSM_DATA
*walk(Action
&operate
, CSSM_DATA
* &data
)
56 { return walk(operate
, CssmData::overlayVar(data
)); }
61 // Walking a C string is almost regular (the size comes from strlen()).
62 // Just make sure you honor the needsSize preference of the operator.
64 template <class Action
>
65 char *walk(Action
&operate
, char * &s
)
67 operate(s
, operate
.needsSize
? (strlen(s
) + 1) : 0);
73 // We "walk" an integer by simply returning it unchanged.
74 // This is a degenerate special case that makes some templated
75 // uses of walking easier (notably for Context use). Note that
76 // the action is never called, so operations don't need to be able
77 // to cope with integer (non-ref) arguments. This is strictly for
78 // notational convenience.
80 template <class Action
>
81 uint32
walk(Action
&, uint32 arg
)
88 // Flattener functions for common CSSM data types that have internal
89 // structure. (The flat ones are handled by the default above.)
91 template <class Action
>
92 CssmKey
*walk(Action
&operate
, CssmKey
* &key
)
95 walk(operate
, static_cast<CssmData
&>(*key
));
99 template <class Action
>
100 CSSM_KEY
*walk(Action
&operate
, CSSM_KEY
* &data
)
101 { return walk(operate
, CssmKey::overlayVar(data
)); }
103 template <class Action
>
104 CssmCryptoData
*walk(Action
&operate
, CssmCryptoData
* &data
)
107 walk(operate
, data
->param());
111 template <class Action
>
112 CSSM_CRYPTO_DATA
*walk(Action
&operate
, CSSM_CRYPTO_DATA
* &data
)
113 { return walk(operate
, CssmCryptoData::overlayVar(data
)); }
115 template <class Action
>
116 CSSM_PKCS5_PBKDF2_PARAMS
*walk(Action
&operate
, CSSM_PKCS5_PBKDF2_PARAMS
* &data
)
119 walk(operate
, data
->Passphrase
);
124 } // end namespace DataWalkers
125 } // end namespace Security
127 #endif //_H_CSSMWALKERS