Skip to content

Commit a194e44

Browse files
fix return value and handle PKCS7 PEM types correctly
1 parent cde2d95 commit a194e44

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/tools/clu_base64.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,17 @@ int wolfCLU_Base64Setup(int argc, char** argv)
163163
/* Try other types if PRIVATEKEY_TYPE fails */
164164
ret = wc_PemToDer(input, (long)inputSz, CERT_TYPE,
165165
&der, NULL, NULL, NULL);
166-
if (ret < 0) {
167-
ret = wc_PemToDer(input, (long)inputSz, CERTREQ_TYPE,
166+
}
167+
168+
if (ret < 0) {
169+
ret = wc_PemToDer(input, (long)inputSz, PKCS7_TYPE,
168170
&der, NULL, NULL, NULL);
169-
if (ret < 0) {
170-
wolfCLU_LogError("PEM to DER conversion failed: %d",
171-
ret);
172-
ret = WOLFCLU_FATAL_ERROR;
173-
}
174-
}
171+
}
172+
173+
/* If all PEM to DER attempts failed then set error */
174+
if (ret < 0) {
175+
wolfCLU_LogError("PEM to DER conversion failed: %d", ret);
176+
ret = WOLFCLU_FATAL_ERROR;
175177
}
176178

177179
if (ret == 0) {
@@ -247,6 +249,9 @@ int wolfCLU_Base64Setup(int argc, char** argv)
247249
wolfCLU_LogError("Base64 encode failed: %d", ret);
248250
ret = WOLFCLU_FATAL_ERROR;
249251
}
252+
else {
253+
ret = WOLFCLU_SUCCESS;
254+
}
250255
}
251256
}
252257

@@ -257,6 +262,9 @@ int wolfCLU_Base64Setup(int argc, char** argv)
257262
wolfCLU_LogError("Failed to write output data: %d", ret);
258263
ret = WOLFCLU_FATAL_ERROR;
259264
}
265+
else {
266+
ret = WOLFCLU_SUCCESS;
267+
}
260268
}
261269
else if (ret == WOLFCLU_SUCCESS) {
262270
/* Write to stdout */
@@ -268,6 +276,9 @@ int wolfCLU_Base64Setup(int argc, char** argv)
268276
wolfCLU_LogError("Failed to write to stdout: %d", ret);
269277
ret = WOLFCLU_FATAL_ERROR;
270278
}
279+
else {
280+
ret = WOLFCLU_SUCCESS;
281+
}
271282
}
272283
else {
273284
wolfCLU_LogError("Failed to create stdout BIO");

0 commit comments

Comments
 (0)