]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cdsa_utilities/lib/AuthorizationData.h
Security-59306.101.1.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_utilities / lib / AuthorizationData.h
1 /*
2 * Copyright (c) 2000,2002-2006,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 /*
26 * AuthorizationData.h
27 * Authorization
28 */
29
30 #ifndef _H_AUTHORIZATIONDATA
31 #define _H_AUTHORIZATIONDATA 1
32
33 #include <Security/Authorization.h>
34 #include <Security/AuthorizationPlugin.h>
35 #include <security_cdsa_utilities/cssmdata.h>
36 #include <CoreFoundation/CFDate.h>
37
38 #include <security_utilities/refcount.h>
39 #include <security_utilities/alloc.h>
40
41 #include <map>
42 #include <set>
43 #include <string>
44
45 // ptrdiff_t needed, so including STL type closest
46 #include <vector>
47
48 // @@@ Should consider making the various types better citizens by taking an Allocator, for now values are wiped.
49
50 namespace Authorization
51 {
52
53 class AuthValueOverlay : public AuthorizationValue
54 {
55 public:
56 AuthValueOverlay(const string& stringValue) { length = stringValue.length(); data = const_cast<char *>(stringValue.c_str()); }
57 AuthValueOverlay(UInt32 inLength, void *inData) { length = inLength; data = inData; }
58 };
59
60 class AuthValueRef;
61
62 class AuthValue : public RefCount
63 {
64 friend class AuthValueRef;
65 private:
66 AuthValue(const AuthValue& value) {}
67 protected:
68 AuthValue(const AuthorizationValue &value);
69 AuthValue(UInt32 length, void *data);
70 public:
71 AuthValue &operator = (const AuthValue &other);
72 ~AuthValue();
73 void fillInAuthorizationValue(AuthorizationValue &value);
74 const AuthorizationValue& value() const { return mValue; }
75 private:
76 AuthorizationValue mValue;
77 mutable bool mOwnsValue;
78 };
79
80 // AuthValueRef impl
81 class AuthValueRef : public RefPointer<AuthValue>
82 {
83 public:
84 AuthValueRef(const AuthValue &value);
85 AuthValueRef(const AuthorizationValue &value);
86 AuthValueRef(UInt32 length, void *data);
87 };
88
89
90 // vector should become a member with accessors
91 class AuthValueVector : public vector<AuthValueRef>
92 {
93 public:
94 AuthValueVector() {}
95 ~AuthValueVector() {}
96
97 AuthValueVector &operator = (const AuthorizationValueVector& valueVector);
98 };
99
100
101
102 class AuthItemRef;
103
104 class AuthItem : public RefCount
105 {
106 friend class AuthItemRef;
107 private:
108 AuthItem(const AuthItem& item);
109 protected:
110 AuthItem(const AuthorizationItem &item);
111 AuthItem(AuthorizationString name);
112 AuthItem(AuthorizationString name, AuthorizationValue value);
113 AuthItem(AuthorizationString name, AuthorizationValue value, AuthorizationFlags flags);
114
115 bool operator < (const AuthItem &other) const;
116
117 public:
118 AuthItem &operator = (const AuthItem &other);
119 ~AuthItem();
120
121 AuthorizationString name() const { return mName; }
122 const AuthorizationValue& value() const { return mValue; }
123 string stringValue() const { return string(static_cast<char *>(mValue.data), mValue.length); }
124 AuthorizationFlags flags() const { return mFlags; }
125 void setFlags(AuthorizationFlags inFlags) { mFlags = inFlags; };
126
127 private:
128 AuthorizationString mName;
129 AuthorizationValue mValue;
130 AuthorizationFlags mFlags;
131 mutable bool mOwnsName;
132 mutable bool mOwnsValue;
133
134 public:
135 bool getString(string &value);
136 bool getCssmData(CssmAutoData &value);
137 };
138
139 class AuthItemRef : public RefPointer<AuthItem>
140 {
141 public:
142 AuthItemRef(const AuthorizationItem &item);
143 AuthItemRef(AuthorizationString name);
144 AuthItemRef(AuthorizationString name, AuthorizationValue value, AuthorizationFlags flags = 0);
145
146 bool operator < (const AuthItemRef &other) const
147 {
148 return **this < *other;
149 }
150 };
151
152 // set should become a member with accessors
153 class AuthItemSet : public set<AuthItemRef>
154 {
155 public:
156 AuthItemSet();
157 ~AuthItemSet();
158 AuthItemSet(const AuthorizationItemSet *item);
159 AuthItemSet(const AuthItemSet& itemSet);
160
161 AuthItemSet &operator = (const AuthorizationItemSet& itemSet);
162 AuthItemSet &operator = (const AuthItemSet& itemSet);
163
164 public:
165 AuthItem *find(const char *name);
166 };
167
168 class FindAuthItemByRightName
169 {
170 public:
171 FindAuthItemByRightName(const char *find_name) : name(find_name) { }
172
173 bool operator()( const AuthItemRef& authitem )
174 {
175 return (!strcmp(name, authitem->name()));
176 }
177 bool operator()( const AuthorizationItem* authitem )
178 {
179 return (!strcmp(name, authitem->name));
180 }
181
182 private:
183 const char *name;
184 };
185
186 }; // namespace Authorization
187
188 #endif /* ! _H_AUTHORIZATIONDATA */