From a89758a3fd7c9b9a69b26b139cf74781a1f72909 Mon Sep 17 00:00:00 2001 From: Alami-Amine Date: Mon, 23 Dec 2024 15:37:12 +0100 Subject: [PATCH] comments integration --- src/lib/support/CodeUtils.h | 3 +- src/protocols/secure_channel/CASESession.cpp | 4 +-- src/protocols/secure_channel/CASESession.h | 21 ++++++------ .../secure_channel/tests/TestCASESession.cpp | 34 +++++++++---------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/lib/support/CodeUtils.h b/src/lib/support/CodeUtils.h index cb3591956b3bc0..cd07370fa92ec4 100644 --- a/src/lib/support/CodeUtils.h +++ b/src/lib/support/CodeUtils.h @@ -161,8 +161,7 @@ * * @brief * This is for use when the calling function returns a Variant type. It returns a CHIP_ERROR variant with the corresponding error - * code if the expression returns an error. For a CHIP_ERROR expression, this means any value other - * than CHIP_NO_ERROR. For an integer expression, this means non-zero. + * code if the expression returns an error. * * Example usage: * diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index 46a8b887203bb9..6242cc2aa6199c 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -1162,7 +1162,7 @@ CHIP_ERROR CASESession::PrepareSigma2Resume(EncodeSigma2ResumeInputs & outSigma2 outSigma2ResData.resumptionId = mNewResumptionId; ReturnErrorOnFailure(GenerateSigmaResumeMIC(ByteSpan(mInitiatorRandom), mNewResumptionId, ByteSpan(kKDFS2RKeyInfo), - ByteSpan(kResume2MIC_Nonce), outSigma2ResData.resumeMICSpan)); + ByteSpan(kResume2MIC_Nonce), outSigma2ResData.resumeMIC)); outSigma2ResData.responderMrpConfig = &mLocalMRPConfig.Value(); @@ -1191,7 +1191,7 @@ CHIP_ERROR CASESession::EncodeSigma2Resume(System::PacketBufferHandle & msgR2Res ReturnErrorOnFailure(tlvWriter.StartContainer(AnonymousTag(), kTLVType_Structure, outerContainerType)); ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma2ResumeTags::kResumptionID), input.resumptionId)); - ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma2ResumeTags::kSigma2ResumeMIC), input.resumeMICSpan)); + ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma2ResumeTags::kSigma2ResumeMIC), input.resumeMIC)); ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma2ResumeTags::kResponderSessionID), input.responderSessionId)); ReturnErrorOnFailure( diff --git a/src/protocols/secure_channel/CASESession.h b/src/protocols/secure_channel/CASESession.h index 8f565eb62c76e4..97da417b983162 100644 --- a/src/protocols/secure_channel/CASESession.h +++ b/src/protocols/secure_channel/CASESession.h @@ -194,7 +194,6 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, // Helper Enum for use in HandleSigma1_and_SendSigma2 enum class Step : uint8_t { - kNone, kSendSigma2, kSendSigma2Resume, }; @@ -202,7 +201,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, // the next Sigma step to send) or a CHIP_ERROR (indicating a failure that will trigger // a Status Report). using NextStep = Variant; - // This struct only serves as a base struct for EncodedSigma1Inputs and ParsedSigma1 + // This struct only serves as a base struct for EncodeSigma1Inputs and ParsedSigma1 struct Sigma1Param { ByteSpan initiatorRandom; @@ -242,17 +241,17 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, { ByteSpan resumptionId; uint8_t sigma2ResumeMICBuffer[Crypto::CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES]; - MutableByteSpan resumeMICSpan{ sigma2ResumeMICBuffer }; + MutableByteSpan resumeMIC{ sigma2ResumeMICBuffer }; uint16_t responderSessionId; const ReliableMessageProtocolConfig * responderMrpConfig; }; /** * @brief Encodes a Sigma1 message into TLV format and allocates a buffer for it, which is owned by the PacketBufferHandle - *outparam. + * outparam. * * @param outMsg PacketBufferHandle passed by reference. A new buffer will be allocated and assigned to it within the - *method. + * method. * * @param inParam a struct containing all the values that will be encoded into TLV format * @@ -260,13 +259,13 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, static CHIP_ERROR EncodeSigma1(System::PacketBufferHandle & outMsg, EncodeSigma1Inputs & inParam); /** - * Parse a sigma1 message. This function will return success only if the + * Parse a Sigma1 message. This function will return success only if the * message passes schema checks. Specifically: * * The tags come in order. * * The required tags are present. * * The values for the tags that are present satisfy schema requirements * (e.g. constraints on octet string lengths) - * * Either resumptionID and initiatorResume1MICBuffer are both present or both + * * Either resumptionID and initiatorResume1MICBuffer are both present or both are * absent. * * On success, the members of outParam will be set to the values corresponding to the message. @@ -280,10 +279,10 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, /** * @brief Encodes a Sigma2 message into TLV format and allocates a buffer for it, which is owned by the PacketBufferHandle - *outparam. + * outparam. * * @param outMsg PacketBufferHandle passed by reference. A new buffer will be allocated and assigned to it within the - *method. + * method. * * @param inParam a struct containing all the values that will be encoded into TLV format * @@ -293,10 +292,10 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler, /** * @brief Encodes a Sigma2_Resume message into TLV format and allocates a buffer for it, which is owned by the - *PacketBufferHandle outparam. + * PacketBufferHandle outparam. * * @param outMsg PacketBufferHandle passed by reference. A new buffer will be allocated and assigned to it within the - *method. + * method. * * @param inParam a struct containing all the values that will be encoded into TLV format * diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index c0b28df137652f..81a2142c716021 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -888,10 +888,10 @@ TEST_F(TestCASESession, EncodeSigma1Test) uint8_t random[32]; EXPECT_EQ(chip::Crypto::DRBG_get_bytes(&random[0], sizeof(random)), CHIP_NO_ERROR); - encodeParams.initiatorRandom = ByteSpan(random, sizeof(random)); + encodeParams.initiatorRandom = ByteSpan(random); encodeParams.initiatorSessionId = 7315; uint8_t destinationId[32] = { 0xDE, 0xAD }; - encodeParams.destinationId = ByteSpan(destinationId, sizeof(destinationId)); + encodeParams.destinationId = ByteSpan(destinationId); ReliableMessageProtocolConfig mrpConfig = GetDefaultMRPConfig(); encodeParams.initiatorMrpConfig = &mrpConfig; @@ -937,15 +937,15 @@ TEST_F(TestCASESession, EncodeSigma1Test) tlvReader.Init(std::move(msg1)); CASESessionAccess session; - CASESessionAccess::ParsedSigma1 parseParams; + CASESessionAccess::ParsedSigma1 parsedMessage; - EXPECT_EQ(CHIP_NO_ERROR, session.ParseSigma1(tlvReader, parseParams)); + EXPECT_EQ(CHIP_NO_ERROR, session.ParseSigma1(tlvReader, parsedMessage)); // compare parsed values with original values - EXPECT_TRUE(parseParams.initiatorRandom.data_equal(encodeParams.initiatorRandom)); - EXPECT_EQ(parseParams.initiatorSessionId, encodeParams.initiatorSessionId); - EXPECT_TRUE(parseParams.destinationId.data_equal(encodeParams.destinationId)); - EXPECT_TRUE(parseParams.initiatorEphPubKey.data_equal( + EXPECT_TRUE(parsedMessage.initiatorRandom.data_equal(encodeParams.initiatorRandom)); + EXPECT_EQ(parsedMessage.initiatorSessionId, encodeParams.initiatorSessionId); + EXPECT_TRUE(parsedMessage.destinationId.data_equal(encodeParams.destinationId)); + EXPECT_TRUE(parsedMessage.initiatorEphPubKey.data_equal( ByteSpan(encodeParams.initiatorEphPubKey->ConstBytes(), encodeParams.initiatorEphPubKey->Length()))); } @@ -971,20 +971,20 @@ TEST_F(TestCASESession, EncodeSigma1Test) tlvReader.Init(std::move(msg2)); CASESessionAccess session; - CASESessionAccess::ParsedSigma1 parseParams; + CASESessionAccess::ParsedSigma1 parsedMessage; - EXPECT_EQ(CHIP_NO_ERROR, session.ParseSigma1(tlvReader, parseParams)); + EXPECT_EQ(CHIP_NO_ERROR, session.ParseSigma1(tlvReader, parsedMessage)); // RoundTrip - EXPECT_TRUE(parseParams.initiatorRandom.data_equal(encodeParams.initiatorRandom)); - EXPECT_EQ(parseParams.initiatorSessionId, encodeParams.initiatorSessionId); - EXPECT_TRUE(parseParams.destinationId.data_equal(encodeParams.destinationId)); - EXPECT_TRUE(parseParams.initiatorEphPubKey.data_equal( + EXPECT_TRUE(parsedMessage.initiatorRandom.data_equal(encodeParams.initiatorRandom)); + EXPECT_EQ(parsedMessage.initiatorSessionId, encodeParams.initiatorSessionId); + EXPECT_TRUE(parsedMessage.destinationId.data_equal(encodeParams.destinationId)); + EXPECT_TRUE(parsedMessage.initiatorEphPubKey.data_equal( ByteSpan(encodeParams.initiatorEphPubKey->ConstBytes(), encodeParams.initiatorEphPubKey->Length()))); - EXPECT_TRUE(parseParams.resumptionId.data_equal(encodeParams.resumptionId)); - EXPECT_TRUE(parseParams.initiatorResumeMIC.data_equal(encodeParams.initiatorResumeMIC)); - EXPECT_TRUE(parseParams.initiatorMrpParamsPresent); + EXPECT_TRUE(parsedMessage.resumptionId.data_equal(encodeParams.resumptionId)); + EXPECT_TRUE(parsedMessage.initiatorResumeMIC.data_equal(encodeParams.initiatorResumeMIC)); + EXPECT_TRUE(parsedMessage.initiatorMrpParamsPresent); } // Release EphemeralKeyPair gDeviceOperationalKeystore.ReleaseEphemeralKeypair(ephemeralKey);