AuthorizationData.h [plain text]
#ifndef _H_AUTHORIZATIONDATA
#define _H_AUTHORIZATIONDATA 1
#include <Security/Authorization.h>
#include <Security/AuthorizationPlugin.h>
#include <vector>
namespace Authorization
{
class MutableRightSet;
class RightSet;
class Right : protected AuthorizationItem
{
friend class MutableRightSet;
friend class RightSet;
public:
static Right &overlay(AuthorizationItem &item);
static Right *overlay(AuthorizationItem *item);
Right();
Right(AuthorizationString name, size_t valueLength, const void *value);
~Right();
bool operator < (const Right &other) const;
AuthorizationString rightName() const { return name; }
size_t argumentLength() const { return valueLength; }
const void *argument() const { return value; }
};
class RightSet
{
friend class MutableRightSet;
public:
typedef Right value_type;
typedef const Right &const_reference;
typedef const Right *const_pointer;
typedef const_pointer const_iterator;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
RightSet(const AuthorizationRights *rights = NULL);
RightSet(const RightSet &other);
~RightSet();
size_type size() const { return mRights->count; }
size_type max_size() const { return INT_MAX; }
const_iterator begin() const { return static_cast<const_pointer>(mRights->items); }
const_iterator end() const { return static_cast<const_pointer>(&mRights->items[mRights->count]); }
bool empty() const { return size() == 0; }
const_reference back() const;
operator const AuthorizationRights *() const { return mRights; }
private:
RightSet &operator = (const RightSet &other);
protected:
static const AuthorizationRights gEmptyRights;
AuthorizationRights *mRights;
};
class MutableRightSet : public RightSet
{
public:
typedef Right &reference;
typedef Right *pointer;
typedef pointer iterator;
MutableRightSet(size_t count = 0, const Right &element = Right());
MutableRightSet(const RightSet &other);
~MutableRightSet();
MutableRightSet &operator = (const RightSet &other);
iterator begin() { return static_cast<pointer>(mRights->items); }
iterator end() { return static_cast<pointer>(&mRights->items[mRights->count]); }
void swap(MutableRightSet &other);
reference back();
void push_back(const_reference right);
void pop_back();
size_type capacity() const { return mCapacity; }
private:
void grow(size_type min_capacity);
size_type mCapacity;
};
typedef RightSet AuthItemSet;
typedef MutableRightSet MutableAuthItemSet;
class FindAuthItemByRightName
{
public:
FindAuthItemByRightName(const char *find_name) : name(find_name) { }
bool operator()( const Right& right )
{
return (!strcmp(name, right.rightName()));
}
bool operator()( const AuthorizationItem* item )
{
return (!strcmp(name, item->name));
}
private:
const char *name;
};
};
#endif