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
);
104 class AuthItem
: public RefCount
106 friend class AuthItemRef
;
108 AuthItem(const AuthItem
& item
);
110 AuthItem(const AuthorizationItem
&item
);
111 AuthItem(AuthorizationString name
);
112 AuthItem(AuthorizationString name
, AuthorizationValue value
);
113 AuthItem(AuthorizationString name
, AuthorizationValue value
, AuthorizationFlags flags
);
115 bool operator < (const AuthItem
&other
) const;
118 AuthItem
&operator = (const AuthItem
&other
);
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
; };
128 AuthorizationString mName
;
129 AuthorizationValue mValue
;
130 AuthorizationFlags mFlags
;
131 mutable bool mOwnsName
;
132 mutable bool mOwnsValue
;
135 bool getString(string
&value
);
136 bool getCssmData(CssmAutoData
&value
);
139 class AuthItemRef
: public RefPointer
<AuthItem
>
142 AuthItemRef(const AuthorizationItem
&item
);
143 AuthItemRef(AuthorizationString name
);
144 AuthItemRef(AuthorizationString name
, AuthorizationValue value
, AuthorizationFlags flags
= 0);
146 bool operator < (const AuthItemRef
&other
) const
148 return **this < *other
;
152 // set should become a member with accessors
153 class AuthItemSet
: public set
<AuthItemRef
>
158 AuthItemSet(const AuthorizationItemSet
*item
);
159 AuthItemSet(const AuthItemSet
& itemSet
);
161 AuthItemSet
&operator = (const AuthorizationItemSet
& itemSet
);
162 AuthItemSet
&operator = (const AuthItemSet
& itemSet
);
165 AuthItem
*find(const char *name
);
168 class FindAuthItemByRightName
171 FindAuthItemByRightName(const char *find_name
) : name(find_name
) { }
173 bool operator()( const AuthItemRef
& authitem
)
175 return (!strcmp(name
, authitem
->name()));
177 bool operator()( const AuthorizationItem
* authitem
)
179 return (!strcmp(name
, authitem
->name
));
186 }; // namespace Authorization
188 #endif /* ! _H_AUTHORIZATIONDATA */