]>
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>
27 #ifdef _CPP_CSSMWALKERS
39 // Walk an INLINE CSSM_DATA by dealing with the data it points to.
40 // Note that this is not the walker for an OUT OF LINE CSSM_DATA,
41 // which is quite regular and handled below.
43 template <class Action
>
44 void walk(Action
&operate
, CSSM_DATA
&data
)
47 operate(p
, data
.Length
);
48 data
.Data
= reinterpret_cast<unsigned char *>(p
);
53 // Walking a C string is almost regular (the size comes from strlen()).
55 template <class Action
>
56 char *walk(Action
&operate
, char * &s
)
58 // A string's length is obtained by reading the string value.
59 // We must honor the operator's preference for not calculating length
60 // (e.g. because s won't be valid until some magic thing was done to it).
61 operate(s
, operate
.needsSize
? (strlen(s
) + 1) : 0);
67 // We "walk" an integer by simply returning it unchanged.
68 // This is a degenerate special case that makes some templated
69 // uses of walking easier (notably for Context use). Note that
70 // the action is never called, so operations don't need to be able
71 // to cope with integer (non-ref) arguments. This is strictly for
72 // notational convenience.
74 template <class Action
>
75 uint32
walk(Action
&, uint32 arg
)
82 // Flattener functions for common CSSM data types that have internal
83 // structure. (The flat ones are handled by the default above.)
85 template <class Action
>
86 CssmData
*walk(Action
&operate
, CssmData
* &data
)
93 template <class Action
>
94 CSSM_DATA
*walk(Action
&operate
, CSSM_DATA
* &data
)
95 { return walk(operate
, CssmData::overlayVar(data
)); }
97 template <class Action
>
98 CssmKey
*walk(Action
&operate
, CssmKey
* &key
)
101 walk(operate
, static_cast<CssmData
&>(*key
));
105 template <class Action
>
106 CSSM_KEY
*walk(Action
&operate
, CSSM_KEY
* &data
)
107 { return walk(operate
, CssmKey::overlayVar(data
)); }
109 template <class Action
>
110 CssmCryptoData
*walk(Action
&operate
, CssmCryptoData
* &data
)
113 walk(operate
, data
->param());
117 template <class Action
>
118 CSSM_CRYPTO_DATA
*walk(Action
&operate
, CSSM_CRYPTO_DATA
* &data
)
119 { return walk(operate
, CssmCryptoData::overlayVar(data
)); }
122 } // end namespace DataWalkers
124 } // end namespace Security
126 #ifdef _CPP_CSSMWALKERS
130 #endif //_H_CSSMWALKERS