From 723ae94ad69f7ca6fc589842bfb3fab6fe9f07fa Mon Sep 17 00:00:00 2001 From: Karsten Sperling Date: Thu, 26 Oct 2023 11:13:27 +1300 Subject: [PATCH] Tests: Use TestCert enum type instead of uint8_t --- .../tests/CHIPCert_test_vectors.cpp | 14 +++++----- src/credentials/tests/CHIPCert_test_vectors.h | 14 +++++----- src/credentials/tests/TestChipCert.cpp | 26 +++++++++---------- 3 files changed, 27 insertions(+), 27 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; };