2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved
27 #ifndef _H_AUTHORIZATIONDATA
28 #define _H_AUTHORIZATIONDATA 1
30 #include <Security/Authorization.h>
31 #include <Security/AuthorizationPlugin.h>
33 // ptrdiff_t needed, so including STL type closest
36 namespace Authorization
40 class MutableRightSet
;
43 class Right
: protected AuthorizationItem
45 friend class MutableRightSet
;
46 friend class RightSet
;
48 static Right
&overlay(AuthorizationItem
&item
);
49 static Right
*overlay(AuthorizationItem
*item
);
51 Right(AuthorizationString name
, size_t valueLength
, const void *value
);
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
; }
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. */
65 friend class MutableRightSet
;
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
;
75 RightSet(const AuthorizationRights
*rights
= NULL
);
76 RightSet(const RightSet
&other
);
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; }
85 // Back Insertion Sequence required memebers
86 const_reference
back() const;
88 // Other convenience members
89 operator const AuthorizationRights
*() const { return mRights
; }
91 RightSet
&operator = (const RightSet
&other
);
94 static const AuthorizationRights gEmptyRights
;
95 AuthorizationRights
*mRights
;
99 /* A MutableRightSet is a Container and a Back Insertion Sequence, but it is not a Sequence. */
100 class MutableRightSet
: public RightSet
103 // Container required memebers
104 typedef Right
&reference
;
105 typedef Right
*pointer
;
106 typedef pointer iterator
;
108 MutableRightSet(size_t count
= 0, const Right
&element
= Right());
109 MutableRightSet(const RightSet
&other
);
112 MutableRightSet
&operator = (const RightSet
&other
);
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
);
118 // Back Insertion Sequence required memebers
120 void push_back(const_reference right
);
123 // Other convenience members
124 size_type
capacity() const { return mCapacity
; }
126 void grow(size_type min_capacity
);
131 typedef RightSet AuthItemSet
;
132 typedef MutableRightSet MutableAuthItemSet
;
134 class FindAuthItemByRightName
137 FindAuthItemByRightName(const char *find_name
) : name(find_name
) { }
139 bool operator()( const Right
& right
)
141 return (!strcmp(name
, right
.rightName()));
143 bool operator()( const AuthorizationItem
* item
)
145 return (!strcmp(name
, item
->name
));
153 }; // namespace Authorization
155 #endif /* ! _H_AUTHORIZATIONDATA */