diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2021-08-06 12:11:13 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2022-01-07 10:42:44 +0100 |
commit | 9944df112ffbe4b6855b6a9bf88720803277cc23 (patch) | |
tree | 7b4a15397f1015c166ef46047d1cade93e3a0068 /crypto/asn1/x_algor.c | |
parent | APPS load_key_certs_crls(): Make file access errors much more readable (diff) | |
download | openssl-9944df112ffbe4b6855b6a9bf88720803277cc23.tar.xz openssl-9944df112ffbe4b6855b6a9bf88720803277cc23.zip |
asn1/x_algor.c: add internal ossl_X509_ALGOR_from_nid() simplifying code
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17363)
Diffstat (limited to 'crypto/asn1/x_algor.c')
-rw-r--r-- | crypto/asn1/x_algor.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/crypto/asn1/x_algor.c b/crypto/asn1/x_algor.c index c0a5f76803..f56ec92f65 100644 --- a/crypto/asn1/x_algor.c +++ b/crypto/asn1/x_algor.c @@ -43,7 +43,7 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) ASN1_OBJECT_free(alg->algorithm); alg->algorithm = aobj; - if (ptype == 0) + if (ptype == V_ASN1_EOC) return 1; if (ptype == V_ASN1_UNDEF) { ASN1_TYPE_free(alg->parameter); @@ -53,6 +53,25 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) return 1; } +X509_ALGOR *ossl_X509_ALGOR_from_nid(int nid, int ptype, void *pval) +{ + ASN1_OBJECT *algo = OBJ_nid2obj(nid); + X509_ALGOR *alg = NULL; + + if (algo == NULL) + return NULL; + if ((alg = X509_ALGOR_new()) == NULL) + goto err; + if (X509_ALGOR_set0(alg, algo, ptype, pval)) + return alg; + alg->algorithm = NULL; /* precaution to prevent double free */ + + err: + X509_ALGOR_free(alg); + ASN1_OBJECT_free(algo); + return NULL; +} + void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, const void **ppval, const X509_ALGOR *algor) { @@ -176,15 +195,12 @@ int ossl_x509_algor_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md) goto err; if (ASN1_item_pack(algtmp, ASN1_ITEM_rptr(X509_ALGOR), &stmp) == NULL) goto err; - *palg = X509_ALGOR_new(); + *palg = ossl_X509_ALGOR_from_nid(NID_mgf1, V_ASN1_SEQUENCE, stmp); if (*palg == NULL) goto err; - X509_ALGOR_set0(*palg, OBJ_nid2obj(NID_mgf1), V_ASN1_SEQUENCE, stmp); stmp = NULL; err: ASN1_STRING_free(stmp); X509_ALGOR_free(algtmp); - if (*palg != NULL) - return 1; - return 0; + return *palg != NULL; } |