diff options
author | Ben Toews <mastahyeti@gmail.com> | 2018-06-21 10:26:30 -0600 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2019-10-01 11:25:06 +1300 |
commit | 23ae5c9cbf43dec30b138b952982f6212940943d (patch) | |
tree | 3dda9dfde0f1a55854a68e7f64a0fd6c7eaacb70 /ext/openssl | |
parent | f201e3282ec0f93cb6e199dfbed4e80c0f57714b (diff) | |
download | ruby-openssl-23ae5c9cbf43dec30b138b952982f6212940943d.tar.gz |
ts: get tests running/passing
A number of conventions seem to have changed, causing a fair bit of breakage:
- `Data_*` was deprecated in favor of `TypedData_*`
- `ossl_obj2bio` takes a `VALUE*` instead of `VALUE` now
- `time_to_time_t()` was removed
Diffstat (limited to 'ext/openssl')
-rw-r--r-- | ext/openssl/ossl_pkcs7.c | 17 | ||||
-rw-r--r-- | ext/openssl/ossl_pkcs7.h | 16 | ||||
-rwxr-xr-x | ext/openssl/ossl_ts.c | 22 |
3 files changed, 31 insertions, 24 deletions
diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c index a8148d53..ea8e92d1 100644 --- a/ext/openssl/ossl_pkcs7.c +++ b/ext/openssl/ossl_pkcs7.c @@ -9,21 +9,6 @@ */ #include "ossl.h" -#define NewPKCS7(klass) \ - TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0) -#define SetPKCS7(obj, pkcs7) do { \ - if (!(pkcs7)) { \ - ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ - } \ - RTYPEDDATA_DATA(obj) = (pkcs7); \ -} while (0) -#define GetPKCS7(obj, pkcs7) do { \ - TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \ - if (!(pkcs7)) { \ - ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ - } \ -} while (0) - #define NewPKCS7si(klass) \ TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0) #define SetPKCS7si(obj, p7si) do { \ @@ -75,7 +60,7 @@ ossl_pkcs7_free(void *ptr) PKCS7_free(ptr); } -static const rb_data_type_t ossl_pkcs7_type = { +const rb_data_type_t ossl_pkcs7_type = { "OpenSSL/PKCS7", { 0, ossl_pkcs7_free, diff --git a/ext/openssl/ossl_pkcs7.h b/ext/openssl/ossl_pkcs7.h index 139e00d6..0d0fea7e 100644 --- a/ext/openssl/ossl_pkcs7.h +++ b/ext/openssl/ossl_pkcs7.h @@ -10,6 +10,22 @@ #if !defined(_OSSL_PKCS7_H_) #define _OSSL_PKCS7_H_ +#define NewPKCS7(klass) \ + TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0) +#define SetPKCS7(obj, pkcs7) do { \ + if (!(pkcs7)) { \ + ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ + } \ + RTYPEDDATA_DATA(obj) = (pkcs7); \ +} while (0) +#define GetPKCS7(obj, pkcs7) do { \ + TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \ + if (!(pkcs7)) { \ + ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ + } \ +} while (0) + +extern const rb_data_type_t ossl_pkcs7_type; extern VALUE cPKCS7; extern VALUE cPKCS7Signer; extern VALUE cPKCS7Recipient; diff --git a/ext/openssl/ossl_ts.c b/ext/openssl/ossl_ts.c index fbb4ee1d..9b9a6db6 100755 --- a/ext/openssl/ossl_ts.c +++ b/ext/openssl/ossl_ts.c @@ -187,7 +187,7 @@ ossl_tsreq_initialize(int argc, VALUE *argv, VALUE self) } arg = ossl_to_der_if_possible(arg); - in = ossl_obj2bio(arg); + in = ossl_obj2bio(&arg); if (!d2i_TS_REQ_bio(in, &ts_req)) { ossl_raise(eTimestampError, "Error when decoding the timestamp request"); @@ -530,7 +530,7 @@ ossl_ts_initialize(VALUE self, VALUE der) BIO *in; der = ossl_to_der_if_possible(der); - in = ossl_obj2bio(der); + in = ossl_obj2bio(&der); if (!d2i_TS_RESP_bio(in, &ts_resp)) { ossl_raise(eTimestampError, "Error when decoding the timestamp response"); @@ -655,13 +655,18 @@ ossl_ts_get_pkcs7(VALUE self) { TS_RESP *resp; PKCS7 *p7; + VALUE obj; GetTS_RESP(self, resp); p7 = resp->token; if (!p7) return Qnil; - return Data_Wrap_Struct(cPKCS7, 0, PKCS7_free, PKCS7_dup(p7)); + obj = NewPKCS7(cPKCS7); + SetPKCS7(obj, PKCS7_dup(p7)); + + return obj; + // return Data_Wrap_Struct(cPKCS7, 0, PKCS7_free, PKCS7_dup(p7)); } /* @@ -957,7 +962,7 @@ static void int_ossl_init_roots(VALUE roots, X509_STORE * store) X509_STORE_add_cert(store, GetX509CertPtr(roots)); } else { - in = ossl_obj2bio(roots); + in = ossl_obj2bio(&roots); inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); BIO_free(in); if(!inf) { @@ -1116,9 +1121,10 @@ ossl_tsfac_serial_cb(struct TS_resp_ctx *ctx, void *data) static int ossl_tsfac_time_cb(struct TS_resp_ctx *ctx, void *data, long *sec, long *usec) { - VALUE time = *((VALUE *)data); - time_t secs = time_to_time_t(time); - *sec = (long) secs; + VALUE time_v = *((VALUE *)data); + if (rb_obj_is_instance_of(time_v, rb_cTime)) + time_v = rb_funcall(time_v, rb_intern("to_i"), 0); + *sec = NUM2LONG(time_v);; *usec = 0; return 1; } @@ -1236,7 +1242,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request) TS_RESP_CTX_add_md(ctx, EVP_get_digestbyname(OBJ_nid2sn(NID_sha512))); str = rb_funcall(request, rb_intern("to_der"), 0); - req_bio = ossl_obj2bio(str); + req_bio = ossl_obj2bio(&str); response = TS_RESP_create_response(ctx, req_bio); if (!response) { err_msg = "Error during response generation"; |