]> git.saurik.com Git - apple/security.git/blob - SecurityServer/Authorization/AuthorizationData.h
Security-54.tar.gz
[apple/security.git] / SecurityServer / Authorization / AuthorizationData.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 * AuthorizationData.h
21 * Authorization
22 *
23 * Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved
24 *
25 */
26
27 #ifndef _H_AUTHORIZATIONDATA
28 #define _H_AUTHORIZATIONDATA 1
29
30 #include <Security/Authorization.h>
31 #include <Security/AuthorizationPlugin.h>
32
33 // ptrdiff_t needed, so including STL type closest
34 #include <vector>
35
36 namespace Authorization
37 {
38
39
40 class MutableRightSet;
41 class RightSet;
42
43 class Right : protected AuthorizationItem
44 {
45 friend class MutableRightSet;
46 friend class RightSet;
47 public:
48 static Right &overlay(AuthorizationItem &item);
49 static Right *overlay(AuthorizationItem *item);
50 Right();
51 Right(AuthorizationString name, size_t valueLength, const void *value);
52 ~Right();
53
54 bool operator < (const Right &other) const;
55 AuthorizationString rightName() const { return name; }
56 size_t argumentLength() const { return valueLength; }
57 const void *argument() const { return value; }
58 };
59
60
61 /* A RightSet is a Container and a Back Insertion Sequence, but it is not a Sequence. Also it only
62 implements the const members of Container and Back Insertion Sequence. */
63 class RightSet
64 {
65 friend class MutableRightSet;
66 public:
67 // Container required memebers
68 typedef Right value_type;
69 typedef const Right &const_reference;
70 typedef const Right *const_pointer;
71 typedef const_pointer const_iterator;
72 typedef ptrdiff_t difference_type;
73 typedef size_t size_type;
74
75 RightSet(const AuthorizationRights *rights = NULL);
76 RightSet(const RightSet &other);
77 ~RightSet();
78
79 size_type size() const { return mRights->count; }
80 size_type max_size() const { return INT_MAX; }
81 const_iterator begin() const { return static_cast<const_pointer>(mRights->items); }
82 const_iterator end() const { return static_cast<const_pointer>(&mRights->items[mRights->count]); }
83 bool empty() const { return size() == 0; }
84
85 // Back Insertion Sequence required memebers
86 const_reference back() const;
87
88 // Other convenience members
89 operator const AuthorizationRights *() const { return mRights; }
90 private:
91 RightSet &operator = (const RightSet &other);
92
93 protected:
94 static const AuthorizationRights gEmptyRights;
95 AuthorizationRights *mRights;
96 };
97
98
99 /* A MutableRightSet is a Container and a Back Insertion Sequence, but it is not a Sequence. */
100 class MutableRightSet : public RightSet
101 {
102 public:
103 // Container required memebers
104 typedef Right &reference;
105 typedef Right *pointer;
106 typedef pointer iterator;
107
108 MutableRightSet(size_t count = 0, const Right &element = Right());
109 MutableRightSet(const RightSet &other);
110 ~MutableRightSet();
111
112 MutableRightSet &operator = (const RightSet &other);
113
114 iterator begin() { return static_cast<pointer>(mRights->items); }
115 iterator end() { return static_cast<pointer>(&mRights->items[mRights->count]); }
116 void swap(MutableRightSet &other);
117
118 // Back Insertion Sequence required memebers
119 reference back();
120 void push_back(const_reference right);
121 void pop_back();
122
123 // Other convenience members
124 size_type capacity() const { return mCapacity; }
125 private:
126 void grow(size_type min_capacity);
127
128 size_type mCapacity;
129 };
130
131 typedef RightSet AuthItemSet;
132 typedef MutableRightSet MutableAuthItemSet;
133
134 class FindAuthItemByRightName
135 {
136 public:
137 FindAuthItemByRightName(const char *find_name) : name(find_name) { }
138
139 bool operator()( const Right& right )
140 {
141 return (!strcmp(name, right.rightName()));
142 }
143 bool operator()( const AuthorizationItem* item )
144 {
145 return (!strcmp(name, item->name));
146 }
147
148 private:
149 const char *name;
150 };
151
152
153 }; // namespace Authorization
154
155 #endif /* ! _H_AUTHORIZATIONDATA */