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