Skip to content

Commit 7014d69

Browse files
authored
Merge pull request #429 from JacobBarthelmeh/pkcs7_stream
update example to handle larger inputs
2 parents 37f622e + f0e18b6 commit 7014d69

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

pkcs7/envelopedData-ktri-stream.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ static int load_certs(byte* cert, word32* certSz, byte* key, word32* keySz)
101101
}
102102

103103

104-
static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
104+
static size_t envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
105105
word32 keySz, byte* out, word32 outSz,
106106
word32 contentSz, byte useStreamMode)
107107
{
108-
int ret;
108+
size_t ret;
109109
PKCS7* pkcs7;
110110

111111
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
@@ -125,15 +125,15 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
125125
/* add recipient using RSA certificate (KTRI type) */
126126
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, cert, certSz, 0);
127127
if (ret < 0) {
128-
printf("wc_PKCS7_AddRecipient_KTRI() failed, ret = %d\n", ret);
128+
printf("wc_PKCS7_AddRecipient_KTRI() failed, ret = %zu\n", ret);
129129
wc_PKCS7_Free(pkcs7);
130130
return -1;
131131
}
132132

133133
/* encode envelopedData, returns size */
134134
ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
135135
if (ret <= 0) {
136-
printf("ERROR: wc_PKCS7_EncodeEnvelopedData() failed, ret = %d\n", ret);
136+
printf("ERROR: wc_PKCS7_EncodeEnvelopedData() failed, ret = %zu\n", ret);
137137
wc_PKCS7_Free(pkcs7);
138138
return -1;
139139

@@ -147,11 +147,11 @@ static int envelopedData_encrypt(byte* cert, word32 certSz, byte* key,
147147
return ret;
148148
}
149149

150-
static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
150+
static size_t envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
151151
word32 certSz, byte* key, word32 keySz,
152152
byte* out, word32 outSz)
153153
{
154-
int ret;
154+
size_t ret;
155155
PKCS7* pkcs7;
156156

157157
pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
@@ -175,7 +175,7 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
175175
/* decode envelopedData, returns size */
176176
ret = wc_PKCS7_DecodeEnvelopedData(pkcs7, in, inSz, out, outSz);
177177
if (ret <= 0) {
178-
printf("Failed to decode EnvelopedData bundle (%s), error %d\n",
178+
printf("Failed to decode EnvelopedData bundle (%s), error %zu\n",
179179
encodedFileKTRI, ret);
180180
wc_PKCS7_Free(pkcs7);
181181
return -1;
@@ -197,7 +197,7 @@ static int envelopedData_decrypt(byte* in, word32 inSz, byte* cert,
197197
int main(int argc, char** argv)
198198
{
199199
int ret = 0;
200-
int encryptedSz = 0, decryptedSz;
200+
size_t encryptedSz = 0, decryptedSz;
201201
word32 certSz, keySz, contentSz = 0;
202202

203203
byte cert[DEFAULT_EXAMPLE_BUFFER_SIZE];
@@ -242,7 +242,7 @@ int main(int argc, char** argv)
242242
fseek(testIO.fileIn, 0, SEEK_END);
243243
contentSz = ftell(testIO.fileIn);
244244
fseek(testIO.fileIn, 0, SEEK_SET);
245-
printf("contentSz = %d\n", contentSz);
245+
printf("contentSz = %u\n", contentSz);
246246

247247
certSz = sizeof(cert);
248248
keySz = sizeof(key);
@@ -279,7 +279,7 @@ int main(int argc, char** argv)
279279
printf("error reading file %s\n", encodedFileKTRI);
280280
ret = -1;
281281
}
282-
printf("Read %d bytes for encrypted file found\n", encryptedSz);
282+
printf("Read %ld bytes for encrypted file found\n", encryptedSz);
283283
}
284284

285285
if (ret == 0) {

0 commit comments

Comments
 (0)