From 1634740f762bed13b421bfdf8ccb15186ef5c676 Mon Sep 17 00:00:00 2001 From: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:47:34 +1300 Subject: [PATCH] Tests: Use TestCert enum type instead of uint8_t (#30011) * Tests: Use TestCert enum type instead of uint8_t * Fix CHIPCryptoPALTest --- .../tests/CHIPCert_test_vectors.cpp | 14 +++++----- src/credentials/tests/CHIPCert_test_vectors.h | 14 +++++----- src/credentials/tests/TestChipCert.cpp | 26 +++++++++---------- src/crypto/tests/CHIPCryptoPALTest.cpp | 12 ++++----- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/credentials/tests/CHIPCert_test_vectors.cpp b/src/credentials/tests/CHIPCert_test_vectors.cpp index 9a21d934f52ec5..eb84e7d3dabb11 100644 --- a/src/credentials/tests/CHIPCert_test_vectors.cpp +++ b/src/credentials/tests/CHIPCert_test_vectors.cpp @@ -32,7 +32,7 @@ namespace chip { namespace TestCerts { // clang-format off -extern const uint8_t gTestCerts[] = { +extern const TestCert gTestCerts[] = { TestCert::kRoot01, TestCert::kRoot02, TestCert::kRoot03, @@ -55,7 +55,7 @@ extern const uint8_t gTestCerts[] = { extern const size_t gNumTestCerts = ArraySize(gTestCerts); -CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFlags, ByteSpan & cert) +CHIP_ERROR GetTestCert(TestCert certType, BitFlags certLoadFlags, ByteSpan & cert) { CHIP_ERROR err; bool derForm = certLoadFlags.Has(TestCertLoadFlags::kDERForm); @@ -96,7 +96,7 @@ CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFla return err; } -const char * GetTestCertName(uint8_t certType) +const char * GetTestCertName(TestCert certType) { #define NAME_CERT(NAME) \ do \ @@ -129,7 +129,7 @@ const char * GetTestCertName(uint8_t certType) return nullptr; } -CHIP_ERROR GetTestCertPubkey(uint8_t certType, ByteSpan & pubkey) +CHIP_ERROR GetTestCertPubkey(TestCert certType, ByteSpan & pubkey) { CHIP_ERROR err; @@ -169,7 +169,7 @@ CHIP_ERROR GetTestCertPubkey(uint8_t certType, ByteSpan & pubkey) return err; } -CHIP_ERROR GetTestCertSKID(uint8_t certType, ByteSpan & skid) +CHIP_ERROR GetTestCertSKID(TestCert certType, ByteSpan & skid) { CHIP_ERROR err; @@ -209,7 +209,7 @@ CHIP_ERROR GetTestCertSKID(uint8_t certType, ByteSpan & skid) return err; } -CHIP_ERROR GetTestCertAKID(uint8_t certType, ByteSpan & akid) +CHIP_ERROR GetTestCertAKID(TestCert certType, ByteSpan & akid) { CHIP_ERROR err; @@ -249,7 +249,7 @@ CHIP_ERROR GetTestCertAKID(uint8_t certType, ByteSpan & akid) return err; } -CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags certLoadFlags, +CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, TestCert certType, BitFlags certLoadFlags, BitFlags decodeFlags) { CHIP_ERROR err; diff --git a/src/credentials/tests/CHIPCert_test_vectors.h b/src/credentials/tests/CHIPCert_test_vectors.h index dc717f396eeccb..521426ee3e5084 100644 --- a/src/credentials/tests/CHIPCert_test_vectors.h +++ b/src/credentials/tests/CHIPCert_test_vectors.h @@ -68,15 +68,15 @@ enum class TestCertLoadFlags : uint8_t kSetAppDefinedCertType = 0x20, }; -extern CHIP_ERROR GetTestCert(uint8_t certType, BitFlags certLoadFlags, ByteSpan & cert); -extern const char * GetTestCertName(uint8_t certType); -extern CHIP_ERROR GetTestCertPubkey(uint8_t certType, ByteSpan & pubkey); -extern CHIP_ERROR GetTestCertSKID(uint8_t certType, ByteSpan & skid); -extern CHIP_ERROR GetTestCertAKID(uint8_t certType, ByteSpan & akid); -extern CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags certLoadFlags, +extern CHIP_ERROR GetTestCert(TestCert certType, BitFlags certLoadFlags, ByteSpan & cert); +extern const char * GetTestCertName(TestCert certType); +extern CHIP_ERROR GetTestCertPubkey(TestCert certType, ByteSpan & pubkey); +extern CHIP_ERROR GetTestCertSKID(TestCert certType, ByteSpan & skid); +extern CHIP_ERROR GetTestCertAKID(TestCert certType, ByteSpan & akid); +extern CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, TestCert certType, BitFlags certLoadFlags, BitFlags decodeFlags); -extern const uint8_t gTestCerts[]; +extern const TestCert gTestCerts[]; extern const size_t gNumTestCerts; // ------------------------------ DECLARATIONS ---------------------------------------- diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp index 4d81940f9b8549..1a8da833c06173 100644 --- a/src/credentials/tests/TestChipCert.cpp +++ b/src/credentials/tests/TestChipCert.cpp @@ -171,7 +171,7 @@ static void TestChipCert_ChipToX509(nlTestSuite * inSuite, void * inContext) for (size_t i = 0; i < gNumTestCerts; i++) { - uint8_t certType = gTestCerts[i]; + TestCert certType = gTestCerts[i]; err = GetTestCert(certType, sNullLoadFlag, inCert); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -267,7 +267,7 @@ static void TestChipCert_X509ToChip(nlTestSuite * inSuite, void * inContext) for (size_t i = 0; i < gNumTestCerts; i++) { - uint8_t certType = gTestCerts[i]; + TestCert certType = gTestCerts[i]; err = GetTestCert(certType, sDerFormFlag, inCert); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -368,7 +368,7 @@ static void TestChipCert_CertValidation(nlTestSuite * inSuite, void * inContext) int mExpectedTrustAnchorIndex; struct { - uint8_t Type; + TestCert Type; BitFlags DecodeFlags; BitFlags LoadFlags; } InputCerts[kMaxCertsPerTestCase]; @@ -832,7 +832,7 @@ static void TestChipCert_ValidateChipRCAC(nlTestSuite * inSuite, void * inContex { struct RCACTestCase { - uint8_t Cert; + TestCert Cert; CHIP_ERROR mExpectedResult; }; @@ -1191,7 +1191,7 @@ static void TestChipCert_CertType(nlTestSuite * inSuite, void * inContext) struct TestCase { - uint8_t Cert; + TestCert Cert; CertType ExpectedCertType; }; @@ -1237,7 +1237,7 @@ static void TestChipCert_CertId(nlTestSuite * inSuite, void * inContext) struct TestCase { - uint8_t Cert; + TestCert Cert; uint64_t ExpectedCertId; }; @@ -1728,8 +1728,8 @@ static void TestChipCert_ExtractNodeIdFabricId(nlTestSuite * inSuite, void * inC { struct TestCase { - uint8_t Cert; - uint8_t ICACert; + TestCert Cert; + TestCert ICACert; uint64_t ExpectedNodeId; uint64_t ExpectedFabricId; }; @@ -1844,8 +1844,8 @@ static void TestChipCert_ExtractOperationalDiscoveryId(nlTestSuite * inSuite, vo { struct TestCase { - uint8_t Noc; - uint8_t Rcac; + TestCert Noc; + TestCert Rcac; uint64_t ExpectedNodeId; uint64_t ExpectedFabricId; uint64_t ExpectedCompressedFabricId; @@ -1900,7 +1900,7 @@ static void TestChipCert_ExtractAndValidateCATsFromOpCert(nlTestSuite * inSuite, { struct TestCase { - uint8_t Cert; + TestCert Cert; CATValues ExpectedCATs; }; @@ -1986,7 +1986,7 @@ static void TestChipCert_ExtractSubjectDNFromChipCert(nlTestSuite * inSuite, voi { struct TestCase { - uint8_t Cert; + TestCert Cert; ChipDN ExpectedSubjectDN; }; @@ -2058,7 +2058,7 @@ static void TestChipCert_ExtractPublicKeyAndSKID(nlTestSuite * inSuite, void * i { struct TestCase { - uint8_t Cert; + TestCert Cert; ByteSpan ExpectedPublicKey; ByteSpan ExpectedSKID; }; diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index 14e5ec9c052ead..39d9998fa95b80 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -2005,7 +2005,7 @@ static void TestPubkey_x509Extraction(nlTestSuite * inSuite, void * inContext) for (size_t i = 0; i < gNumTestCerts; i++) { - uint8_t certType = TestCerts::gTestCerts[i]; + TestCert certType = TestCerts::gTestCerts[i]; err = GetTestCert(certType, TestCertLoadFlags::kDERForm, cert); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -2193,7 +2193,7 @@ static void TestSKID_x509Extraction(nlTestSuite * inSuite, void * inContext) for (size_t i = 0; i < gNumTestCerts; i++) { - uint8_t certType = gTestCerts[i]; + TestCert certType = gTestCerts[i]; err = GetTestCert(certType, TestCertLoadFlags::kDERForm, cert); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -2220,7 +2220,7 @@ static void TestAKID_x509Extraction(nlTestSuite * inSuite, void * inContext) for (size_t i = 0; i < gNumTestCerts; i++) { - uint8_t certType = gTestCerts[i]; + TestCert certType = gTestCerts[i]; err = GetTestCert(certType, TestCertLoadFlags::kDERForm, cert); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -2360,7 +2360,7 @@ static void TestSerialNumber_x509Extraction(nlTestSuite * inSuite, void * inCont struct SerialNumberTestCase { - uint8_t Cert; + TestCert Cert; ByteSpan mExpectedResult; }; @@ -2401,7 +2401,7 @@ static void TestSubject_x509Extraction(nlTestSuite * inSuite, void * inContext) struct TestCase { - uint8_t Cert; + TestCert Cert; ChipDN mExpectedDN; }; @@ -2475,7 +2475,7 @@ static void TestIssuer_x509Extraction(nlTestSuite * inSuite, void * inContext) struct TestCase { - uint8_t Cert; + TestCert Cert; ChipDN mExpectedDN; };