]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/keyclient.h
Security-54.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 AclBearer, 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 CssmKeySize sizeInBits() const;
49
50 // Acl manipulation
51 void getAcl(AutoAclEntryInfoList &aclInfos, const char *selectionTag = NULL) const;
52 void changeAcl(const CSSM_ACL_EDIT &aclEdit,
53 const CSSM_ACCESS_CREDENTIALS *accessCred);
54
55 // Acl owner manipulation
56 void getOwner(AutoAclOwnerPrototype &owner) const;
57 void changeOwner(const CSSM_ACL_OWNER_PROTOTYPE &newOwner,
58 const CSSM_ACCESS_CREDENTIALS *accessCred = NULL);
59
60 // Call this after completing the CSSM API call after having called Key::makeNewKey()
61 void activate();
62
63 protected:
64 void deactivate();
65 };
66
67 class Key : public Object
68 {
69 public:
70 typedef KeyImpl Impl;
71 explicit Key(Impl *impl) : Object(impl) {}
72
73 Key() : Object(NULL) {}
74 Key(const CSP &csp, CSSM_KEY &key) : Object(new Impl(csp, key)) {}
75 Key(const CSP &csp, CSSM_DATA &keyData) : Object(new Impl(csp, keyData)) {}
76
77 // Creates an inactive key, client must call activate() after this.
78 Key(const CSP &csp) : Object(new Impl(csp)) {}
79
80 Impl *operator ->() const { return (*this) ? &impl<Impl>() : NULL; }
81 Impl &operator *() const { return impl<Impl>(); }
82
83 // Conversion operators to CssmKey baseclass.
84 operator const CssmKey * () const { return (*this) ? &(**this) : NULL; }
85 operator const CssmKey & () const { return **this; }
86
87 // Creates an inactive key, client must call activate() after this.
88 CssmKey *makeNewKey(const CSP &csp) { (*this) = Key(csp); return &(**this); }
89
90 // inquiries
91 CssmKeySize sizeInBits() const { return (*this)->sizeInBits(); }
92 };
93
94
95 struct KeySpec
96 {
97 uint32 usage;
98 uint32 attributes;
99 const CssmData *label;
100 //add rc context
101
102 KeySpec(uint32 u, uint32 a) : usage(u), attributes(a), label(NULL) { }
103 KeySpec(uint32 u, uint32 a, const CssmData &l) : usage(u), attributes(a), label(&l) { }
104 };
105
106 } // end namespace CssmClient
107
108 } // end namespace Security
109
110
111 #endif // _H_CDSA_CLIENT_KEYCLIENT