Skip to content

Commit 6a14a59

Browse files
committed
Remove SafeGet*() macros
They are no longer useful since we use the TypedData_Get_Struct() which also performs type checking (based on the rb_data_type_t) for the non-safe Get*() macros. Just use them instead.
1 parent fa51e0c commit 6a14a59

22 files changed

+71
-186
lines changed

ext/openssl/ossl_bn.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
} \
2727
} while (0)
2828

29-
#define SafeGetBN(obj, bn) do { \
30-
OSSL_Check_Kind((obj), cBN); \
31-
GetBN((obj), (bn)); \
32-
} while (0)
33-
3429
static void
3530
ossl_bn_free(void *ptr)
3631
{

ext/openssl/ossl_cipher.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
ossl_raise(rb_eRuntimeError, "Cipher not inititalized!"); \
2727
} \
2828
} while (0)
29-
#define SafeGetCipher(obj, ctx) do { \
30-
OSSL_Check_Kind((obj), cCipher); \
31-
GetCipher((obj), (ctx)); \
32-
} while (0)
3329

3430
/*
3531
* Classes
@@ -146,7 +142,7 @@ ossl_cipher_copy(VALUE self, VALUE other)
146142
if (!ctx1) {
147143
AllocCipher(self, ctx1);
148144
}
149-
SafeGetCipher(other, ctx2);
145+
GetCipher(other, ctx2);
150146
if (EVP_CIPHER_CTX_copy(ctx1, ctx2) != 1)
151147
ossl_raise(eCipherError, NULL);
152148

ext/openssl/ossl_digest.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
ossl_raise(rb_eRuntimeError, "Digest CTX wasn't initialized!"); \
1616
} \
1717
} while (0)
18-
#define SafeGetDigest(obj, ctx) do { \
19-
OSSL_Check_Kind((obj), cDigest); \
20-
GetDigest((obj), (ctx)); \
21-
} while (0)
2218

2319
/*
2420
* Classes
@@ -65,7 +61,7 @@ GetDigestPtr(VALUE obj)
6561
} else {
6662
EVP_MD_CTX *ctx;
6763

68-
SafeGetDigest(obj, ctx);
64+
GetDigest(obj, ctx);
6965

7066
md = EVP_MD_CTX_md(ctx);
7167
}
@@ -158,7 +154,7 @@ ossl_digest_copy(VALUE self, VALUE other)
158154
if (!ctx1)
159155
ossl_raise(eDigestError, "EVP_MD_CTX_new");
160156
}
161-
SafeGetDigest(other, ctx2);
157+
GetDigest(other, ctx2);
162158

163159
if (!EVP_MD_CTX_copy(ctx1, ctx2)) {
164160
ossl_raise(eDigestError, NULL);

ext/openssl/ossl_engine.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
2626
} \
2727
} while (0)
28-
#define SafeGetEngine(obj, engine) do { \
29-
OSSL_Check_Kind((obj), cEngine); \
30-
GetPKCS7((obj), (engine)); \
31-
} while (0)
3228

3329
/*
3430
* Classes

ext/openssl/ossl_hmac.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
ossl_raise(rb_eRuntimeError, "HMAC wasn't initialized"); \
2020
} \
2121
} while (0)
22-
#define SafeGetHMAC(obj, ctx) do { \
23-
OSSL_Check_Kind((obj), cHMAC); \
24-
GetHMAC((obj), (ctx)); \
25-
} while (0)
2622

2723
/*
2824
* Classes
@@ -124,7 +120,7 @@ ossl_hmac_copy(VALUE self, VALUE other)
124120
if (self == other) return self;
125121

126122
GetHMAC(self, ctx1);
127-
SafeGetHMAC(other, ctx2);
123+
GetHMAC(other, ctx2);
128124

129125
if (!HMAC_CTX_copy(ctx1, ctx2))
130126
ossl_raise(eHMACError, "HMAC_CTX_copy");

ext/openssl/ossl_ocsp.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
TypedData_Get_Struct((obj), OCSP_REQUEST, &ossl_ocsp_request_type, (req)); \
2323
if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
2424
} while (0)
25-
#define SafeGetOCSPReq(obj, req) do { \
26-
OSSL_Check_Kind((obj), cOCSPReq); \
27-
GetOCSPReq((obj), (req)); \
28-
} while (0)
2925

3026
#define NewOCSPRes(klass) \
3127
TypedData_Wrap_Struct((klass), &ossl_ocsp_response_type, 0)
@@ -37,10 +33,6 @@
3733
TypedData_Get_Struct((obj), OCSP_RESPONSE, &ossl_ocsp_response_type, (res)); \
3834
if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
3935
} while (0)
40-
#define SafeGetOCSPRes(obj, res) do { \
41-
OSSL_Check_Kind((obj), cOCSPRes); \
42-
GetOCSPRes((obj), (res)); \
43-
} while (0)
4436

4537
#define NewOCSPBasicRes(klass) \
4638
TypedData_Wrap_Struct((klass), &ossl_ocsp_basicresp_type, 0)
@@ -52,10 +44,6 @@
5244
TypedData_Get_Struct((obj), OCSP_BASICRESP, &ossl_ocsp_basicresp_type, (res)); \
5345
if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
5446
} while (0)
55-
#define SafeGetOCSPBasicRes(obj, res) do { \
56-
OSSL_Check_Kind((obj), cOCSPBasicRes); \
57-
GetOCSPBasicRes((obj), (res)); \
58-
} while (0)
5947

6048
#define NewOCSPSingleRes(klass) \
6149
TypedData_Wrap_Struct((klass), &ossl_ocsp_singleresp_type, 0)
@@ -67,10 +55,6 @@
6755
TypedData_Get_Struct((obj), OCSP_SINGLERESP, &ossl_ocsp_singleresp_type, (res)); \
6856
if(!(res)) ossl_raise(rb_eRuntimeError, "SingleResponse wasn't initialized!"); \
6957
} while (0)
70-
#define SafeGetOCSPSingleRes(obj, res) do { \
71-
OSSL_Check_Kind((obj), cOCSPSingleRes); \
72-
GetOCSPSingleRes((obj), (res)); \
73-
} while (0)
7458

7559
#define NewOCSPCertId(klass) \
7660
TypedData_Wrap_Struct((klass), &ossl_ocsp_certid_type, 0)
@@ -82,10 +66,6 @@
8266
TypedData_Get_Struct((obj), OCSP_CERTID, &ossl_ocsp_certid_type, (cid)); \
8367
if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
8468
} while (0)
85-
#define SafeGetOCSPCertId(obj, cid) do { \
86-
OSSL_Check_Kind((obj), cOCSPCertId); \
87-
GetOCSPCertId((obj), (cid)); \
88-
} while (0)
8969

9070
VALUE mOCSP;
9171
VALUE eOCSPError;
@@ -200,7 +180,7 @@ ossl_ocspreq_initialize_copy(VALUE self, VALUE other)
200180

201181
rb_check_frozen(self);
202182
GetOCSPReq(self, req_old);
203-
SafeGetOCSPReq(other, req);
183+
GetOCSPReq(other, req);
204184

205185
req_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_REQUEST), req);
206186
if (!req_new)
@@ -304,7 +284,7 @@ ossl_ocspreq_check_nonce(VALUE self, VALUE basic_resp)
304284
int res;
305285

306286
GetOCSPReq(self, req);
307-
SafeGetOCSPBasicRes(basic_resp, bs);
287+
GetOCSPBasicRes(basic_resp, bs);
308288
res = OCSP_check_nonce(req, bs);
309289

310290
return INT2NUM(res);
@@ -521,7 +501,7 @@ ossl_ocspres_initialize_copy(VALUE self, VALUE other)
521501

522502
rb_check_frozen(self);
523503
GetOCSPRes(self, res_old);
524-
SafeGetOCSPRes(other, res);
504+
GetOCSPRes(other, res);
525505

526506
res_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_RESPONSE), res);
527507
if (!res_new)
@@ -677,7 +657,7 @@ ossl_ocspbres_initialize_copy(VALUE self, VALUE other)
677657

678658
rb_check_frozen(self);
679659
GetOCSPBasicRes(self, bs_old);
680-
SafeGetOCSPBasicRes(other, bs);
660+
GetOCSPBasicRes(other, bs);
681661

682662
bs_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_BASICRESP), bs);
683663
if (!bs_new)
@@ -736,7 +716,7 @@ ossl_ocspbres_copy_nonce(VALUE self, VALUE request)
736716
int ret;
737717

738718
GetOCSPBasicRes(self, bs);
739-
SafeGetOCSPReq(request, req);
719+
GetOCSPReq(request, req);
740720
ret = OCSP_copy_nonce(bs, req);
741721

742722
return INT2NUM(ret);
@@ -829,7 +809,7 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
829809
VALUE tmp;
830810

831811
GetOCSPBasicRes(self, bs);
832-
SafeGetOCSPCertId(cid, id);
812+
GetOCSPCertId(cid, id);
833813
st = NUM2INT(status);
834814
if (!NIL_P(ext)) { /* All ext's members must be X509::Extension */
835815
ext = rb_check_array_type(ext);
@@ -988,7 +968,7 @@ ossl_ocspbres_find_response(VALUE self, VALUE target)
988968
OCSP_CERTID *id;
989969
int n;
990970

991-
SafeGetOCSPCertId(target, id);
971+
GetOCSPCertId(target, id);
992972
GetOCSPBasicRes(self, bs);
993973

994974
if ((n = OCSP_resp_find(bs, id, -1)) == -1)
@@ -1213,7 +1193,7 @@ ossl_ocspsres_initialize_copy(VALUE self, VALUE other)
12131193

12141194
rb_check_frozen(self);
12151195
GetOCSPSingleRes(self, sres_old);
1216-
SafeGetOCSPSingleRes(other, sres);
1196+
GetOCSPSingleRes(other, sres);
12171197

12181198
sres_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_SINGLERESP), sres);
12191199
if (!sres_new)
@@ -1468,7 +1448,7 @@ ossl_ocspcid_initialize_copy(VALUE self, VALUE other)
14681448

14691449
rb_check_frozen(self);
14701450
GetOCSPCertId(self, cid_old);
1471-
SafeGetOCSPCertId(other, cid);
1451+
GetOCSPCertId(other, cid);
14721452

14731453
cid_new = OCSP_CERTID_dup(cid);
14741454
if (!cid_new)
@@ -1543,7 +1523,7 @@ ossl_ocspcid_cmp(VALUE self, VALUE other)
15431523
int result;
15441524

15451525
GetOCSPCertId(self, id);
1546-
SafeGetOCSPCertId(other, id2);
1526+
GetOCSPCertId(other, id2);
15471527
result = OCSP_id_cmp(id, id2);
15481528

15491529
return (result == 0) ? Qtrue : Qfalse;
@@ -1564,7 +1544,7 @@ ossl_ocspcid_cmp_issuer(VALUE self, VALUE other)
15641544
int result;
15651545

15661546
GetOCSPCertId(self, id);
1567-
SafeGetOCSPCertId(other, id2);
1547+
GetOCSPCertId(other, id2);
15681548
result = OCSP_id_issuer_cmp(id, id2);
15691549

15701550
return (result == 0) ? Qtrue : Qfalse;

ext/openssl/ossl_pkcs12.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
1818
} while (0)
1919

20-
#define SafeGetPKCS12(obj, p12) do { \
21-
OSSL_Check_Kind((obj), cPKCS12); \
22-
GetPKCS12((obj), (p12)); \
23-
} while (0)
24-
2520
#define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v))
2621
#define ossl_pkcs12_set_cert(o,v) rb_iv_set((o), "@certificate", (v))
2722
#define ossl_pkcs12_set_ca_certs(o,v) rb_iv_set((o), "@ca_certs", (v))
@@ -72,7 +67,7 @@ ossl_pkcs12_initialize_copy(VALUE self, VALUE other)
7267

7368
rb_check_frozen(self);
7469
GetPKCS12(self, p12_old);
75-
SafeGetPKCS12(other, p12);
70+
GetPKCS12(other, p12);
7671

7772
p12_new = ASN1_dup((i2d_of_void *)i2d_PKCS12, (d2i_of_void *)d2i_PKCS12, (char *)p12);
7873
if (!p12_new)

ext/openssl/ossl_pkcs7.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
2424
} \
2525
} while (0)
26-
#define SafeGetPKCS7(obj, pkcs7) do { \
27-
OSSL_Check_Kind((obj), cPKCS7); \
28-
GetPKCS7((obj), (pkcs7)); \
29-
} while (0)
3026

3127
#define NewPKCS7si(klass) \
3228
TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
@@ -42,10 +38,6 @@
4238
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
4339
} \
4440
} while (0)
45-
#define SafeGetPKCS7si(obj, p7si) do { \
46-
OSSL_Check_Kind((obj), cPKCS7Signer); \
47-
GetPKCS7si((obj), (p7si)); \
48-
} while (0)
4941

5042
#define NewPKCS7ri(klass) \
5143
TypedData_Wrap_Struct((klass), &ossl_pkcs7_recip_info_type, 0)
@@ -61,10 +53,6 @@
6153
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
6254
} \
6355
} while (0)
64-
#define SafeGetPKCS7ri(obj, p7ri) do { \
65-
OSSL_Check_Kind((obj), cPKCS7Recipient); \
66-
GetPKCS7ri((obj), (p7ri)); \
67-
} while (0)
6856

6957
#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
7058

@@ -162,7 +150,7 @@ DupPKCS7SignerPtr(VALUE obj)
162150
{
163151
PKCS7_SIGNER_INFO *p7si, *pkcs7;
164152

165-
SafeGetPKCS7si(obj, p7si);
153+
GetPKCS7si(obj, p7si);
166154
if (!(pkcs7 = ossl_PKCS7_SIGNER_INFO_dup(p7si))) {
167155
ossl_raise(ePKCS7Error, NULL);
168156
}
@@ -189,7 +177,7 @@ DupPKCS7RecipientPtr(VALUE obj)
189177
{
190178
PKCS7_RECIP_INFO *p7ri, *pkcs7;
191179

192-
SafeGetPKCS7ri(obj, p7ri);
180+
GetPKCS7ri(obj, p7ri);
193181
if (!(pkcs7 = ossl_PKCS7_RECIP_INFO_dup(p7ri))) {
194182
ossl_raise(ePKCS7Error, NULL);
195183
}
@@ -238,7 +226,7 @@ ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
238226
rb_scan_args(argc, argv, "12", &pkcs7, &data, &flags);
239227
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
240228
if(NIL_P(data)) data = ossl_pkcs7_get_data(pkcs7);
241-
SafeGetPKCS7(pkcs7, p7);
229+
GetPKCS7(pkcs7, p7);
242230
if(!NIL_P(data) && PKCS7_is_detached(p7))
243231
flg |= PKCS7_DETACHED;
244232
in = NIL_P(data) ? NULL : ossl_obj2bio(data);
@@ -414,7 +402,7 @@ ossl_pkcs7_copy(VALUE self, VALUE other)
414402
if (self == other) return self;
415403

416404
GetPKCS7(self, a);
417-
SafeGetPKCS7(other, b);
405+
GetPKCS7(other, b);
418406

419407
pkcs7 = PKCS7_dup(b);
420408
if (!pkcs7) {

ext/openssl/ossl_pkey.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ GetPKeyPtr(VALUE obj)
207207
{
208208
EVP_PKEY *pkey;
209209

210-
SafeGetPKey(obj, pkey);
210+
GetPKey(obj, pkey);
211211

212212
return pkey;
213213
}
@@ -220,7 +220,7 @@ GetPrivPKeyPtr(VALUE obj)
220220
if (rb_funcallv(obj, id_private_q, 0, NULL) != Qtrue) {
221221
ossl_raise(rb_eArgError, "Private key is needed.");
222222
}
223-
SafeGetPKey(obj, pkey);
223+
GetPKey(obj, pkey);
224224

225225
return pkey;
226226
}
@@ -230,7 +230,7 @@ DupPKeyPtr(VALUE obj)
230230
{
231231
EVP_PKEY *pkey;
232232

233-
SafeGetPKey(obj, pkey);
233+
GetPKey(obj, pkey);
234234
EVP_PKEY_up_ref(pkey);
235235

236236
return pkey;

ext/openssl/ossl_pkey.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ extern const rb_data_type_t ossl_evp_pkey_type;
3434
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\
3535
} \
3636
} while (0)
37-
#define SafeGetPKey(obj, pkey) do { \
38-
OSSL_Check_Kind((obj), cPKey); \
39-
GetPKey((obj), (pkey)); \
40-
} while (0)
4137

4238
struct ossl_generate_cb_arg {
4339
int yield;

0 commit comments

Comments
 (0)