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 * AppleX509CLSession.cpp - general CL session support
21 */
22
23#include "AppleX509CLSession.h"
24#include <security_utilities/debugging.h>
25
26AppleX509CLSession::AppleX509CLSession(
27	CSSM_MODULE_HANDLE theHandle,
28	CssmPlugin &plug,
29	const CSSM_VERSION &version,
30	uint32 subserviceId,
31	CSSM_SERVICE_TYPE subserviceType,
32	CSSM_ATTACH_FLAGS attachFlags,
33	const CSSM_UPCALLS &upcalls)
34		: CLPluginSession(theHandle, plug, version, subserviceId,
35							subserviceType,attachFlags, upcalls)
36{
37}
38
39AppleX509CLSession::~AppleX509CLSession()
40{
41	/* free leftover contents of cache and query maps */
42	CLCachedEntry *cachedCert = cacheMap.removeFirstEntry();
43	while(cachedCert != NULL) {
44		secdebug("clDetach", "CL detach: deleting a cached Cert\n");
45		delete cachedCert;
46		cachedCert = cacheMap.removeFirstEntry();
47	}
48	CLQuery *query = queryMap.removeFirstEntry();
49	while(query != NULL) {
50		secdebug("clDetach", "CL detach: deleting a cached query\n");
51		delete query;
52		query = queryMap.removeFirstEntry();
53	}
54}
55
56CLCachedCert *
57AppleX509CLSession::lookupCachedCert(CSSM_HANDLE handle)
58{
59	CLCachedEntry *entry = cacheMap.lookupEntry(handle);
60	if(entry != NULL) {
61		/*
62		 * we rely on this dynamic cast to detect a bogus lookup
63		 * of a cert via a CRL's handle
64		 */
65		return dynamic_cast<CLCachedCert *>(entry);
66	}
67	else {
68		return NULL;
69	}
70}
71
72CLCachedCRL	*
73AppleX509CLSession::lookupCachedCRL(CSSM_HANDLE handle)
74{
75	CLCachedEntry *entry = cacheMap.lookupEntry(handle);
76	if(entry != NULL) {
77		/*
78		 * we rely on this dynamic cast to detect a bogus lookup
79		 * of a CRL via a cert's handle
80		 */
81		return dynamic_cast<CLCachedCRL *>(entry);
82	}
83	else {
84		return NULL;
85	}
86}
87
88