diff options
author | Richard Levitte <levitte@openssl.org> | 2020-11-04 16:14:00 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-11-13 09:35:31 +0100 |
commit | a150f8e1fcc38752fef4d7c75d765d8efc7d46d6 (patch) | |
tree | f7f62c9a5d8407d8b17820fbef67378aa7b9ddbb /crypto/cmp | |
parent | 9311d0c471ca2eaa259e8c1bbbeb7c46394c7ba2 (diff) |
CRYPTO: refactor ERR_raise()+ERR_add_error_data() to ERR_raise_data()
This is not done absolutely everywhere, as there are places where
the use of ERR_add_error_data() is quite complex, but at least the
simple cases are done.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13318)
Diffstat (limited to 'crypto/cmp')
-rw-r--r-- | crypto/cmp/cmp_client.c | 17 | ||||
-rw-r--r-- | crypto/cmp/cmp_msg.c | 16 | ||||
-rw-r--r-- | crypto/cmp/cmp_status.c | 10 |
3 files changed, 17 insertions, 26 deletions
diff --git a/crypto/cmp/cmp_client.c b/crypto/cmp/cmp_client.c index dd974413c0..c19eea818f 100644 --- a/crypto/cmp/cmp_client.c +++ b/crypto/cmp/cmp_client.c @@ -169,9 +169,9 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, ctx->msg_timeout = msg_timeout; /* restore original value */ if (*rep == NULL) { - ERR_raise(ERR_LIB_CMP, CMP_R_TRANSFER_ERROR); /* or receiving response */ - ERR_add_error_data(2, "request sent: ", req_type_str); - ERR_add_error_data(2, ", expected response: ", expected_type_str); + ERR_raise_data(ERR_LIB_CMP, CMP_R_TRANSFER_ERROR, /* or receiving response */ + "request sent: %s, expected response: %s", + req_type_str, expected_type_str); return 0; } @@ -633,11 +633,14 @@ static int cert_response(OSSL_CMP_CTX *ctx, int sleep, int rid, /* not throwing failure earlier as transfer_cb may call ERR_clear_error() */ if (fail_info != 0) { - ERR_raise(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_ACCEPTED); - ERR_add_error_data(2, "rejecting newly enrolled cert with subject: ", + if (txt == NULL) + ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_ACCEPTED, + "rejecting newly enrolled cert with subject: %s", subj); - if (txt != NULL) - ERR_add_error_txt("; ", txt); + else + ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTIFICATE_NOT_ACCEPTED, + "rejecting newly enrolled cert with subject: %s; %s", + subj, txt); ret = 0; } OPENSSL_free(subj); diff --git a/crypto/cmp/cmp_msg.c b/crypto/cmp/cmp_msg.c index eff093c6b5..1a4a873168 100644 --- a/crypto/cmp/cmp_msg.c +++ b/crypto/cmp/cmp_msg.c @@ -888,14 +888,6 @@ static int suitable_rid(const ASN1_INTEGER *certReqId, int rid) return rid == trid; } -static void add_expected_rid(int rid) -{ - char str[DECIMAL_SIZE(rid) + 1]; - - BIO_snprintf(str, sizeof(str), "%d", rid); - ERR_add_error_data(2, "expected certReqId = ", str); -} - /* * returns a pointer to the PollResponse with the given CertReqId * (or the first one in case -1) inside a PollRepContent @@ -917,8 +909,8 @@ ossl_cmp_pollrepcontent_get0_pollrep(const OSSL_CMP_POLLREPCONTENT *prc, return pollRep; } - ERR_raise(ERR_LIB_CMP, CMP_R_CERTRESPONSE_NOT_FOUND); - add_expected_rid(rid); + ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTRESPONSE_NOT_FOUND, + "expected certReqId = %d", rid); return NULL; } @@ -943,8 +935,8 @@ ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crm, return crep; } - ERR_raise(ERR_LIB_CMP, CMP_R_CERTRESPONSE_NOT_FOUND); - add_expected_rid(rid); + ERR_raise_data(ERR_LIB_CMP, CMP_R_CERTRESPONSE_NOT_FOUND, + "expected certReqId = %d", rid); return NULL; } diff --git a/crypto/cmp/cmp_status.c b/crypto/cmp/cmp_status.c index 1660906753..dc14f754de 100644 --- a/crypto/cmp/cmp_status.c +++ b/crypto/cmp/cmp_status.c @@ -53,13 +53,9 @@ const char *ossl_cmp_PKIStatus_to_string(int status) case OSSL_CMP_PKISTATUS_keyUpdateWarning: return "PKIStatus: key update warning - update already done for the cert"; default: - { - char buf[40]; - BIO_snprintf(buf, sizeof(buf), "PKIStatus: invalid=%d", status); - ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_PARSING_PKISTATUS); - ERR_add_error_data(1, buf); - return NULL; - } + ERR_raise_data(ERR_LIB_CMP, CMP_R_ERROR_PARSING_PKISTATUS, + "PKIStatus: invalid=%d", status); + return NULL; } } |