Skip to content

Commit

Permalink
doc: Refactored the example in crypto.pod
Browse files Browse the repository at this point in the history
Added return value and error code in the sample

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from #17721)

(cherry picked from commit 4a4f446)
  • Loading branch information
yangyangtiantianlonglong authored and mspncp committed Feb 20, 2022
1 parent 6ff03e3 commit 18e046c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/man7/crypto.pod
Expand Up @@ -380,6 +380,7 @@ encryption/decryption, signatures, message authentication codes, etc.
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/err.h>

int main(void)
{
Expand All @@ -390,6 +391,7 @@ encryption/decryption, signatures, message authentication codes, etc.
};
unsigned int len = 0;
unsigned char *outdigest = NULL;
int ret = 1;

/* Create a context for the digest operation */
ctx = EVP_MD_CTX_new();
Expand Down Expand Up @@ -430,11 +432,16 @@ encryption/decryption, signatures, message authentication codes, etc.
/* Print out the digest result */
BIO_dump_fp(stdout, outdigest, len);

ret = 0;

err:
/* Clean up all the resources we allocated */
OPENSSL_free(outdigest);
EVP_MD_free(sha256);
EVP_MD_CTX_free(ctx);
if (ret != 0)
ERR_print_errors_fp(stderr);
return ret;
}

=head1 CONFIGURATION
Expand Down

0 comments on commit 18e046c

Please sign in to comment.