Skip to content

Commit 54c1c26

Browse files
committed
pkey: rename ossl_pkey_new() to ossl_pkey_wrap()
Among functions named ossl_*_new(), ossl_pkey_new() is now the only one that takes ownership of the passed OpenSSL object instead of making a copy or incrementing its reference counter. Rename it to make this behavior easier to understand.
1 parent 7e0288e commit 54c1c26

File tree

8 files changed

+17
-17
lines changed

8 files changed

+17
-17
lines changed

ext/openssl/ossl_engine.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ ossl_engine_load_privkey(int argc, VALUE *argv, VALUE self)
320320
GetEngine(self, e);
321321
pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
322322
if (!pkey) ossl_raise(eEngineError, NULL);
323-
obj = ossl_pkey_new(pkey);
323+
obj = ossl_pkey_wrap(pkey);
324324
OSSL_PKEY_SET_PRIVATE(obj);
325325

326326
return obj;
@@ -350,7 +350,7 @@ ossl_engine_load_pubkey(int argc, VALUE *argv, VALUE self)
350350
pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
351351
if (!pkey) ossl_raise(eEngineError, NULL);
352352

353-
return ossl_pkey_new(pkey);
353+
return ossl_pkey_wrap(pkey);
354354
}
355355

356356
/*

ext/openssl/ossl_ns_spki.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ ossl_spki_get_public_key(VALUE self)
190190
ossl_raise(eSPKIError, NULL);
191191
}
192192

193-
return ossl_pkey_new(pkey); /* NO DUP - OK */
193+
return ossl_pkey_wrap(pkey);
194194
}
195195

196196
/*

ext/openssl/ossl_pkcs12.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
161161
}
162162

163163
static VALUE
164-
ossl_pkey_new_i(VALUE arg)
164+
ossl_pkey_wrap_i(VALUE arg)
165165
{
166-
return ossl_pkey_new((EVP_PKEY *)arg);
166+
return ossl_pkey_wrap((EVP_PKEY *)arg);
167167
}
168168

169169
static VALUE
@@ -211,7 +211,7 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
211211
if(!PKCS12_parse(pkcs, passphrase, &key, &x509, &x509s))
212212
ossl_raise(ePKCS12Error, "PKCS12_parse");
213213
if (key) {
214-
pkey = rb_protect(ossl_pkey_new_i, (VALUE)key, &st);
214+
pkey = rb_protect(ossl_pkey_wrap_i, (VALUE)key, &st);
215215
if (st) goto err;
216216
}
217217
if (x509) {

ext/openssl/ossl_pkey.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const rb_data_type_t ossl_evp_pkey_type = {
3939
};
4040

4141
static VALUE
42-
pkey_new0(VALUE arg)
42+
pkey_wrap0(VALUE arg)
4343
{
4444
EVP_PKEY *pkey = (EVP_PKEY *)arg;
4545
VALUE klass, obj;
@@ -65,12 +65,12 @@ pkey_new0(VALUE arg)
6565
}
6666

6767
VALUE
68-
ossl_pkey_new(EVP_PKEY *pkey)
68+
ossl_pkey_wrap(EVP_PKEY *pkey)
6969
{
7070
VALUE obj;
7171
int status;
7272

73-
obj = rb_protect(pkey_new0, (VALUE)pkey, &status);
73+
obj = rb_protect(pkey_wrap0, (VALUE)pkey, &status);
7474
if (status) {
7575
EVP_PKEY_free(pkey);
7676
rb_jump_tag(status);
@@ -239,7 +239,7 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
239239
BIO_free(bio);
240240
if (!pkey)
241241
ossl_raise(ePKeyError, "Could not parse PKey");
242-
return ossl_pkey_new(pkey);
242+
return ossl_pkey_wrap(pkey);
243243
}
244244

245245
static VALUE
@@ -443,7 +443,7 @@ pkey_generate(int argc, VALUE *argv, VALUE self, int genparam)
443443
}
444444
}
445445

446-
return ossl_pkey_new(gen_arg.pkey);
446+
return ossl_pkey_wrap(gen_arg.pkey);
447447
}
448448

449449
/*
@@ -687,7 +687,7 @@ ossl_pkey_new_raw_private_key(VALUE self, VALUE type, VALUE key)
687687
ossl_raise(ePKeyError, "EVP_PKEY_new_raw_private_key");
688688
#endif
689689

690-
return ossl_pkey_new(pkey);
690+
return ossl_pkey_wrap(pkey);
691691
}
692692

693693
/*
@@ -719,7 +719,7 @@ ossl_pkey_new_raw_public_key(VALUE self, VALUE type, VALUE key)
719719
ossl_raise(ePKeyError, "EVP_PKEY_new_raw_public_key");
720720
#endif
721721

722-
return ossl_pkey_new(pkey);
722+
return ossl_pkey_wrap(pkey);
723723
}
724724

725725
/*

ext/openssl/ossl_pkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern const rb_data_type_t ossl_evp_pkey_type;
2727
} while (0)
2828

2929
/* Takes ownership of the EVP_PKEY */
30-
VALUE ossl_pkey_new(EVP_PKEY *);
30+
VALUE ossl_pkey_wrap(EVP_PKEY *);
3131
void ossl_pkey_check_public_key(const EVP_PKEY *);
3232
EVP_PKEY *ossl_pkey_read_generic(BIO *, VALUE);
3333
EVP_PKEY *GetPKeyPtr(VALUE);

ext/openssl/ossl_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ ossl_ssl_tmp_key(VALUE self)
26422642
GetSSL(self, ssl);
26432643
if (!SSL_get_server_tmp_key(ssl, &key))
26442644
return Qnil;
2645-
return ossl_pkey_new(key);
2645+
return ossl_pkey_wrap(key);
26462646
}
26472647
#endif /* !defined(OPENSSL_NO_SOCK) */
26482648

ext/openssl/ossl_x509cert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ ossl_x509_get_public_key(VALUE self)
504504
ossl_raise(eX509CertError, NULL);
505505
}
506506

507-
return ossl_pkey_new(pkey); /* NO DUP - OK */
507+
return ossl_pkey_wrap(pkey);
508508
}
509509

510510
/*

ext/openssl/ossl_x509req.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ ossl_x509req_get_public_key(VALUE self)
289289
ossl_raise(eX509ReqError, NULL);
290290
}
291291

292-
return ossl_pkey_new(pkey); /* NO DUP - OK */
292+
return ossl_pkey_wrap(pkey);
293293
}
294294

295295
static VALUE

0 commit comments

Comments
 (0)