From 353bb08330c13bac208e3921b3e5d326b21b27a0 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Tue, 24 Oct 2017 12:13:50 -0600 Subject: [PATCH] refactor sanity checks and a debug print --- .../encryption-through-signing/rsa-private-encrypt-app.c | 4 +++- .../encryption-through-signing/rsa-public-decrypt-app.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/signature/encryption-through-signing/rsa-private-encrypt-app.c b/signature/encryption-through-signing/rsa-private-encrypt-app.c index 38af25f2..9507072f 100644 --- a/signature/encryption-through-signing/rsa-private-encrypt-app.c +++ b/signature/encryption-through-signing/rsa-private-encrypt-app.c @@ -80,8 +80,10 @@ int main(void) return -99; } ret = (int) fwrite(out, 1, RSA_TEST_BYTES, fStream); - check_ret(ret, "fwrite the rsa key to file"); fclose(fStream); + if (ret <= 0) { + printf("Something went wrong writing to file %s\n", fName); + } return ret; } diff --git a/signature/encryption-through-signing/rsa-public-decrypt-app.c b/signature/encryption-through-signing/rsa-public-decrypt-app.c index 699b0862..4784f608 100644 --- a/signature/encryption-through-signing/rsa-public-decrypt-app.c +++ b/signature/encryption-through-signing/rsa-public-decrypt-app.c @@ -48,7 +48,7 @@ int main(void) /* Decode the public key from buffer "tmp" into RsaKey stucture "key" */ ret = wc_RsaPublicKeyDecode(tmp, &idx, &key, (word32)bytes); - check_ret(ret, "wc_RsaPrivateKeyDecode"); + check_ret(ret, "wc_RsaPublicKeyDecode"); fStream = fopen(fName, "rb"); if (!fStream) { @@ -56,8 +56,11 @@ int main(void) return -99; } ret = (int) fread(out, 1, RSA_TEST_BYTES, fStream); - check_ret(ret, "fread the rsa key to file"); fclose(fStream); + if (ret <= 0) { + printf("Something went wrong, please check the file: %s\n", fName); + return ret; + } idx = (word32)ret; /* number of bytes read in from the file */ XMEMSET(plain, 0, plainSz);