Skip to content

Commit 4d39d8b

Browse files
committed
Remove bare scope blocks in spdm_ctrl.c and unit_tests.c
1 parent 7dbb21e commit 4d39d8b

2 files changed

Lines changed: 43 additions & 48 deletions

File tree

examples/spdm/spdm_ctrl.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ static int ctrl_nations_status(WOLFTPM2_DEV* dev)
224224
{
225225
int rc;
226226
int isConn;
227+
int stsRc;
227228
GetCapability_In capIn;
228229
GetCapability_Out capOut;
230+
WOLFSPDM_NATIONS_STATUS status;
229231

230232
printf("\n=== Nations SPDM Status ===\n");
231233

@@ -246,25 +248,20 @@ static int ctrl_nations_status(WOLFTPM2_DEV* dev)
246248
}
247249

248250
/* 2. Try GET_STS_ vendor command (PSK mode only — may fail) */
249-
{
250-
WOLFSPDM_NATIONS_STATUS status;
251-
int stsRc;
252-
253-
stsRc = wolfSPDM_GetVersion(dev->spdmCtx->spdmCtx);
251+
stsRc = wolfSPDM_GetVersion(dev->spdmCtx->spdmCtx);
252+
if (stsRc == 0) {
253+
XMEMSET(&status, 0, sizeof(status));
254+
stsRc = wolfTPM2_SpdmNationsGetStatus(dev, &status);
254255
if (stsRc == 0) {
255-
XMEMSET(&status, 0, sizeof(status));
256-
stsRc = wolfTPM2_SpdmNationsGetStatus(dev, &status);
257-
if (stsRc == 0) {
258-
printf(" PSK: %s SPDM-Only: %s\n",
259-
status.pskProvisioned ? "provisioned" : "not provisioned",
260-
!status.spdmOnlyLocked ? "disabled" :
261-
status.spdmOnlyPending ? "PENDING_DISABLE" : "ENABLED");
262-
} else {
263-
printf(" PSK Status: unknown (GET_STS failed)\n");
264-
}
256+
printf(" PSK: %s SPDM-Only: %s\n",
257+
status.pskProvisioned ? "provisioned" : "not provisioned",
258+
!status.spdmOnlyLocked ? "disabled" :
259+
status.spdmOnlyPending ? "PENDING_DISABLE" : "ENABLED");
265260
} else {
266-
printf(" PSK Status: GET_VERSION failed\n");
261+
printf(" PSK Status: unknown (GET_STS failed)\n");
267262
}
263+
} else {
264+
printf(" PSK Status: GET_VERSION failed\n");
268265
}
269266

270267
/* 3. Local session state */

tests/unit_tests.c

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,16 @@ static void test_wolfTPM2_SPDM_Functions(void)
967967
{
968968
int rc;
969969
WOLFTPM2_DEV dev;
970+
#ifdef WOLFSPDM_NUVOTON
971+
WOLFSPDM_NUVOTON_STATUS nuvStatus;
972+
#endif
973+
#if defined(WOLFSPDM_NUVOTON) || defined(WOLFSPDM_NATIONS)
974+
byte pubKey[256];
975+
word32 pubKeySz;
976+
#endif
977+
#ifdef WOLFSPDM_NATIONS
978+
WOLFSPDM_NATIONS_STATUS nStatus;
979+
#endif
970980

971981
printf("Test TPM Wrapper:\tSPDM Functions:\t");
972982

@@ -1011,20 +1021,15 @@ static void test_wolfTPM2_SPDM_Functions(void)
10111021
AssertIntEQ(rc, BAD_FUNC_ARG);
10121022
rc = wolfTPM2_SpdmEnable(NULL);
10131023
AssertIntEQ(rc, BAD_FUNC_ARG);
1014-
{
1015-
WOLFSPDM_NUVOTON_STATUS status;
1016-
byte pubKey[256];
1017-
word32 pubKeySz = sizeof(pubKey);
1018-
1019-
rc = wolfTPM2_SpdmGetStatus(NULL, &status);
1020-
AssertIntEQ(rc, BAD_FUNC_ARG);
1021-
rc = wolfTPM2_SpdmGetStatus(&dev, NULL);
1022-
AssertIntEQ(rc, BAD_FUNC_ARG);
1023-
rc = wolfTPM2_SpdmGetPubKey(NULL, pubKey, &pubKeySz);
1024-
AssertIntEQ(rc, BAD_FUNC_ARG);
1025-
rc = wolfTPM2_SpdmSetOnlyMode(NULL, 0);
1026-
AssertIntEQ(rc, BAD_FUNC_ARG);
1027-
}
1024+
pubKeySz = sizeof(pubKey);
1025+
rc = wolfTPM2_SpdmGetStatus(NULL, &nuvStatus);
1026+
AssertIntEQ(rc, BAD_FUNC_ARG);
1027+
rc = wolfTPM2_SpdmGetStatus(&dev, NULL);
1028+
AssertIntEQ(rc, BAD_FUNC_ARG);
1029+
rc = wolfTPM2_SpdmGetPubKey(NULL, pubKey, &pubKeySz);
1030+
AssertIntEQ(rc, BAD_FUNC_ARG);
1031+
rc = wolfTPM2_SpdmSetOnlyMode(NULL, 0);
1032+
AssertIntEQ(rc, BAD_FUNC_ARG);
10281033
#endif /* WOLFSPDM_NUVOTON */
10291034

10301035
#ifdef WOLFSPDM_NATIONS
@@ -1033,27 +1038,20 @@ static void test_wolfTPM2_SPDM_Functions(void)
10331038
AssertIntEQ(rc, BAD_FUNC_ARG);
10341039
rc = wolfTPM2_SpdmNationsIdentityKeySet(NULL, 0);
10351040
AssertIntEQ(rc, BAD_FUNC_ARG);
1036-
{
1037-
byte pubKey[256];
1038-
word32 pubKeySz = sizeof(pubKey);
1039-
1040-
rc = wolfTPM2_SpdmGetPubKey(NULL, pubKey, &pubKeySz);
1041-
AssertIntEQ(rc, BAD_FUNC_ARG);
1042-
}
1041+
pubKeySz = sizeof(pubKey);
1042+
rc = wolfTPM2_SpdmGetPubKey(NULL, pubKey, &pubKeySz);
1043+
AssertIntEQ(rc, BAD_FUNC_ARG);
10431044
/* Nations PSK wrapper parameter validation */
10441045
rc = wolfTPM2_SpdmConnectNationsPsk(NULL, NULL, 0, NULL, 0);
10451046
AssertIntEQ(rc, BAD_FUNC_ARG);
1046-
{
1047-
WOLFSPDM_NATIONS_STATUS nStatus;
1048-
rc = wolfTPM2_SpdmNationsGetStatus(NULL, &nStatus);
1049-
AssertIntEQ(rc, BAD_FUNC_ARG);
1050-
rc = wolfTPM2_SpdmNationsSetOnlyMode(NULL, 0);
1051-
AssertIntEQ(rc, BAD_FUNC_ARG);
1052-
rc = wolfTPM2_SpdmNationsPskSet(NULL, NULL, 0);
1053-
AssertIntEQ(rc, BAD_FUNC_ARG);
1054-
rc = wolfTPM2_SpdmNationsPskClear(NULL, NULL, 0);
1055-
AssertIntEQ(rc, BAD_FUNC_ARG);
1056-
}
1047+
rc = wolfTPM2_SpdmNationsGetStatus(NULL, &nStatus);
1048+
AssertIntEQ(rc, BAD_FUNC_ARG);
1049+
rc = wolfTPM2_SpdmNationsSetOnlyMode(NULL, 0);
1050+
AssertIntEQ(rc, BAD_FUNC_ARG);
1051+
rc = wolfTPM2_SpdmNationsPskSet(NULL, NULL, 0);
1052+
AssertIntEQ(rc, BAD_FUNC_ARG);
1053+
rc = wolfTPM2_SpdmNationsPskClear(NULL, NULL, 0);
1054+
AssertIntEQ(rc, BAD_FUNC_ARG);
10571055
#endif /* WOLFSPDM_NATIONS */
10581056

10591057
wolfTPM2_Cleanup(&dev);

0 commit comments

Comments
 (0)