Skip to content

Commit

Permalink
make-pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
EskoDijk committed May 13, 2024
1 parent 4d40298 commit 2ac2574
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/core/meshcop/secure_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,13 @@ Error SecureTransport::GetThreadAttributeFromCertificate(const mbedtls_x509_crt
{
// per RFC 5280, octet string must contain ASN.1 Type Length Value octets
VerifyOrExit(len >= 2, error = kErrorParse);
VerifyOrExit( *(p+1) == len-2, error = kErrorParse); // check TLV Length, not Type.
*aAttributeLength = len-2; // strip the ASN.1 Type Length bytes from embedded TLV
VerifyOrExit(*(p + 1) == len - 2, error = kErrorParse); // check TLV Length, not Type.
*aAttributeLength = len - 2; // strip the ASN.1 Type Length bytes from embedded TLV

if (aAttributeBuffer != nullptr)
{
VerifyOrExit(*aAttributeLength <= attributeBufferSize, error = kErrorNoBufs);
memcpy(aAttributeBuffer, p+2, *aAttributeLength);
memcpy(aAttributeBuffer, p + 2, *aAttributeLength);
}

error = kErrorNone;
Expand Down
3 changes: 2 additions & 1 deletion src/core/radio/ble_secure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ void BleSecure::HandleTlsConnected(bool aConnected)
{
Error err = mTcatAgent.Connected(mTls);

if (err != kErrorNone){
if (err != kErrorNone)
{
mTls.Close();
LogWarn("Rejected TCAT Commissioner, error: %s", ErrorToString(err));
ExitNow();
Expand Down
19 changes: 10 additions & 9 deletions tests/unit/test_tcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ static void HandleBleSecureConnect(otInstance *aInstance, bool aConnected, bool

void TestTcat(void)
{
const char kPskdVendor[] = "J01NM3";
const char kUrl[] = "dummy_url";
constexpr uint16_t kConnectionId = 0;
const int kCertificateThreadVersion = 2;
const char kPskdVendor[] = "J01NM3";
const char kUrl[] = "dummy_url";
constexpr uint16_t kConnectionId = 0;
const int kCertificateThreadVersion = 2;
const int kCertificateAuthorizationField = 3;
const uint8_t expectedTcatAuthField[5] = {0x20, 0x01, 0x01, 0x01, 0x01};
const uint8_t expectedTcatAuthField[5] = {0x20, 0x01, 0x01, 0x01, 0x01};
uint8_t attributeBuffer[8];
size_t attributeLen;

Expand Down Expand Up @@ -145,10 +145,11 @@ void TestTcat(void)
// Verify that Thread-attribute parsing isn't available yet when not connected as client or server.
attributeLen = sizeof(attributeBuffer);
VerifyOrQuit(otBleSecureGetThreadAttributeFromPeerCertificate(instance, kCertificateAuthorizationField,
&attributeBuffer[0], &attributeLen) == kErrorInvalidState);
&attributeBuffer[0],
&attributeLen) == kErrorInvalidState);
attributeLen = sizeof(attributeBuffer);
VerifyOrQuit(otBleSecureGetThreadAttributeFromOwnCertificate(instance, kCertificateThreadVersion,
&attributeBuffer[0], &attributeLen) == kErrorInvalidState);
VerifyOrQuit(otBleSecureGetThreadAttributeFromOwnCertificate(
instance, kCertificateThreadVersion, &attributeBuffer[0], &attributeLen) == kErrorInvalidState);

// Validate connection callbacks when calling `otBleSecureDisconnect()`
otPlatBleGapOnConnected(instance, kConnectionId);
Expand All @@ -165,7 +166,7 @@ void TestTcat(void)
// Test that the Thread-specific attributes can be decoded properly.
attributeLen = 1;
SuccessOrQuit(otBleSecureGetThreadAttributeFromOwnCertificate(instance, kCertificateThreadVersion,
&attributeBuffer[0], &attributeLen));
&attributeBuffer[0], &attributeLen));
VerifyOrQuit(attributeLen == 1 && attributeBuffer[0] >= kThreadVersion1p4);

static_assert(5 == sizeof(expectedTcatAuthField), "expectedTcatAuthField size incorrect for test");
Expand Down

0 comments on commit 2ac2574

Please sign in to comment.