summaryrefslogtreecommitdiffstats
path: root/demos/digest
diff options
context:
space:
mode:
authorslontis <shane.lontis@oracle.com>2023-03-20 14:48:33 +1000
committerTomas Mraz <tomas@openssl.org>2023-04-24 14:39:19 +0200
commit09ff84bd2752cac649f57cfbf95b49dbce1c69ee (patch)
tree9a3dbf4aa9835f2be7d874cde743f6dfa1de6293 /demos/digest
parenta80840c663e3409203b0235764e53d8624f74cb8 (diff)
Fixup demo exit status magic numbers
The demo code is quite often block copied for new demos, so this PR changes demos to use EXIT_SUCCESS & EXIT_FAILURE instead of using 0 and 1. Internal functions use the normal notation of 0 = error, 1 = success, but the value returned by main() must use EXIT_SUCCESS and EXIT_FAILURE. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20545)
Diffstat (limited to 'demos/digest')
-rw-r--r--demos/digest/BIO_f_md.c15
-rw-r--r--demos/digest/EVP_MD_demo.c11
-rw-r--r--demos/digest/EVP_MD_stdin.c16
-rw-r--r--demos/digest/EVP_MD_xof.c6
4 files changed, 24 insertions, 24 deletions
diff --git a/demos/digest/BIO_f_md.c b/demos/digest/BIO_f_md.c
index 0a1f319f11..1317e82237 100644
--- a/demos/digest/BIO_f_md.c
+++ b/demos/digest/BIO_f_md.c
@@ -36,15 +36,14 @@
int main(int argc, char * argv[])
{
- int result = 1;
+ int ret = EXIT_FAILURE;
OSSL_LIB_CTX *library_context = NULL;
BIO *input = NULL;
- BIO *bio_digest = NULL;
+ BIO *bio_digest = NULL, *reading = NULL;
EVP_MD *md = NULL;
unsigned char buffer[512];
- size_t readct, writect;
size_t digest_size;
- char *digest_value=NULL;
+ char *digest_value = NULL;
int j;
input = BIO_new_fd(fileno(stdin), 1);
@@ -89,7 +88,7 @@ int main(int argc, char * argv[])
* We will use BIO chaining so that as we read, the digest gets updated
* See the man page for BIO_push
*/
- BIO *reading = BIO_push(bio_digest, input);
+ reading = BIO_push(bio_digest, input);
while (BIO_read(reading, buffer, sizeof(buffer)) > 0)
;
@@ -106,10 +105,10 @@ int main(int argc, char * argv[])
fprintf(stdout, "%02x", (unsigned char)digest_value[j]);
}
fprintf(stdout, "\n");
- result = 0;
+ ret = EXIT_SUCCESS;
cleanup:
- if (result != 0)
+ if (ret != EXIT_SUCCESS)
ERR_print_errors_fp(stderr);
OPENSSL_free(digest_value);
@@ -118,5 +117,5 @@ cleanup:
EVP_MD_free(md);
OSSL_LIB_CTX_free(library_context);
- return result;
+ return ret;
}
diff --git a/demos/digest/EVP_MD_demo.c b/demos/digest/EVP_MD_demo.c
index e406801aff..51a87559d2 100644
--- a/demos/digest/EVP_MD_demo.c
+++ b/demos/digest/EVP_MD_demo.c
@@ -79,7 +79,7 @@ const unsigned char known_answer[] = {
int demonstrate_digest(void)
{
OSSL_LIB_CTX *library_context;
- int result = 0;
+ int ret = 0;
const char *option_properties = NULL;
EVP_MD *message_digest = NULL;
EVP_MD_CTX *digest_context = NULL;
@@ -161,12 +161,11 @@ int demonstrate_digest(void)
fprintf(stdout, "\nDigest does not match known answer\n");
} else {
fprintf(stdout, "Digest computed properly.\n");
- result = 1;
+ ret = 1;
}
-
cleanup:
- if (result != 1)
+ if (ret != 1)
ERR_print_errors_fp(stderr);
/* OpenSSL free functions will ignore NULL arguments */
EVP_MD_CTX_free(digest_context);
@@ -174,10 +173,10 @@ cleanup:
EVP_MD_free(message_digest);
OSSL_LIB_CTX_free(library_context);
- return result;
+ return ret;
}
int main(void)
{
- return demonstrate_digest() == 0;
+ return demonstrate_digest() ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/demos/digest/EVP_MD_stdin.c b/demos/digest/EVP_MD_stdin.c
index 43a820f945..6990b721c5 100644
--- a/demos/digest/EVP_MD_stdin.c
+++ b/demos/digest/EVP_MD_stdin.c
@@ -34,7 +34,7 @@
int demonstrate_digest(BIO *input)
{
OSSL_LIB_CTX *library_context = NULL;
- int result = 0;
+ int ret = 0;
const char * option_properties = NULL;
EVP_MD *message_digest = NULL;
EVP_MD_CTX *digest_context = NULL;
@@ -103,14 +103,14 @@ int demonstrate_digest(BIO *input)
fprintf(stderr, "EVP_DigestFinal() failed.\n");
goto cleanup;
}
- result = 1;
+ ret = 1;
for (ii=0; ii<digest_length; ii++) {
fprintf(stdout, "%02x", digest_value[ii]);
}
fprintf(stdout, "\n");
cleanup:
- if (result != 1)
+ if (ret != 1)
ERR_print_errors_fp(stderr);
/* OpenSSL free functions will ignore NULL arguments */
EVP_MD_CTX_free(digest_context);
@@ -118,17 +118,19 @@ cleanup:
EVP_MD_free(message_digest);
OSSL_LIB_CTX_free(library_context);
- return result;
+ return ret;
}
int main(void)
{
- int result = 1;
+ int ret = EXIT_FAILURE;
BIO *input = BIO_new_fd(fileno(stdin), 1);
if (input != NULL) {
- result = demonstrate_digest(input);
+ ret = (demonstrate_digest(input) ? EXIT_SUCCESS : EXIT_FAILURE);
BIO_free(input);
}
- return result;
+ if (ret != EXIT_SUCCESS)
+ ERR_print_errors_fp(stderr);
+ return ret;
}
diff --git a/demos/digest/EVP_MD_xof.c b/demos/digest/EVP_MD_xof.c
index f31c047164..c2bd1a9fc5 100644
--- a/demos/digest/EVP_MD_xof.c
+++ b/demos/digest/EVP_MD_xof.c
@@ -43,7 +43,7 @@ static const char *propq = NULL;
int main(int argc, char **argv)
{
- int rv = 1;
+ int ret = EXIT_FAILURE;
OSSL_LIB_CTX *libctx = NULL;
EVP_MD *md = NULL;
EVP_MD_CTX *ctx = NULL;
@@ -122,11 +122,11 @@ int main(int argc, char **argv)
}
}
- rv = 0;
+ ret = EXIT_SUCCESS;
end:
OPENSSL_free(digest);
EVP_MD_CTX_free(ctx);
EVP_MD_free(md);
OSSL_LIB_CTX_free(libctx);
- return rv;
+ return ret;
}