]> git.saurik.com Git - apple/security.git/blob - Keychain/PolicyCursor.cpp
8532f1c503b604f8e2835e3e59c88bc8117f5369
[apple/security.git] / Keychain / PolicyCursor.cpp
1 /*
2 * Copyright (c) 2002 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 // PolicyCursor.cpp
20 //
21 #include <Security/PolicyCursor.h>
22 #include <Security/Policies.h>
23 #include <Security/oidsalg.h>
24 #include <Security/tpclient.h>
25
26 using namespace KeychainCore;
27 using namespace CssmClient;
28
29
30 //
31 // This preliminary implementation bypasses MDS and uses
32 // a fixed set of policies known to exist in the one known TP.
33 //
34 struct TheOneTP : public TP {
35 TheOneTP() : TP(gGuidAppleX509TP) { }
36 };
37
38 static ModuleNexus<TheOneTP> theOneTP;
39 static const CssmOid *theOidList[] = {
40 static_cast<const CssmOid *>(&CSSMOID_APPLE_ISIGN),
41 static_cast<const CssmOid *>(&CSSMOID_APPLE_X509_BASIC),
42 static_cast<const CssmOid *>(&CSSMOID_APPLE_TP_SSL),
43 static_cast<const CssmOid *>(&CSSMOID_APPLE_TP_SMIME),
44 static_cast<const CssmOid *>(&CSSMOID_APPLE_TP_EAP),
45 static_cast<const CssmOid *>(&CSSMOID_APPLE_TP_REVOCATION_CRL),
46 NULL // sentinel
47 };
48
49
50 //
51 // Canonical Construction
52 //
53 PolicyCursor::PolicyCursor(const CSSM_OID* oid, const CSSM_DATA* value)
54 : mOid(CssmAllocator::standard()), mOidGiven(false)
55 {
56 if (oid) {
57 mOid = CssmOid::required(oid);
58 mOidGiven = true;
59 }
60 mSearchPos = 0;
61 }
62
63
64 //
65 // Destroy
66 //
67 PolicyCursor::~PolicyCursor() throw()
68 {
69 }
70
71
72 //
73 // Crank the iterator
74 //
75 bool PolicyCursor::next(SecPointer<Policy> &policy)
76 {
77 while (theOidList[mSearchPos]) {
78 if (mOidGiven && mOid != *theOidList[mSearchPos]) {
79 mSearchPos++;
80 continue; // no oid match
81 }
82 // ignoring mValue - not used by current TP
83 policy = new Policy(theOneTP(), *theOidList[mSearchPos]);
84 mSearchPos++; // advance cursor
85 return true; // return next match
86 }
87 return false; // end of table, no more matches
88 }