tpm12: Implement TPM_PrintFourLimit to print 4 or less bytes

Implement TPM_PrintFourLimit to print only up to 4 bytes or less.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2019-11-18 10:40:29 -05:00 committed by Stefan Berger
parent ae15c8c76b
commit accf4437c6
2 changed files with 41 additions and 9 deletions

View File

@ -57,17 +57,40 @@ int tpm_swallow_printf_args(const char *format, ...)
#else
/* TPM_PrintFour() prints a prefix plus 4 bytes of a buffer */
void TPM_PrintFour(const char *string, const unsigned char* buff)
void TPM_PrintFourLimit(const char *string,
const unsigned char *buff, size_t buflen)
{
if (buff != NULL) {
TPMLIB_LogPrintf("%s %02x %02x %02x %02x\n",
string,
buff[0],
buff[1],
buff[2],
buff[3]);
switch (buflen) {
case 0:
TPMLIB_LogPrintf("%s (no data)\n", string);
break;
case 1:
TPMLIB_LogPrintf("%s %02x\n",
string,
buff[0]);
break;
case 2:
TPMLIB_LogPrintf("%s %02x %02x\n",
string,
buff[0],
buff[1]);
break;
case 3:
TPMLIB_LogPrintf("%s %02x %02x %02x\n",
string,
buff[0],
buff[1],
buff[2]);
break;
default:
TPMLIB_LogPrintf("%s %02x %02x %02x %02x\n",
string,
buff[0],
buff[1],
buff[2],
buff[3]);
}
}
else {
TPMLIB_LogPrintf("%s null\n", string);
@ -75,6 +98,13 @@ void TPM_PrintFour(const char *string, const unsigned char* buff)
return;
}
/* TPM_PrintFour() prints a prefix plus 4 bytes of a buffer */
void TPM_PrintFour(const char *string, const unsigned char* buff)
{
TPM_PrintFourLimit(string, buff, 4);
}
#endif
/* TPM_PrintAll() prints 'string', the length, and then the entire byte array

View File

@ -46,6 +46,8 @@
/* prototypes */
void TPM_PrintFour(const char *string, const unsigned char* buff);
void TPM_PrintFourLimit(const char *string,
const unsigned char* buff, size_t bufflen);
void TPM_PrintAll(const char *string, const unsigned char* buff, uint32_t length);
#if 0