From 00e824726e67ac60f4500af3e2eb04bc6165190b Mon Sep 17 00:00:00 2001 From: tb <> Date: Mon, 4 Jul 2022 12:22:32 +0000 Subject: Prepare to provide DSA_meth_{get0,set1}_name() Also follow OpenSSL by making the name non-const to avoid ugly casting. Used by OpenSC's pkcs11-helper, as reported by Fabrice Fontaine in https://github.com/libressl-portable/openbsd/issues/130 ok jsing sthen --- src/lib/libcrypto/dsa/dsa_meth.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/lib/libcrypto/dsa/dsa_meth.c') diff --git a/src/lib/libcrypto/dsa/dsa_meth.c b/src/lib/libcrypto/dsa/dsa_meth.c index cd232835eb..2cb0426d43 100644 --- a/src/lib/libcrypto/dsa/dsa_meth.c +++ b/src/lib/libcrypto/dsa/dsa_meth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_meth.c,v 1.3 2022/05/07 10:31:54 tb Exp $ */ +/* $OpenBSD: dsa_meth.c,v 1.4 2022/07/04 12:22:32 tb Exp $ */ /* * Copyright (c) 2018 Theo Buehler * @@ -42,10 +42,11 @@ DSA_meth_new(const char *name, int flags) void DSA_meth_free(DSA_METHOD *meth) { - if (meth != NULL) { - free((char *)meth->name); - free(meth); - } + if (meth == NULL) + return + + free(meth->name); + free(meth); } DSA_METHOD * @@ -64,6 +65,28 @@ DSA_meth_dup(const DSA_METHOD *meth) return copy; } +const char * +DSA_meth_get0_name(const DSA_METHOD *meth) +{ + return meth->name; +} + +int +DSA_meth_set1_name(DSA_METHOD *meth, const char *name) +{ + char *new_name; + + if ((new_name = strdup(name)) == NULL) { + DSAerror(ERR_R_MALLOC_FAILURE); + return 0; + } + + free(meth->name); + meth->name = new_name; + + return 1; +} + int DSA_meth_set_sign(DSA_METHOD *meth, DSA_SIG *(*sign)(const unsigned char *, int, DSA *)) -- cgit v1.2.3-55-g6feb