LCOV - code coverage report
Current view: top level - lib/support - TestGroupData.h (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 0 2 0.0 %
Date: 2024-02-15 08:20:41 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2022 Project CHIP Authors
       4             :  *    All rights reserved.
       5             :  *
       6             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7             :  *    you may not use this file except in compliance with the License.
       8             :  *    You may obtain a copy of the License at
       9             :  *
      10             :  *        http://www.apache.org/licenses/LICENSE-2.0
      11             :  *
      12             :  *    Unless required by applicable law or agreed to in writing, software
      13             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15             :  *    See the License for the specific language governing permissions and
      16             :  *    limitations under the License.
      17             :  */
      18             : 
      19             : #pragma once
      20             : 
      21             : #include <credentials/GroupDataProvider.h>
      22             : #include <crypto/CHIPCryptoPAL.h>
      23             : 
      24             : namespace chip {
      25             : 
      26             : namespace GroupTesting {
      27             : 
      28             : class DefaultIpkValue
      29             : {
      30             : public:
      31             :     DefaultIpkValue() {}
      32             : 
      33           0 :     static ByteSpan GetDefaultIpk()
      34             :     {
      35             :         static const uint8_t mDefaultIpk[Crypto::CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES] = {
      36             :             't', 'e', 'm', 'p', 'o', 'r', 'a', 'r', 'y', ' ', 'i', 'p', 'k', ' ', '0', '1'
      37             :         };
      38           0 :         return ByteSpan(mDefaultIpk);
      39             :     }
      40             : };
      41             : 
      42             : inline CHIP_ERROR InitData(chip::Credentials::GroupDataProvider * provider, chip::FabricIndex fabric_index,
      43             :                            const ByteSpan & compressed_fabric_id)
      44             : {
      45             :     static const chip::GroupId kGroup1   = 0x0101;
      46             :     static const chip::GroupId kGroup2   = 0x0102;
      47             :     static const chip::GroupId kGroup3   = 0x0103;
      48             :     static const chip::KeysetId kKeySet1 = 0x01a1;
      49             :     static const chip::KeysetId kKeySet2 = 0x01a2;
      50             :     static const chip::KeysetId kKeySet3 = 0x01a3;
      51             : 
      52             :     // Groups
      53             : 
      54             :     const chip::Credentials::GroupDataProvider::GroupInfo group1(kGroup1, "Group #1");
      55             :     ReturnErrorOnFailure(provider->SetGroupInfo(fabric_index, group1));
      56             :     ReturnErrorOnFailure(provider->AddEndpoint(fabric_index, group1.group_id, 1));
      57             : 
      58             :     const chip::Credentials::GroupDataProvider::GroupInfo group2(kGroup2, "Group #2");
      59             :     ReturnErrorOnFailure(provider->SetGroupInfo(fabric_index, group2));
      60             :     ReturnErrorOnFailure(provider->AddEndpoint(fabric_index, group2.group_id, 0));
      61             : 
      62             :     const chip::Credentials::GroupDataProvider::GroupInfo group3(kGroup3, "Group #3");
      63             :     ReturnErrorOnFailure(provider->SetGroupInfo(fabric_index, group3));
      64             :     ReturnErrorOnFailure(provider->AddEndpoint(fabric_index, group3.group_id, 0));
      65             : 
      66             :     // Key Sets
      67             : 
      68             :     chip::Credentials::GroupDataProvider::KeySet keyset1(kKeySet1,
      69             :                                                          chip::Credentials::GroupDataProvider::SecurityPolicy::kCacheAndSync, 3);
      70             :     const chip::Credentials::GroupDataProvider::EpochKey epoch_keys1[] = {
      71             :         { 1110000, { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf } },
      72             :         { 1110001, { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf } },
      73             :         { 1110002, { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf } },
      74             :     };
      75             :     memcpy(keyset1.epoch_keys, epoch_keys1, sizeof(epoch_keys1));
      76             :     CHIP_ERROR err = provider->SetKeySet(fabric_index, compressed_fabric_id, keyset1);
      77             :     ReturnErrorOnFailure(err);
      78             : 
      79             :     chip::Credentials::GroupDataProvider::KeySet keyset2(kKeySet2,
      80             :                                                          chip::Credentials::GroupDataProvider::SecurityPolicy::kCacheAndSync, 3);
      81             :     const chip::Credentials::GroupDataProvider::EpochKey epoch_keys2[] = {
      82             :         { 2220000, { 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf } },
      83             :         { 2220001, { 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef } },
      84             :         { 2220002, { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff } },
      85             :     };
      86             :     memcpy(keyset2.epoch_keys, epoch_keys2, sizeof(epoch_keys2));
      87             :     err = provider->SetKeySet(fabric_index, compressed_fabric_id, keyset2);
      88             :     ReturnErrorOnFailure(err);
      89             : 
      90             :     chip::Credentials::GroupDataProvider::KeySet keyset3(kKeySet3,
      91             :                                                          chip::Credentials::GroupDataProvider::SecurityPolicy::kTrustFirst, 3);
      92             :     const chip::Credentials::GroupDataProvider::EpochKey epoch_keys3[] = {
      93             :         { 2220000, { 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf } },
      94             :         { 2220001, { 0xd1, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf } },
      95             :         { 2220002, { 0xd2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf } },
      96             :     };
      97             :     memcpy(keyset3.epoch_keys, epoch_keys3, sizeof(epoch_keys3));
      98             :     err = provider->SetKeySet(fabric_index, compressed_fabric_id, keyset3);
      99             :     ReturnErrorOnFailure(err);
     100             : 
     101             :     provider->SetGroupKeyAt(fabric_index, 0, chip::Credentials::GroupDataProvider::GroupKey(kGroup1, kKeySet1));
     102             :     provider->SetGroupKeyAt(fabric_index, 1, chip::Credentials::GroupDataProvider::GroupKey(kGroup2, kKeySet2));
     103             :     provider->SetGroupKeyAt(fabric_index, 2, chip::Credentials::GroupDataProvider::GroupKey(kGroup3, kKeySet3));
     104             : 
     105             :     return CHIP_NO_ERROR;
     106             : }
     107             : 
     108             : } // namespace GroupTesting
     109             : 
     110             : } // namespace chip

Generated by: LCOV version 1.14