3 * Copyright (c) 2021 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <core/CHIPPersistentStorageDelegate.h>
21 #include <transport/PASESession.h>
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";
30 class DLL_EXPORT StorablePeerConnection
33 StorablePeerConnection() {}
35 StorablePeerConnection(PASESession & session, Transport::AdminId admin);
37 virtual ~StorablePeerConnection() {}
39 CHIP_ERROR StoreIntoKVS(PersistentStorageDelegate & kvs);
41 CHIP_ERROR FetchFromKVS(PersistentStorageDelegate & kvs, uint16_t keyId);
43 static CHIP_ERROR DeleteFromKVS(PersistentStorageDelegate & kvs, uint16_t keyId);
45 void GetPASESession(PASESession * session) { session->FromSerializable(mSession.mOpCreds); }
47 Transport::AdminId GetAdminId() { return mSession.mAdmin; }
50 static constexpr size_t KeySize();
52 static CHIP_ERROR GenerateKey(uint16_t id, char * key, size_t len);
54 struct StorableSession
56 PASESessionSerializable mOpCreds;
57 Transport::AdminId mAdmin; /* This field is serialized in LittleEndian byte order */
60 StorableSession mSession;