Skip to content

Commit

Permalink
Merge branch 'access-control-module-prototype' into access-control-mo…
Browse files Browse the repository at this point in the history
…dule-hookup
  • Loading branch information
mlepage-google committed Oct 15, 2021
2 parents 25ccc69 + 6ec8954 commit 30556bf
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/access/AccessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CHIP_ERROR AccessControl::Check(const SubjectDescriptor & subjectDescriptor, con
{
CHIP_ERROR err = CHIP_ERROR_ACCESS_DENIED;

EntryIterator* iterator = mDataProvider.Entries(subjectDescriptor.fabricIndex);
EntryIterator * iterator = mDataProvider.Entries(subjectDescriptor.fabricIndex);
#if 0
ReturnErrorCodeIf(iterator == nullptr, CHIP_ERROR_INTERNAL);
#else
Expand Down
17 changes: 4 additions & 13 deletions src/access/AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ class AccessControl
* uninitialized DataProvider must be provided, and the module must then be
* initialized before use, and deinitialized when finished.
*/
AccessControl(DataProvider & dataProvider)
: mDataProvider(dataProvider)
{
}
AccessControl(DataProvider & dataProvider) : mDataProvider(dataProvider) {}

AccessControl(const AccessControl &) = delete;
AccessControl & operator=(const AccessControl &) = delete;

/**
* Initialize the access control module. Will also initialize its data
* provider.
*
*
* @retval various errors, probably fatal.
* @retval #CHIP_NO_ERROR on success.
*/
Expand Down Expand Up @@ -84,20 +81,14 @@ class AccessControl
*
* @retval nullptr if configured so.
*/
static AccessControl * GetInstance()
{
return mInstance;
}
static AccessControl * GetInstance() { return mInstance; }

/**
* Set the configured instance, for advanced use (e.g. testing). Does not
* call Init or Finish (so ensure that happens appropriately). The
* configured instance can be cleared (by setting to nullptr).
*/
static void SetInstance(AccessControl * instance)
{
mInstance = instance;
}
static void SetInstance(AccessControl * instance) { mInstance = instance; }

private:
DataProvider & mDataProvider;
Expand Down
6 changes: 3 additions & 3 deletions src/access/AuthMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace access {
*/
enum AuthMode
{
kNone = 0,
kPase = 1 << 5,
kCase = 1 << 6,
kNone = 0,
kPase = 1 << 5,
kCase = 1 << 6,
kGroup = 1 << 7
};

Expand Down
11 changes: 5 additions & 6 deletions src/access/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ namespace access {
struct Config
{

// Data provider implementation used by AccessControl configured instance.
typedef DataProviderImpl DataProvider;
// Data provider implementation used by AccessControl configured instance.
typedef DataProviderImpl DataProvider;

static const int kSubjectsPerEntry = 4;
static const int kSubjectsPerEntry = 4;

static const int kTargetsPerEntry = 3;

static const int kEntriesPerFabric = 3;
static const int kTargetsPerEntry = 3;

static const int kEntriesPerFabric = 3;
};

} // namespace access
Expand Down
16 changes: 8 additions & 8 deletions src/access/DataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ class EntryIterator
/**
* Returns the next entry. Must only be called if a next entry exists (see
* HasNext).
*
*
* @retval the next entry.
*/
virtual Entry& Next() = 0;
virtual Entry & Next() = 0;

/**
* Whether a next entry exists.
*
*
* @retval true if a next entry exists (next can be called).
* @retval false if no next entry exists (next must not be called).
*/
Expand Down Expand Up @@ -124,7 +124,7 @@ class DataProvider

/**
* Initialize the data provider.
*
*
* @retval various errors, probably fatal.
* @retval #CHIP_NO_ERROR on success.
*/
Expand All @@ -137,19 +137,19 @@ class DataProvider

/**
* Get an iterator over all entries.
*
*
* @retval iterator, release when finished.
* @retval nullptr if error, probably fatal, generally should not happen.
*/
virtual EntryIterator* Entries() const = 0;
virtual EntryIterator * Entries() const = 0;

/**
* Get an iterator over all entries for a particular fabric.
*
*
* @retval iterator, release when finished.
* @retval nullptr if error, probably fatal, generally should not happen.
*/
virtual EntryIterator* Entries(FabricIndex fabricIndex) const = 0;
virtual EntryIterator * Entries(FabricIndex fabricIndex) const = 0;
};

} // namespace access
Expand Down
8 changes: 3 additions & 5 deletions src/access/DataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ CHIP_ERROR DataProviderImpl::Init()
return CHIP_NO_ERROR;
}

void DataProviderImpl::Finish()
{
}
void DataProviderImpl::Finish() {}

EntryIterator* DataProviderImpl::Entries() const
EntryIterator * DataProviderImpl::Entries() const
{
// TODO: provide iterator
return nullptr;
}

EntryIterator* DataProviderImpl::Entries(FabricIndex fabricIndex) const
EntryIterator * DataProviderImpl::Entries(FabricIndex fabricIndex) const
{
// TODO: provide iterator
return nullptr;
Expand Down
6 changes: 3 additions & 3 deletions src/access/DataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ namespace access {
class DataProviderImpl : public DataProvider
{
public:
DataProviderImpl() = default;
DataProviderImpl() = default;
virtual ~DataProviderImpl() = default;

CHIP_ERROR Init() override;
void Finish() override;

EntryIterator* Entries() const override;
EntryIterator* Entries(FabricIndex fabricIndex) const override;
EntryIterator * Entries() const override;
EntryIterator * Entries(FabricIndex fabricIndex) const override;
};

} // namespace access
Expand Down
8 changes: 4 additions & 4 deletions src/access/Privilege.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace access {
*/
enum Privilege
{
kView = 1 << 0,
kProxyView = 1 << 1,
kOperate = 1 << 2,
kManage = 1 << 3,
kView = 1 << 0,
kProxyView = 1 << 1,
kOperate = 1 << 2,
kManage = 1 << 3,
kAdminister = 1 << 4
};

Expand Down
2 changes: 1 addition & 1 deletion src/access/RequestPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct RequestPath
{
// TODO: don't worry about node for now (proxy source)
EndpointId endpoint = 0;
ClusterId cluster = 0;
ClusterId cluster = 0;
};

} // namespace access
Expand Down
4 changes: 2 additions & 2 deletions src/access/SubjectDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace access {

/**
* @typedef SubjectId
*
*
* @brief Access control subject identifier. Can store a PasscodeId, NodeId,
* CatId, GroupId, etc. as appropriate.
*/
typedef uint64_t SubjectId;

/**
* @class SubjectDescriptor
*
*
* @brief Access control subject descriptor.
*/
struct SubjectDescriptor
Expand Down
4 changes: 1 addition & 3 deletions src/access/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import("${chip_root}/build/chip/chip_test_suite.gni")
chip_test_suite("tests") {
output_name = "libaccesstest"

test_sources = [
"TestAccessControl.cpp",
]
test_sources = [ "TestAccessControl.cpp" ]

cflags = [ "-Wconversion" ]

Expand Down
Loading

0 comments on commit 30556bf

Please sign in to comment.