LCOV - code coverage report
Current view: top level - app/util - privilege-storage.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 8 8 100.0 %
Date: 2024-02-15 08:20:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  *
       3             :  *    Copyright (c) 2022 Project CHIP Authors
       4             :  *
       5             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6             :  *    you may not use this file except in compliance with the License.
       7             :  *    You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  *    Unless required by applicable law or agreed to in writing, software
      12             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  *    See the License for the specific language governing permissions and
      15             :  *    limitations under the License.
      16             :  */
      17             : 
      18             : #include <lib/core/CHIPConfig.h>
      19             : 
      20             : #include "privilege-storage.h"
      21             : 
      22             : #if !CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES
      23             : #include <zap-generated/access.h>
      24             : #endif // !CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES
      25             : 
      26             : #include <lib/support/CodeUtils.h>
      27             : 
      28             : #include <cstdint>
      29             : 
      30             : using chip::AttributeId;
      31             : using chip::ClusterId;
      32             : using chip::CommandId;
      33             : using chip::EventId;
      34             : 
      35             : namespace {
      36             : 
      37             : #ifdef GENERATED_ACCESS_READ_ATTRIBUTE__CLUSTER
      38             : namespace GeneratedAccessReadAttribute {
      39             : constexpr ClusterId kCluster[]     = GENERATED_ACCESS_READ_ATTRIBUTE__CLUSTER;
      40             : constexpr AttributeId kAttribute[] = GENERATED_ACCESS_READ_ATTRIBUTE__ATTRIBUTE;
      41             : constexpr uint8_t kPrivilege[]     = GENERATED_ACCESS_READ_ATTRIBUTE__PRIVILEGE;
      42             : static_assert(ArraySize(kCluster) == ArraySize(kAttribute) && ArraySize(kAttribute) == ArraySize(kPrivilege),
      43             :               "Generated parallel arrays must be same size");
      44             : } // namespace GeneratedAccessReadAttribute
      45             : #endif
      46             : 
      47             : #ifdef GENERATED_ACCESS_WRITE_ATTRIBUTE__CLUSTER
      48             : namespace GeneratedAccessWriteAttribute {
      49             : constexpr ClusterId kCluster[]     = GENERATED_ACCESS_WRITE_ATTRIBUTE__CLUSTER;
      50             : constexpr AttributeId kAttribute[] = GENERATED_ACCESS_WRITE_ATTRIBUTE__ATTRIBUTE;
      51             : constexpr uint8_t kPrivilege[]     = GENERATED_ACCESS_WRITE_ATTRIBUTE__PRIVILEGE;
      52             : static_assert(ArraySize(kCluster) == ArraySize(kAttribute) && ArraySize(kAttribute) == ArraySize(kPrivilege),
      53             :               "Generated parallel arrays must be same size");
      54             : } // namespace GeneratedAccessWriteAttribute
      55             : #endif
      56             : 
      57             : #ifdef GENERATED_ACCESS_INVOKE_COMMAND__CLUSTER
      58             : namespace GeneratedAccessInvokeCommand {
      59             : constexpr ClusterId kCluster[] = GENERATED_ACCESS_INVOKE_COMMAND__CLUSTER;
      60             : constexpr CommandId kCommand[] = GENERATED_ACCESS_INVOKE_COMMAND__COMMAND;
      61             : constexpr uint8_t kPrivilege[] = GENERATED_ACCESS_INVOKE_COMMAND__PRIVILEGE;
      62             : static_assert(ArraySize(kCluster) == ArraySize(kCommand) && ArraySize(kCommand) == ArraySize(kPrivilege),
      63             :               "Generated parallel arrays must be same size");
      64             : } // namespace GeneratedAccessInvokeCommand
      65             : #endif
      66             : 
      67             : #ifdef GENERATED_ACCESS_READ_EVENT__CLUSTER
      68             : namespace GeneratedAccessReadEvent {
      69             : constexpr ClusterId kCluster[] = GENERATED_ACCESS_READ_EVENT__CLUSTER;
      70             : constexpr EventId kEvent[]     = GENERATED_ACCESS_READ_EVENT__EVENT;
      71             : constexpr uint8_t kPrivilege[] = GENERATED_ACCESS_READ_EVENT__PRIVILEGE;
      72             : static_assert(ArraySize(kCluster) == ArraySize(kEvent) && ArraySize(kEvent) == ArraySize(kPrivilege),
      73             :               "Generated parallel arrays must be same size");
      74             : } // namespace GeneratedAccessReadEvent
      75             : #endif
      76             : 
      77             : } // anonymous namespace
      78             : 
      79        2476 : int MatterGetAccessPrivilegeForReadAttribute(ClusterId cluster, AttributeId attribute)
      80             : {
      81             : #ifdef GENERATED_ACCESS_READ_ATTRIBUTE__CLUSTER
      82             :     using namespace GeneratedAccessReadAttribute;
      83             :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
      84             :     {
      85             :         if (kCluster[i] == cluster && kAttribute[i] == attribute)
      86             :         {
      87             :             return kPrivilege[i];
      88             :         }
      89             :     }
      90             : #endif
      91        2476 :     return kMatterAccessPrivilegeView;
      92             : }
      93             : 
      94        2434 : int MatterGetAccessPrivilegeForWriteAttribute(ClusterId cluster, AttributeId attribute)
      95             : {
      96             : #ifdef GENERATED_ACCESS_WRITE_ATTRIBUTE__CLUSTER
      97             :     using namespace GeneratedAccessWriteAttribute;
      98             :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
      99             :     {
     100             :         if (kCluster[i] == cluster && kAttribute[i] == attribute)
     101             :         {
     102             :             return kPrivilege[i];
     103             :         }
     104             :     }
     105             : #endif
     106        2434 :     return kMatterAccessPrivilegeOperate;
     107             : }
     108             : 
     109           3 : int MatterGetAccessPrivilegeForInvokeCommand(ClusterId cluster, CommandId command)
     110             : {
     111             : #ifdef GENERATED_ACCESS_INVOKE_COMMAND__CLUSTER
     112             :     using namespace GeneratedAccessInvokeCommand;
     113             :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
     114             :     {
     115             :         if (kCluster[i] == cluster && kCommand[i] == command)
     116             :         {
     117             :             return kPrivilege[i];
     118             :         }
     119             :     }
     120             : #endif
     121           3 :     return kMatterAccessPrivilegeOperate;
     122             : }
     123             : 
     124        2047 : int MatterGetAccessPrivilegeForReadEvent(ClusterId cluster, EventId event)
     125             : {
     126             : #ifdef GENERATED_ACCESS_READ_EVENT__CLUSTER
     127             :     using namespace GeneratedAccessReadEvent;
     128             :     for (size_t i = 0; i < ArraySize(kCluster); ++i)
     129             :     {
     130             :         if (kCluster[i] == cluster && kEvent[i] == event)
     131             :         {
     132             :             return kPrivilege[i];
     133             :         }
     134             :     }
     135             : #endif
     136        2047 :     return kMatterAccessPrivilegeView;
     137             : }

Generated by: LCOV version 1.14