2 * Copyright (c) 2000,2002-2006,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
30 #ifndef _H_AUTHORIZATIONDATA
31 #define _H_AUTHORIZATIONDATA 1
33 #include <Security/Authorization.h>
34 #include <Security/AuthorizationPlugin.h>
35 #include <security_cdsa_utilities/cssmdata.h>
36 #include <CoreFoundation/CFDate.h>
38 #include <security_utilities/refcount.h>
39 #include <security_utilities/alloc.h>
45 // ptrdiff_t needed, so including STL type closest
48 // @@@ Should consider making the various types better citizens by taking an Allocator, for now values are wiped.
50 namespace Authorization
53 class AuthValueOverlay
: public AuthorizationValue
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
; }
62 class AuthValue
: public RefCount
64 friend class AuthValueRef
;
66 AuthValue(const AuthValue
& value
) {}
68 AuthValue(const AuthorizationValue
&value
);
69 AuthValue(UInt32 length
, void *data
);
71 AuthValue
&operator = (const AuthValue
&other
);
73 void fillInAuthorizationValue(AuthorizationValue
&value
);
74 const AuthorizationValue
& value() const { return mValue
; }
76 AuthorizationValue mValue
;
77 mutable bool mOwnsValue
;
81 class AuthValueRef
: public RefPointer
<AuthValue
>
84 AuthValueRef(const AuthValue
&value
);
85 AuthValueRef(const AuthorizationValue
&value
);
86 AuthValueRef(UInt32 length
, void *data
);
90 // vector should become a member with accessors
91 class AuthValueVector
: public vector
<AuthValueRef
>
97 AuthValueVector
&operator = (const AuthorizationValueVector
& valueVector
);
99 void copy(AuthorizationValueVector
**data
, size_t *length
) const;
106 class AuthItem
: public RefCount
108 friend class AuthItemRef
;
110 AuthItem(const AuthItem
& item
);
112 AuthItem(const AuthorizationItem
&item
);
113 AuthItem(AuthorizationString name
);
114 AuthItem(AuthorizationString name
, AuthorizationValue value
);
115 AuthItem(AuthorizationString name
, AuthorizationValue value
, AuthorizationFlags flags
);
117 bool operator < (const AuthItem
&other
) const;
120 AuthItem
&operator = (const AuthItem
&other
);
123 void fillInAuthorizationItem(AuthorizationItem
&item
);
125 AuthorizationString
name() const { return mName
; }
126 const AuthorizationValue
& value() const { return mValue
; }
127 string
stringValue() const { return string(static_cast<char *>(mValue
.data
), mValue
.length
); }
128 AuthorizationFlags
flags() const { return mFlags
; }
129 void setFlags(AuthorizationFlags inFlags
) { mFlags
= inFlags
; };
132 AuthorizationString mName
;
133 AuthorizationValue mValue
;
134 AuthorizationFlags mFlags
;
135 mutable bool mOwnsName
;
136 mutable bool mOwnsValue
;
139 bool getBool(bool &value
);
140 bool getString(string
&value
);
141 bool getCssmData(CssmAutoData
&value
);
144 class AuthItemRef
: public RefPointer
<AuthItem
>
147 AuthItemRef(const AuthorizationItem
&item
);
148 AuthItemRef(AuthorizationString name
);
149 AuthItemRef(AuthorizationString name
, AuthorizationValue value
, AuthorizationFlags flags
= 0);
151 bool operator < (const AuthItemRef
&other
) const
153 return **this < *other
;
157 // set should become a member with accessors
158 class AuthItemSet
: public set
<AuthItemRef
>
163 AuthItemSet(const AuthorizationItemSet
*item
);
164 AuthItemSet(const AuthItemSet
& itemSet
);
166 AuthItemSet
&operator = (const AuthorizationItemSet
& itemSet
);
167 AuthItemSet
&operator = (const AuthItemSet
& itemSet
);
169 void copy(AuthorizationItemSet
*&data
, size_t &length
, Allocator
&alloc
= Allocator::standard()) const;
170 AuthorizationItemSet
*copy() const;
175 AuthItem
*find(const char *name
);
178 void duplicate(const AuthItemSet
& itemSet
);
181 class FindAuthItemByRightName
184 FindAuthItemByRightName(const char *find_name
) : name(find_name
) { }
186 bool operator()( const AuthItemRef
& authitem
)
188 return (!strcmp(name
, authitem
->name()));
190 bool operator()( const AuthorizationItem
* authitem
)
192 return (!strcmp(name
, authitem
->name
));
199 }; // namespace Authorization
201 #endif /* ! _H_AUTHORIZATIONDATA */