Skip to content

Commit

Permalink
Tests: Use TestCert enum type instead of uint8_t (#30011)
Browse files Browse the repository at this point in the history
* Tests: Use TestCert enum type instead of uint8_t

* Fix CHIPCryptoPALTest
  • Loading branch information
ksperling-apple authored and pull[bot] committed Feb 15, 2024
1 parent e19173c commit 1634740
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
14 changes: 7 additions & 7 deletions src/credentials/tests/CHIPCert_test_vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,7 +55,7 @@ extern const uint8_t gTestCerts[] = {

extern const size_t gNumTestCerts = ArraySize(gTestCerts);

CHIP_ERROR GetTestCert(uint8_t certType, BitFlags<TestCertLoadFlags> certLoadFlags, ByteSpan & cert)
CHIP_ERROR GetTestCert(TestCert certType, BitFlags<TestCertLoadFlags> certLoadFlags, ByteSpan & cert)
{
CHIP_ERROR err;
bool derForm = certLoadFlags.Has(TestCertLoadFlags::kDERForm);
Expand Down Expand Up @@ -96,7 +96,7 @@ CHIP_ERROR GetTestCert(uint8_t certType, BitFlags<TestCertLoadFlags> certLoadFla
return err;
}

const char * GetTestCertName(uint8_t certType)
const char * GetTestCertName(TestCert certType)
{
#define NAME_CERT(NAME) \
do \
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -249,7 +249,7 @@ CHIP_ERROR GetTestCertAKID(uint8_t certType, ByteSpan & akid)
return err;
}

CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, uint8_t certType, BitFlags<TestCertLoadFlags> certLoadFlags,
CHIP_ERROR LoadTestCert(ChipCertificateSet & certSet, TestCert certType, BitFlags<TestCertLoadFlags> certLoadFlags,
BitFlags<CertDecodeFlags> decodeFlags)
{
CHIP_ERROR err;
Expand Down
14 changes: 7 additions & 7 deletions src/credentials/tests/CHIPCert_test_vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ enum class TestCertLoadFlags : uint8_t
kSetAppDefinedCertType = 0x20,
};

extern CHIP_ERROR GetTestCert(uint8_t certType, BitFlags<TestCertLoadFlags> 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<TestCertLoadFlags> certLoadFlags,
extern CHIP_ERROR GetTestCert(TestCert certType, BitFlags<TestCertLoadFlags> 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<TestCertLoadFlags> certLoadFlags,
BitFlags<CertDecodeFlags> decodeFlags);

extern const uint8_t gTestCerts[];
extern const TestCert gTestCerts[];
extern const size_t gNumTestCerts;

// ------------------------------ DECLARATIONS ----------------------------------------
Expand Down
26 changes: 13 additions & 13 deletions src/credentials/tests/TestChipCert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -368,7 +368,7 @@ static void TestChipCert_CertValidation(nlTestSuite * inSuite, void * inContext)
int mExpectedTrustAnchorIndex;
struct
{
uint8_t Type;
TestCert Type;
BitFlags<CertDecodeFlags> DecodeFlags;
BitFlags<TestCertLoadFlags> LoadFlags;
} InputCerts[kMaxCertsPerTestCase];
Expand Down Expand Up @@ -832,7 +832,7 @@ static void TestChipCert_ValidateChipRCAC(nlTestSuite * inSuite, void * inContex
{
struct RCACTestCase
{
uint8_t Cert;
TestCert Cert;
CHIP_ERROR mExpectedResult;
};

Expand Down Expand Up @@ -1191,7 +1191,7 @@ static void TestChipCert_CertType(nlTestSuite * inSuite, void * inContext)

struct TestCase
{
uint8_t Cert;
TestCert Cert;
CertType ExpectedCertType;
};

Expand Down Expand Up @@ -1237,7 +1237,7 @@ static void TestChipCert_CertId(nlTestSuite * inSuite, void * inContext)

struct TestCase
{
uint8_t Cert;
TestCert Cert;
uint64_t ExpectedCertId;
};

Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1900,7 +1900,7 @@ static void TestChipCert_ExtractAndValidateCATsFromOpCert(nlTestSuite * inSuite,
{
struct TestCase
{
uint8_t Cert;
TestCert Cert;
CATValues ExpectedCATs;
};

Expand Down Expand Up @@ -1986,7 +1986,7 @@ static void TestChipCert_ExtractSubjectDNFromChipCert(nlTestSuite * inSuite, voi
{
struct TestCase
{
uint8_t Cert;
TestCert Cert;
ChipDN ExpectedSubjectDN;
};

Expand Down Expand Up @@ -2058,7 +2058,7 @@ static void TestChipCert_ExtractPublicKeyAndSKID(nlTestSuite * inSuite, void * i
{
struct TestCase
{
uint8_t Cert;
TestCert Cert;
ByteSpan ExpectedPublicKey;
ByteSpan ExpectedSKID;
};
Expand Down
12 changes: 6 additions & 6 deletions src/crypto/tests/CHIPCryptoPALTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -2360,7 +2360,7 @@ static void TestSerialNumber_x509Extraction(nlTestSuite * inSuite, void * inCont

struct SerialNumberTestCase
{
uint8_t Cert;
TestCert Cert;
ByteSpan mExpectedResult;
};

Expand Down Expand Up @@ -2401,7 +2401,7 @@ static void TestSubject_x509Extraction(nlTestSuite * inSuite, void * inContext)

struct TestCase
{
uint8_t Cert;
TestCert Cert;
ChipDN mExpectedDN;
};

Expand Down Expand Up @@ -2475,7 +2475,7 @@ static void TestIssuer_x509Extraction(nlTestSuite * inSuite, void * inContext)

struct TestCase
{
uint8_t Cert;
TestCert Cert;
ChipDN mExpectedDN;
};

Expand Down

0 comments on commit 1634740

Please sign in to comment.