Skip to content

Commit 09edb69

Browse files
committed
pkey: define and use OSSL_HAVE_IMMUTABLE_PKEY macro
Introduce a useful macro to avoid scattering *_PREREQ() checks everywhere. Currently, the macro is defined for OpenSSL 3.0 or later only. I think it is possible that LibreSSL may adopt it in the future.
1 parent 5f0e60e commit 09edb69

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

ext/openssl/ossl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
# define OSSL_USE_PROVIDER
7474
#endif
7575

76+
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
77+
# define OSSL_HAVE_IMMUTABLE_PKEY 1
78+
#endif
79+
7680
/*
7781
* Common Module
7882
*/

ext/openssl/ossl_pkey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self)
507507
void
508508
ossl_pkey_check_public_key(const EVP_PKEY *pkey)
509509
{
510-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
510+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
511511
if (EVP_PKEY_missing_parameters(pkey))
512512
ossl_raise(ePKeyError, "parameters missing");
513513
#else

ext/openssl/ossl_pkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static VALUE ossl_##_keytype##_get_##_name(VALUE self) \
105105
OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \
106106
_type##_get0_##_group(obj, NULL, &bn))
107107

108-
#if !OSSL_OPENSSL_PREREQ(3, 0, 0)
108+
#ifndef OSSL_HAVE_IMMUTABLE_PKEY
109109
#define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \
110110
/* \
111111
* call-seq: \

ext/openssl/ossl_pkey_ec.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ ossl_ec_key_get_group(VALUE self)
248248
static VALUE
249249
ossl_ec_key_set_group(VALUE self, VALUE group_v)
250250
{
251-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
251+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
252252
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
253253
#else
254254
EC_KEY *ec;
@@ -290,7 +290,7 @@ static VALUE ossl_ec_key_get_private_key(VALUE self)
290290
*/
291291
static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
292292
{
293-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
293+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
294294
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
295295
#else
296296
EC_KEY *ec;
@@ -341,7 +341,7 @@ static VALUE ossl_ec_key_get_public_key(VALUE self)
341341
*/
342342
static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
343343
{
344-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
344+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
345345
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
346346
#else
347347
EC_KEY *ec;
@@ -513,7 +513,7 @@ ossl_ec_key_to_der(VALUE self)
513513
*/
514514
static VALUE ossl_ec_key_generate_key(VALUE self)
515515
{
516-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
516+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
517517
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
518518
#else
519519
EC_KEY *ec;
@@ -1367,7 +1367,7 @@ static VALUE ossl_ec_point_make_affine(VALUE self)
13671367
GetECPointGroup(self, group);
13681368

13691369
rb_warn("OpenSSL::PKey::EC::Point#make_affine! is deprecated");
1370-
#if !OSSL_OPENSSL_PREREQ(3, 0, 0)
1370+
#ifndef OSSL_HAVE_IMMUTABLE_PKEY
13711371
if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
13721372
ossl_raise(eEC_POINT, "EC_POINT_make_affine");
13731373
#endif

0 commit comments

Comments
 (0)