3 * Copyright (c) 2021 Project CHIP Authors
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * This file defines functions for encoding and decoding CHIP messages.
22 * The encoded messages contain CHIP packet header, encrypted payload
23 * header, encrypted payload and message authentication code, as per
24 * CHIP specifications.
30 #include <transport/PeerConnectionState.h>
34 namespace SecureMessageCodec {
38 * Attach payload header to the message and encrypt the message buffer using
39 * key from the connection state.
41 * @param localNodeId Node Id of local node
42 * @param state The connection state with peer node
43 * @param payloadHeader Reference to the payload header that should be inserted in
45 * @param packetHeader Reference to the packet header that contains unencrypted
46 * portion of the message header
47 * @param msgBuf The message buffer that contains the unencrypted message. If
48 * the operation is successuful, this buffer will contain the
50 * @ return CHIP_ERROR The result of the encode operation
52 CHIP_ERROR Encode(NodeId localNodeId, Transport::PeerConnectionState * state, PayloadHeader & payloadHeader,
53 PacketHeader & packetHeader, System::PacketBufferHandle & msgBuf);
57 * Decrypt the message, perform message integrity check, and decode the payload header.
59 * @param state The connection state with peer node
60 * @param payloadHeader Reference to the payload header that should be inserted in
62 * @param packetHeader Reference to the packet header that contains unencrypted
63 * portion of the message header
64 * @param msgBuf The message buffer that contains the encrypted message. If
65 * the operation is successuful, this buffer will contain the
66 * unencrypted message.
67 * @ return CHIP_ERROR The result of the decode operation
69 CHIP_ERROR Decode(Transport::PeerConnectionState * state, PayloadHeader & payloadHeader, const PacketHeader & packetHeader,
70 System::PacketBufferHandle & msgBuf);
71 } // namespace SecureMessageCodec