Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / transport / StorablePeerConnection.h
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
18 #pragma once
19
20 #include <core/CHIPPersistentStorageDelegate.h>
21 #include <transport/PASESession.h>
22
23 namespace chip {
24
25 // KVS store is sensitive to length of key strings, based on the underlying
26 // platform. Keeping them short.
27 constexpr char kStorablePeerConnectionKeyPrefix[] = "CHIPCnxn";
28 constexpr char kStorablePeerConnectionCountKey[]  = "CHIPNxtCnxn";
29
30 class DLL_EXPORT StorablePeerConnection
31 {
32 public:
33     StorablePeerConnection() {}
34
35     StorablePeerConnection(PASESession & session, Transport::AdminId admin);
36
37     virtual ~StorablePeerConnection() {}
38
39     CHIP_ERROR StoreIntoKVS(PersistentStorageDelegate & kvs);
40
41     CHIP_ERROR FetchFromKVS(PersistentStorageDelegate & kvs, uint16_t keyId);
42
43     static CHIP_ERROR DeleteFromKVS(PersistentStorageDelegate & kvs, uint16_t keyId);
44
45     void GetPASESession(PASESession * session) { session->FromSerializable(mSession.mOpCreds); }
46
47     Transport::AdminId GetAdminId() { return mSession.mAdmin; }
48
49 private:
50     static constexpr size_t KeySize();
51
52     static CHIP_ERROR GenerateKey(uint16_t id, char * key, size_t len);
53
54     struct StorableSession
55     {
56         PASESessionSerializable mOpCreds;
57         Transport::AdminId mAdmin; /* This field is serialized in LittleEndian byte order */
58     };
59
60     StorableSession mSession;
61     uint16_t mKeyId;
62 };
63
64 } // namespace chip