Skip to content

Commit 0acff8e

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 8752d9e commit 0acff8e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
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.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;
@@ -453,7 +453,7 @@ ossl_ec_key_to_der(VALUE self)
453453
*/
454454
static VALUE ossl_ec_key_generate_key(VALUE self)
455455
{
456-
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
456+
#ifdef OSSL_HAVE_PROVIDER
457457
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
458458
#else
459459
EC_KEY *ec;

0 commit comments

Comments
 (0)