* Checks if the issuer of a certificate is a
* Certificate Authority, or if the certificate is the same
* as the issuer (and therefore it doesn't need to be a CA).
*
* Returns true or false, if the issuer is a CA,
* or not.
*/
static int
check_if_ca (gnutls_x509_crt_t cert, gnutls_x509_crt_t issuer,
unsigned int flags)
{
Sure, returns "true" or "false" which are not things in C. This actually returns either 0 or 1. Many C library functions return 0 for OK and non-zero for error. This one returns 0 for error and 1 for OK.Imagine you are reviewing the a call site of this code:
if (check_if_ca(...)) {
// CA is valid, proceed
}
vs. if (check_if_ca(...) == 0) {
// CA is valid, proceed
}
To the reviewer who is accustomed to strcmp, either of these might appear to be fine, meaning that the reviewer (or even the author) has to carefully check the documentation of this function.What else is wrong with this signature? For one thing it would be easy to swap the arguments around:
if (check_if_ca(cert, issuer, flags)) ...
if (check_if_ca(issuer, cert, flags)) ...
What's the difference? They both look reasonable. What are the valid/relevant values of |flags|?Would it be easier to comprehend |flags| if it were an options struct, e.g.
GNUTLSCertificateVerificationOptions opts;
opts.set_allow_rsa_md2(true);
...
cert.Verify(opts);
?Would it be easier to verify the correctness of a call site of check_if_ca if it looked like this:
if (issuer_cert.IsCA() || cert == issuer_cert) ...
Where are the unit tests. The unit tests should be right here in the lib directory as whatever_unittest.c, adjacent to the source file they are testing, so you don't have to go groping around in the tree trying to find the relevant test, if it even exists. By the way, I found no test that calls this function.Basically this code has all the same problems as the Apple code, except for the mixed tabs/spaces stuff (as far as I can tell). It would be shameful for any professional programmer or organization of programmers to create this code.