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