Skip to content

Commit

Permalink
Clean up the by_file_ctrl x509 code to be slightly less obtuse
Browse files Browse the repository at this point in the history
Change-Id: I3591d3c0e1d189760352857fe147179a759c98fb
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64327
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
(cherry picked from commit 72a2bf4ebde4637223c9351c45cfc074edb2a464)
  • Loading branch information
Bob Beck authored and torben-hansen committed Apr 19, 2024
1 parent 45c46c2 commit 62e019f
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions crypto/x509/by_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,24 @@ X509_LOOKUP_METHOD *X509_LOOKUP_file(void) { return &x509_file_lookup; }

static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
char **ret) {
int ok = 0;
const char *file;

switch (cmd) {
case X509_L_FILE_LOAD:
if (argl == X509_FILETYPE_DEFAULT) {
file = getenv(X509_get_default_cert_file_env());
if (file) {
ok = (X509_load_cert_crl_file(ctx, file, X509_FILETYPE_PEM) != 0);
}

else {
ok = (X509_load_cert_crl_file(ctx, X509_get_default_cert_file(),
X509_FILETYPE_PEM) != 0);
}

if (!ok) {
OPENSSL_PUT_ERROR(X509, X509_R_LOADING_DEFAULTS);
}
} else {
if (argl == X509_FILETYPE_PEM) {
ok = (X509_load_cert_crl_file(ctx, argp, X509_FILETYPE_PEM) != 0);
} else {
ok = (X509_load_cert_file(ctx, argp, (int)argl) != 0);
}
}
break;
if (cmd != X509_L_FILE_LOAD) {
return 0;
}
const char *file = argp;
int type = argl;
if (argl == X509_FILETYPE_DEFAULT) {
if ((file = getenv(X509_get_default_cert_file_env())) == NULL) {
file = X509_get_default_cert_file();
}
type = X509_FILETYPE_PEM;
}
if (X509_load_cert_crl_file(ctx, file, type) != 0) {
return 1;
}
if (argl == X509_FILETYPE_DEFAULT) {
OPENSSL_PUT_ERROR(X509, X509_R_LOADING_DEFAULTS);
}
return ok;
return 0;
}

int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) {
Expand Down

0 comments on commit 62e019f

Please sign in to comment.