]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/keyclient.h
Security-30.1.tar.gz
[apple/security.git] / cdsa / cdsa_client / keyclient.h
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 // keyclient
21 //
22 #ifndef _H_CDSA_CLIENT_KEYCLIENT
23 #define _H_CDSA_CLIENT_KEYCLIENT 1
24
25 #include <Security/aclclient.h>
26 #include <Security/cspclient.h>
27
28 namespace Security
29 {
30
31 namespace CssmClient
32 {
33
34 //
35 // Key
36 //
37 class KeyImpl : public ObjectImpl, public AclClient, public CssmKey
38 {
39 public:
40 KeyImpl(const CSP &csp);
41 KeyImpl(const CSP &csp, CSSM_KEY &key);
42 KeyImpl(const CSP &csp, const CSSM_DATA &keyData);
43 virtual ~KeyImpl();
44
45 CSP csp() const { return parent<CSP>(); }
46 void deleteKey(const CSSM_ACCESS_CREDENTIALS *cred);
47
48 // Acl manipulation
49 void getAcl(const char *selectionTag, AutoAclEntryInfoList &aclInfos) const;
50 void changeAcl(const CSSM_ACCESS_CREDENTIALS *accessCred,
51 const CSSM_ACL_EDIT &aclEdit);
52
53 // Acl owner manipulation
54 void getOwner(AutoAclOwnerPrototype &owner) const;
55 void changeOwner(const CSSM_ACCESS_CREDENTIALS *accessCred,
56 const CSSM_ACL_OWNER_PROTOTYPE &newOwner);
57
58 // Call this after completing the CSSM API call after having called Key::makeNewKey()
59 void activate();
60
61 protected:
62 void deactivate();
63 };
64
65 class Key : public Object
66 {
67 public:
68 typedef KeyImpl Impl;
69 explicit Key(Impl *impl) : Object(impl) {}
70
71 Key() : Object(NULL) {}
72 Key(const CSP &csp, CSSM_KEY &key) : Object(new Impl(csp, key)) {}
73 Key(const CSP &csp, CSSM_DATA &keyData) : Object(new Impl(csp, keyData)) {}
74
75 // Creates an inactive key, client must call activate() after this.
76 Key(const CSP &csp) : Object(new Impl(csp)) {}
77
78 Impl *operator ->() const { return (*this) ? &impl<Impl>() : NULL; }
79 Impl &operator *() const { return impl<Impl>(); }
80
81 // Conversion operators to CssmKey baseclass.
82 operator const CssmKey * () const { return (*this) ? &(**this) : NULL; }
83 operator const CssmKey & () const { return **this; }
84
85 // Creates an inactive key, client must call activate() after this.
86 CssmKey *makeNewKey(const CSP &csp) { (*this) = Key(csp); return &(**this); }
87 };
88
89
90 struct KeySpec
91 {
92 uint32 usage;
93 uint32 attributes;
94 const CssmData *label;
95 //add rc context
96
97 KeySpec(uint32 u, uint32 a) : usage(u), attributes(a), label(NULL) { }
98 KeySpec(uint32 u, uint32 a, const CssmData &l) : usage(u), attributes(a), label(&l) { }
99 };
100
101 } // end namespace CssmClient
102
103 } // end namespace Security
104
105
106 #endif // _H_CDSA_CLIENT_KEYCLIENT