Skip to content

Commit

Permalink
Add 'k' prefix to enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
mlepage-google committed Oct 15, 2021
1 parent 8f6ebd4 commit df86b45
Showing 4 changed files with 51 additions and 51 deletions.
8 changes: 4 additions & 4 deletions src/access/AuthMode.h
Original file line number Diff line number Diff line change
@@ -29,10 +29,10 @@ namespace access {
*/
enum AuthMode
{
None = 0,
Pase = 1 << 5,
Case = 1 << 6,
Group = 1 << 7
kNone = 0,
kPase = 1 << 5,
kCase = 1 << 6,
kGroup = 1 << 7
};

} // namespace access
10 changes: 5 additions & 5 deletions src/access/Privilege.h
Original file line number Diff line number Diff line change
@@ -29,11 +29,11 @@ namespace access {
*/
enum Privilege
{
View = 1 << 0,
ProxyView = 1 << 1,
Operate = 1 << 2,
Manage = 1 << 3,
Administer = 1 << 4
kView = 1 << 0,
kProxyView = 1 << 1,
kOperate = 1 << 2,
kManage = 1 << 3,
kAdminister = 1 << 4
};

} // namespace access
10 changes: 5 additions & 5 deletions src/access/SubjectDescriptor.h
Original file line number Diff line number Diff line change
@@ -39,17 +39,17 @@ typedef uint64_t SubjectId;
*/
struct SubjectDescriptor
{
// Holds PasscodeId if Pase, NodeId if Case, GroupId if Group
// Holds PasscodeId if kPase, NodeId if kCase, GroupId if kGroup
SubjectId subject = 0;

// Holds (optional) CAT1/CAT2 if Case
// Holds (optional) CAT1/CAT2 if kCase
SubjectId subject1 = 0;

// Holds (optional) CAT1/CAT2 if Case
// Holds (optional) CAT1/CAT2 if kCase
SubjectId subject2 = 0;

// Holds AuthMode of subject(s), None if no access
AuthMode authMode = AuthMode::None;
// Holds AuthMode of subject(s), kNone if no access
AuthMode authMode = AuthMode::kNone;

// Holds FabricIndex of fabric, 0 if no fabric
FabricIndex fabricIndex = 0;
74 changes: 37 additions & 37 deletions src/access/tests/TestAccessControl.cpp
Original file line number Diff line number Diff line change
@@ -76,9 +76,9 @@ struct TestTarget
{
enum Flag
{
DeviceType = 1 << 0,
Endpoint = 1 << 1,
Cluster = 1 << 2,
kDeviceType = 1 << 0,
kEndpoint = 1 << 1,
kCluster = 1 << 2,
};

int flags = SENTINEL;
@@ -90,7 +90,7 @@ struct TestTarget
TestTarget Target(EndpointId endpoint, ClusterId cluster)
{
return {
.flags = TestTarget::Endpoint | TestTarget::Cluster,
.flags = TestTarget::kEndpoint | TestTarget::kCluster,
.endpoint = endpoint,
.cluster = cluster
};
@@ -99,20 +99,20 @@ TestTarget Target(EndpointId endpoint, ClusterId cluster)
#if 0
TestTarget Target(EndpointId endpoint)
{
return { .flags = TestTarget::Endpoint, .endpoint = endpoint };
return { .flags = TestTarget::kEndpoint, .endpoint = endpoint };
}

TestTarget Target(ClusterId cluster)
{
return { .flags = TestTarget::Cluster, .cluster = cluster };
return { .flags = TestTarget::kCluster, .cluster = cluster };
}
#endif

struct TestEntryDelegate
{
FabricIndex fabricIndex = 0;
AuthMode authMode = AuthMode::None; // aka SENTINEL
Privilege privilege = Privilege::View;
AuthMode authMode = AuthMode::kNone; // aka SENTINEL
Privilege privilege = Privilege::kView;
TestSubject subjects[Config::kSubjectsPerEntry + 1];
TestTarget targets[Config::kTargetsPerEntry + 1];
};
@@ -121,43 +121,43 @@ TestEntryDelegate entries[] =
{
{
.fabricIndex = 1,
.authMode = AuthMode::Case,
.privilege = Privilege::Administer,
.authMode = AuthMode::kCase,
.privilege = Privilege::kAdminister,
.subjects = { Node(0x1122334455667788) },
},
{
.fabricIndex = 2,
.authMode = AuthMode::Case,
.privilege = Privilege::Administer,
.authMode = AuthMode::kCase,
.privilege = Privilege::kAdminister,
.subjects = { Node(0x8877665544332211) },
},
{
.fabricIndex = 2,
.authMode = AuthMode::Case,
.privilege = Privilege::View,
.authMode = AuthMode::kCase,
.privilege = Privilege::kView,
},
{
.fabricIndex = 1,
.authMode = AuthMode::Pase,
.privilege = Privilege::View,
.authMode = AuthMode::kPase,
.privilege = Privilege::kView,
.targets = { Target(2, ONOFF )},
},
{
.fabricIndex = 1,
.authMode = AuthMode::Case,
.privilege = Privilege::View,
.authMode = AuthMode::kCase,
.privilege = Privilege::kView,
.targets = { Target(1, LEVELCONTROL )},
},
{
.fabricIndex = 1,
.authMode = AuthMode::Case,
.privilege = Privilege::Operate,
.authMode = AuthMode::kCase,
.privilege = Privilege::kOperate,
.targets = { Target(1, COLORCONTROL )},
},
{
.fabricIndex = 1,
.authMode = AuthMode::Case,
.privilege = Privilege::View,
.authMode = AuthMode::kCase,
.privilege = Privilege::kView,
.targets = { Target(2, ONOFF )},
},
{} // sentinel entry
@@ -182,16 +182,16 @@ class TestEntry : public Entry
{
switch (privilege)
{
case Privilege::ProxyView:
return (delegate->privilege == Privilege::ProxyView)
|| (delegate->privilege == Privilege::Administer);
case Privilege::View: if (delegate->privilege == Privilege::View) return true;
case Privilege::kProxyView:
return (delegate->privilege == Privilege::kProxyView)
|| (delegate->privilege == Privilege::kAdminister);
case Privilege::kView: if (delegate->privilege == Privilege::kView) return true;
// fall through
case Privilege::Operate: if (delegate->privilege == Privilege::Operate) return true;
case Privilege::kOperate: if (delegate->privilege == Privilege::kOperate) return true;
// fall through
case Privilege::Manage: if (delegate->privilege == Privilege::Manage) return true;
case Privilege::kManage: if (delegate->privilege == Privilege::kManage) return true;
// fall through
case Privilege::Administer: return delegate->privilege == Privilege::Administer;
case Privilege::kAdminister: return delegate->privilege == Privilege::kAdminister;
}
return false;
}
@@ -216,8 +216,8 @@ class TestEntry : public Entry
return true;
for (; p->flags != SENTINEL; ++p)
{
if (((p->flags & TestTarget::Endpoint) == 0 || p->endpoint == endpoint)
&& ((p->flags & TestTarget::Cluster) == 0 || p->cluster == cluster))
if (((p->flags & TestTarget::kEndpoint) == 0 || p->endpoint == endpoint)
&& ((p->flags & TestTarget::kCluster) == 0 || p->cluster == cluster))
return true;
}
return false;
@@ -250,12 +250,12 @@ class TestEntryIterator : public EntryIterator
{
next = (entry.delegate == nullptr) ? entries : next + 1;

while (next->authMode != AuthMode::None && fabricFiltered && next->fabricIndex != fabricIndex)
while (next->authMode != AuthMode::kNone && fabricFiltered && next->fabricIndex != fabricIndex)
{
++next;
}

if (next->authMode == AuthMode::None)
if (next->authMode == AuthMode::kNone)
{
next = nullptr;
}
@@ -348,15 +348,15 @@ void TestCheck(nlTestSuite * inSuite, void * inContext)
// TODO: make this table driven, add a bunch more test cases

err = context.Check(
{.subject = 0x1122334455667788, .authMode = AuthMode::Case, .fabricIndex = 1},
{.subject = 0x1122334455667788, .authMode = AuthMode::kCase, .fabricIndex = 1},
{.endpoint = 1, .cluster = ONOFF},
Privilege::Administer);
Privilege::kAdminister);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);

err = context.Check(
{.subject = 0x8877665544332211, .authMode = AuthMode::Case, .fabricIndex = 1},
{.subject = 0x8877665544332211, .authMode = AuthMode::kCase, .fabricIndex = 1},
{.endpoint = 1, .cluster = ONOFF},
Privilege::Administer);
Privilege::kAdminister);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ACCESS_DENIED);
}

0 comments on commit df86b45

Please sign in to comment.