/src/connectedhomeip/src/credentials/DeviceAttestationCredsProvider.cpp
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (c) 2021 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 | | #include "DeviceAttestationCredsProvider.h" |
18 | | |
19 | | namespace chip { |
20 | | namespace Credentials { |
21 | | |
22 | | namespace { |
23 | | |
24 | | // Version to have a default placeholder so the getter never |
25 | | // returns `nullptr` by default. |
26 | | class UnimplementedDACProvider : public DeviceAttestationCredentialsProvider |
27 | | { |
28 | | public: |
29 | | CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & out_cd_buffer) override |
30 | 0 | { |
31 | 0 | (void) out_cd_buffer; |
32 | 0 | return CHIP_ERROR_NOT_IMPLEMENTED; |
33 | 0 | } |
34 | | |
35 | | CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override |
36 | 0 | { |
37 | 0 | (void) out_firmware_info_buffer; |
38 | 0 | return CHIP_ERROR_NOT_IMPLEMENTED; |
39 | 0 | } |
40 | | |
41 | | CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & out_dac_buffer) override |
42 | 0 | { |
43 | 0 | (void) out_dac_buffer; |
44 | 0 | return CHIP_ERROR_NOT_IMPLEMENTED; |
45 | 0 | } |
46 | | |
47 | | CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & out_pai_buffer) override |
48 | 0 | { |
49 | 0 | (void) out_pai_buffer; |
50 | 0 | return CHIP_ERROR_NOT_IMPLEMENTED; |
51 | 0 | } |
52 | | |
53 | | CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & message_to_sign, MutableByteSpan & out_signature_buffer) override |
54 | 0 | { |
55 | 0 | (void) message_to_sign; |
56 | 0 | (void) out_signature_buffer; |
57 | 0 | return CHIP_ERROR_NOT_IMPLEMENTED; |
58 | 0 | } |
59 | | }; |
60 | | |
61 | | // Default to avoid nullptr on getter and cleanly handle new products/clients before |
62 | | // they provide their own. |
63 | | UnimplementedDACProvider gDefaultDACProvider; |
64 | | |
65 | | DeviceAttestationCredentialsProvider * gDacProvider = &gDefaultDACProvider; |
66 | | |
67 | | } // namespace |
68 | | |
69 | | DeviceAttestationCredentialsProvider * GetDeviceAttestationCredentialsProvider() |
70 | 0 | { |
71 | 0 | return gDacProvider; |
72 | 0 | } |
73 | | |
74 | | void SetDeviceAttestationCredentialsProvider(DeviceAttestationCredentialsProvider * provider) |
75 | 0 | { |
76 | 0 | if (provider == nullptr) |
77 | 0 | { |
78 | 0 | return; |
79 | 0 | } |
80 | | |
81 | 0 | gDacProvider = provider; |
82 | 0 | } |
83 | | |
84 | | bool IsDeviceAttestationCredentialsProviderSet() |
85 | 0 | { |
86 | 0 | return (gDacProvider != &gDefaultDACProvider); |
87 | 0 | } |
88 | | |
89 | | } // namespace Credentials |
90 | | } // namespace chip |