]> git.saurik.com Git - apple/security.git/blob - Keychain/Item.h
Security-30.1.tar.gz
[apple/security.git] / Keychain / Item.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 // Item.h
21 //
22 #ifndef _H_DBITEM
23 #define _H_DBITEM
24
25 #include <Security/Keychains.h>
26 #include <Security/PrimaryKey.h>
27 #include <Security/securestorage.h>
28
29 namespace Security
30 {
31
32 using namespace CssmClient;
33
34 namespace KeychainCore
35 {
36 class Item;
37 class Keychain;
38
39 class ItemImpl : public ReferencedObject
40 {
41 friend class Item;
42
43 protected:
44 // new item constructors
45 ItemImpl(SecItemClass itemClass, OSType itemCreator, UInt32 length, const void* data);
46
47 ItemImpl(SecItemClass itemClass, SecKeychainAttributeList *attrList, UInt32 length, const void* data);
48
49 // db item contstructor
50 ItemImpl(const Keychain &keychain, const PrimaryKey &primaryKey, const CssmClient::DbUniqueRecord &uniqueId);
51
52 // PrimaryKey item contstructor
53 ItemImpl(const Keychain &keychain, const PrimaryKey &primaryKey);
54
55 ItemImpl(ItemImpl &item);
56
57 void getAttributeFrom(CssmDbAttributeData *data, SecKeychainAttribute &attr, UInt32 *actualLength);
58 void getClass(SecKeychainAttribute &attr, UInt32 *actualLength);
59
60 protected:
61 // Methods called by KeychainImpl;
62 friend class KeychainImpl;
63
64 // Add the receiver to keychain
65 PrimaryKey add(const Keychain &keychain);
66
67 // Get the default value for an attribute
68 static const CSSM_DATA &defaultAttributeValue(const CSSM_DB_ATTRIBUTE_INFO &info);
69
70 public:
71 ~ItemImpl();
72 bool isPersistant() const;
73 bool isModified() const;
74
75 void update();
76
77 // put a copy of the item into a given keychain
78 Item copyTo(const Keychain &keychain);
79
80 CSSM_DB_RECORDTYPE recordType() const;
81
82 // Used for writing the record to the database.
83 CssmClient::DbUniqueRecord dbUniqueRecord();
84 const CssmClient::DbAttributes *modifiedAttributes() const;
85 const CssmData *modifiedData() const;
86 void didModify(); // Forget any attributes and data we just wrote to the db
87
88 Keychain keychain() const;
89 PrimaryKey primaryKey() const;
90 bool operator <(const ItemImpl &other) const;
91
92 void getAttribute(SecKeychainAttribute& attr, UInt32 *actualLength);
93 void getData(CssmDataContainer& outData);
94
95 void modifyContent(const SecKeychainAttributeList *attrList, UInt32 dataLength, const void *inData);
96 void getContent(SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void **outData);
97 static void freeContent(SecKeychainAttributeList *attrList, void *data);
98 static void freeAttributesAndData(SecKeychainAttributeList *attrList, void *data);
99
100 void getAttributesAndData(SecKeychainAttributeInfo *info, SecItemClass *itemClass, SecKeychainAttributeList **attrList, UInt32 *length, void **outData);
101 void modifyAttributesAndData(const SecKeychainAttributeList *attrList, UInt32 dataLength, const void *inData);
102
103 void setAttribute(SecKeychainAttribute& attr);
104 void setAttribute(const CssmDbAttributeInfo &info, const CssmPolyData &data);
105 void setData(UInt32 length,const void *data);
106
107
108
109 SSGroup group();
110
111
112 protected:
113 void getContent(DbAttributes *dbAttributes, CssmDataContainer *itemData);
114
115 // new item members
116 auto_ptr<CssmDataContainer> mData;
117 auto_ptr<CssmClient::DbAttributes> mDbAttributes;
118
119 // db item members
120 CssmClient::DbUniqueRecord mUniqueId;
121 Keychain mKeychain;
122 PrimaryKey mPrimaryKey;
123
124 };
125
126 class Item : public RefPointer<ItemImpl>
127 {
128 public:
129 Item() {}
130 Item(ItemImpl *impl) : RefPointer<ItemImpl>(impl) {}
131
132 Item(SecItemClass itemClass, OSType itemCreator, UInt32 length, const void* data)
133 : RefPointer<ItemImpl>(new ItemImpl(itemClass, itemCreator, length, data)) {}
134
135 Item(SecItemClass itemClass, SecKeychainAttributeList *attrList, UInt32 length, const void* data)
136 : RefPointer<ItemImpl>(new ItemImpl(itemClass, attrList, length, data)) {}
137
138 Item(const Keychain &keychain, const PrimaryKey &primaryKey, const CssmClient::DbUniqueRecord &uniqueId)
139 : RefPointer<ItemImpl>(new ItemImpl(keychain, primaryKey, uniqueId)) {}
140
141 Item(const Keychain &keychain, const PrimaryKey &primaryKey)
142 : RefPointer<ItemImpl>(new ItemImpl(keychain, primaryKey)) {}
143
144 Item(ItemImpl &item)
145 : RefPointer<ItemImpl>(new ItemImpl(item)) {}
146
147 bool operator <(const Item &other) const { return **this < *other; }
148 bool operator !=(const Item &other) const { return **this < *other || *other < **this; }
149 bool operator ==(const Item &other) const { return !(*this != other); }
150
151 typedef ItemImpl Impl;
152 };
153
154
155 typedef Ref<Item, ItemImpl, SecKeychainItemRef, errSecInvalidItemRef> ItemRef;
156
157
158 }; // end namespace KeychainCore
159
160 } // end namespace Security
161
162 #endif // _H_DBITEM