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