]> git.saurik.com Git - apple/security.git/blame - AppleX509CL/CLCachedEntry.h
Security-163.tar.gz
[apple/security.git] / AppleX509CL / CLCachedEntry.h
CommitLineData
bac41a7b
A
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 * CLCachedEntry.h - classes representing cached certs and CRLs.
21 *
22 * Created 9/1/2000 by Doug Mitchell.
23 * Copyright (c) 2000 by Apple Computer.
24 */
25
26#ifndef _APPLE_X509_CL_CACHED_ENTRY_H_
27#define _APPLE_X509_CL_CACHED_ENTRY_H_
28
29#include <Security/cssmtype.h>
30#include <Security/utilities.h>
31#include <Security/cssmdata.h>
32#include "DecodedCert.h"
df0e469f 33#include "DecodedCrl.h"
bac41a7b
A
34
35/*
36 * There is one of these per active cached object (cert or CRL).
37 * AppleX509CLSession keeps a map of these in cacheMap.
38 */
39class CLCachedEntry
40{
41public:
42 CLCachedEntry();
43 virtual ~CLCachedEntry() { }
44 CSSM_HANDLE handle() { return mHandle; }
45private:
46 CSSM_HANDLE mHandle;
47};
48
49class CLCachedCert : public CLCachedEntry
50{
51public:
52 CLCachedCert(
53 DecodedCert &c) : mCert(c) { }
54 ~CLCachedCert();
55 DecodedCert &cert() { return mCert; }
56private:
df0e469f 57 /* decoded NSS format */
bac41a7b
A
58 DecodedCert &mCert;
59};
60
61class CLCachedCRL : public CLCachedEntry
62{
63public:
64 CLCachedCRL(
df0e469f 65 DecodedCrl &c) : mCrl(c) { }
bac41a7b 66 ~CLCachedCRL();
df0e469f 67 DecodedCrl &crl() { return mCrl; }
bac41a7b 68private:
df0e469f
A
69 /* decoded NSS format */
70 DecodedCrl &mCrl;
bac41a7b
A
71};
72
73/*
74 * An active query, always associated with a CLCachedEntry.
75 * AppleX509CLSession keeps a map of these in queryMap.
76 *
77 * In the case of a CLCachedEntry created by an explicit {Cert,CRL}Cache op,
78 * there can be multiple queries active for a given cached cert. In
79 * the *GetFirst*FieldValue case, there is a one-to-one relationship between
80 * the CLQUery and its associated cached object.
81 *
82 * Out of paranoia in the {Cert,CRL}Cache case, we store the handle of
83 * the associated cached object, not a ref to the object, in case the
84 * cached object has been deleted via *AbortCache. We could ref count,
85 * but that would require a lock in CLCachedEntry...looking up an object
86 * in the session's cache map should not be too expensive.
87 */
88
89typedef enum {
df0e469f 90 CLQ_Cert = 1,
bac41a7b
A
91 CLQ_CRL
92} CLQueryType;
93
94class CLQuery
95{
96public:
97 CLQuery(
98 CLQueryType type,
99 const CssmOid &oid,
100 unsigned numFields,
101 bool isFromCache,
102 CSSM_HANDLE cachedObj);
103
104 ~CLQuery();
105
106 /*
107 * Accessors - all member variables are invariant after creation, except
108 * for nextIndex which can only increment
109 */
110 CLQueryType queryType() { return mQueryType; }
111 const CssmOid &fieldId() { return mFieldId; }
112 unsigned nextIndex() { return mNextIndex; }
113 void incrementIndex(){ mNextIndex++; }
114 unsigned numFields() { return mNumFields; }
115 bool fromCache() { return mFromCache; }
116 CSSM_HANDLE cachedObject() { return mCachedObject; }
117 CSSM_HANDLE handle() { return mHandle;}
118
119private:
120 CLQueryType mQueryType;
121 CssmAutoData mFieldId; // thing we're searching for - may be empty
122 unsigned mNextIndex; // index of next find op
123 unsigned mNumFields; // total available
124 bool mFromCache; // true : via CertGetFirstCachedFieldValue
125 // false : via CertGetFirstFieldValue
126 CSSM_HANDLE mCachedObject; // of our associated cached cert/CRL
127 CSSM_HANDLE mHandle; // ours
128};
129
130#endif /* _APPLE_X509_CL_CACHED_ENTRY_H_ */