Understanding the OpenSSL error queue
When running the rsa-encrypt
program, many things can go wrong, such as the following:
- The public key file may be corrupted or not contain a key. In this case, key loading will fail.
- The public key file may contain a non-RSA key. In this case, key loading will succeed, but encryption will fail.
- The input file may be too big. In this case, encryption will also fail but for another reason.
How do we handle such errors? Those OpenSSL functions that can fail usually indicate so by returning NULL
, 0
, or a negative number. Success is usually indicated by returning 1
. Some functions also add an error to the OpenSSL error queue on failure.
The OpenSSL error queue is a container for errors that the OpenSSL library wants to report. Every thread of the process has its own OpenSSL error queue. The error queue does not require initialization or uninitialization; OpenSSL automatically handles it. Every thread starts with an empty error...