Skip to content

Commit ea23d8d

Browse files
add comments, remove hard tab, remove optional debugging output
1 parent 511518d commit ea23d8d

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

pkcs7/benchmark-streaming-envelop.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct timeval startTime;
4040

4141
static void TimeLogStart(void)
4242
{
43-
gettimeofday(&startTime, NULL);
43+
gettimeofday(&startTime, NULL);
4444
}
4545

4646

@@ -108,6 +108,12 @@ typedef struct BENCHMARK_IO {
108108
} BENCHMARK_IO;
109109

110110

111+
/* Callback function to allow wolfSSL to read from a stream of input when
112+
* working with the PKCS7 content. The byte pointer content is handled by the
113+
* code managing the callback, meaning that malloc'ing/free'ing any memory
114+
* should be done here, wolfSSL will not try to free the pointer given.
115+
*
116+
* Expected to return the number of bytes that the buffer pointed to contains */
111117
static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
112118
{
113119
int ret = 0;
@@ -125,6 +131,12 @@ static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
125131
}
126132

127133

134+
/* Callback function to output the PKCS7 bundle as it is created. The buffer
135+
* 'output' contains the current data to be written out and 'outputSz' is the
136+
* number of bytes in the 'output' buffer.
137+
*
138+
* Expected to return 0 on success.
139+
*/
128140
static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
129141
void* ctx)
130142
{
@@ -234,6 +246,12 @@ static int EncodePKCS7Bundle(double contentSz, WC_RNG* rng)
234246
}
235247

236248

249+
/* Decryption callback function that is passed the decrypted data in buffer
250+
* 'output' from wolfSSL. The 'outputSz' argument is the number of decrypted
251+
* bytes being passed in and 'ctx' is a user set context.
252+
*
253+
* This callback is expected to return 0 on success.
254+
*/
237255
static int DecryptCB(wc_PKCS7* pkcs7,
238256
const byte* output, word32 outputSz, void* ctx) {
239257
FILE* out = (FILE*)ctx;
@@ -242,16 +260,13 @@ static int DecryptCB(wc_PKCS7* pkcs7,
242260
return -1;
243261
}
244262

245-
/* printf("Decoded in %d bytes\n", outputSz);
246-
* for (word32 z = 0; z < outputSz; z++) printf("%02X", output[z]);
247-
* printf("\n");
248-
*/
249-
fwrite(output, 1, outputSz, out);
263+
(void)fwrite(output, 1, outputSz, out);
250264

251265
(void)pkcs7;
252266
return 0;
253267
}
254268

269+
255270
static int DecodePKCS7Bundle(void)
256271
{
257272
wc_PKCS7* pkcs7 = NULL;

0 commit comments

Comments
 (0)