]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/acl_keychain.cpp
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / acl_keychain.cpp
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 // acl_keychain - a subject type for the protected-path
21 // keychain prompt interaction model.
22 //
23 // Arguments in list form:
24 // list[1] = CssmData: Descriptive String
25 //
26 #ifdef __MWERKS__
27 #define _CPP_ACL_KEYCHAIN
28 #endif
29
30 #include <Security/acl_keychain.h>
31 #include <algorithm>
32
33
34 //
35 // Validate a credential set against this subject
36 //
37 bool KeychainPromptAclSubject::validate(const AclValidationContext &,
38 const TypedList &sample) const
39 {
40 return interface.validate(description);
41 }
42
43
44 //
45 // Make a copy of this subject in CSSM_LIST form
46 //
47 CssmList KeychainPromptAclSubject::toList(CssmAllocator &alloc) const
48 {
49 return TypedList(alloc, CSSM_ACL_SUBJECT_TYPE_KEYCHAIN_PROMPT,
50 new(alloc) ListElement(alloc, description));
51 }
52
53
54 //
55 // Create a PasswordAclSubject
56 //
57 KeychainPromptAclSubject *KeychainPromptAclSubject::Maker::make(const TypedList &list) const
58 {
59 ListElement *params[1];
60 crack(list, 1, params, CSSM_LIST_ELEMENT_DATUM);
61 return new KeychainPromptAclSubject(interface, *params[0]);
62 }
63
64 KeychainPromptAclSubject *KeychainPromptAclSubject::Maker::make(Reader &pub, Reader &) const
65 {
66 char *description; pub(description);
67 return new KeychainPromptAclSubject(interface, description);
68 }
69
70 KeychainPromptAclSubject::KeychainPromptAclSubject(KeychainPromptInterface &ifc,
71 string descr)
72 : SimpleAclSubject(CSSM_ACL_SUBJECT_TYPE_KEYCHAIN_PROMPT, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT),
73 interface(ifc), description(descr)
74 {
75 }
76
77
78 //
79 // Export the subject to a memory blob
80 //
81 void KeychainPromptAclSubject::exportBlob(Writer::Counter &pub, Writer::Counter &priv)
82 {
83 pub(description.size() + 1);
84 }
85
86 void KeychainPromptAclSubject::exportBlob(Writer &pub, Writer &priv)
87 {
88 pub(description.c_str());
89 }
90