Skip to content

Commit 5a437e0

Browse files
committed
ossl.h: add OSSL_HAVE_PROVIDER macro
With providers, pkeys are immutable and we should avoid using low-level types such as RSA or EC_KEY. Use this special macro instead of version numbers to make the intention clear, and also to make it easier to update when LibreSSL gains OpenSSL 3.0 providers support.
1 parent e25de6b commit 5a437e0

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

ext/openssl/ossl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
# define OSSL_USE_ENGINE
5757
#endif
5858

59+
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
60+
# define OSSL_HAVE_PROVIDER
61+
#endif
62+
5963
/*
6064
* Common Module
6165
*/

ext/openssl/ossl_pkey.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ossl_pkey_new(EVP_PKEY *pkey)
7979
return obj;
8080
}
8181

82-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
82+
#ifdef OSSL_HAVE_PROVIDER
8383
# include <openssl/decoder.h>
8484

8585
EVP_PKEY *
@@ -484,7 +484,7 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self)
484484
void
485485
ossl_pkey_check_public_key(const EVP_PKEY *pkey)
486486
{
487-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
487+
#ifdef OSSL_HAVE_PROVIDER
488488
if (EVP_PKEY_missing_parameters(pkey))
489489
ossl_raise(ePKeyError, "parameters missing");
490490
#else

ext/openssl/ossl_pkey.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static VALUE ossl_##_keytype##_get_##_name(VALUE self) \
116116
OSSL_PKEY_BN_DEF_GETTER0(_keytype, _type, a2, \
117117
_type##_get0_##_group(obj, NULL, &bn))
118118

119-
#if !OSSL_OPENSSL_PREREQ(3, 0, 0)
119+
#ifndef OSSL_HAVE_PROVIDER
120120
#define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \
121121
/* \
122122
* call-seq: \
@@ -174,7 +174,7 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \
174174
} \
175175
return self; \
176176
}
177-
#else
177+
#else /* OSSL_HAVE_PROVIDER */
178178
#define OSSL_PKEY_BN_DEF_SETTER3(_keytype, _type, _group, a1, a2, a3) \
179179
static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALUE v3) \
180180
{ \
@@ -188,7 +188,7 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \
188188
rb_raise(ePKeyError, \
189189
#_keytype"#set_"#_group"= is incompatible with OpenSSL 3.0"); \
190190
}
191-
#endif
191+
#endif /* OSSL_HAVE_PROVIDER */
192192

193193
#define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3) \
194194
OSSL_PKEY_BN_DEF_GETTER3(_keytype, _type, _group, a1, a2, a3) \

ext/openssl/ossl_pkey_ec.c

Lines changed: 4 additions & 4 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_PROVIDER
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_PROVIDER
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_PROVIDER
345345
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
346346
#else
347347
EC_KEY *ec;
@@ -457,7 +457,7 @@ ossl_ec_key_to_der(VALUE self)
457457
*/
458458
static VALUE ossl_ec_key_generate_key(VALUE self)
459459
{
460-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
460+
#ifdef OSSL_HAVE_PROVIDER
461461
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
462462
#else
463463
EC_KEY *ec;

0 commit comments

Comments
 (0)