[ruby/openssl] ts: avoid using OpenSSL::PKCS7's internals
Internals of OpenSSL::PKCS7 should be kept within ossl_pkcs7.c. Add a new ossl_pkcs7_new() function for duplicating and wrapping an OpenSSL PKCS7 object in OpenSSL::PKCS7. This follows the convention used by other ossl_*_new() functions. https://github.com/ruby/openssl/commit/b5f79f771e
This commit is contained in:
parent
870cce9798
commit
f8e9302e66
@ -9,6 +9,21 @@
|
||||
*/
|
||||
#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 { \
|
||||
@ -49,10 +64,10 @@
|
||||
/*
|
||||
* Classes
|
||||
*/
|
||||
VALUE cPKCS7;
|
||||
VALUE cPKCS7Signer;
|
||||
VALUE cPKCS7Recipient;
|
||||
VALUE ePKCS7Error;
|
||||
static VALUE cPKCS7;
|
||||
static VALUE cPKCS7Signer;
|
||||
static VALUE cPKCS7Recipient;
|
||||
static VALUE ePKCS7Error;
|
||||
|
||||
static void
|
||||
ossl_pkcs7_free(void *ptr)
|
||||
@ -60,7 +75,7 @@ ossl_pkcs7_free(void *ptr)
|
||||
PKCS7_free(ptr);
|
||||
}
|
||||
|
||||
const rb_data_type_t ossl_pkcs7_type = {
|
||||
static const rb_data_type_t ossl_pkcs7_type = {
|
||||
"OpenSSL/PKCS7",
|
||||
{
|
||||
0, ossl_pkcs7_free,
|
||||
@ -68,6 +83,20 @@ const rb_data_type_t ossl_pkcs7_type = {
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
||||
};
|
||||
|
||||
VALUE
|
||||
ossl_pkcs7_new(PKCS7 *p7)
|
||||
{
|
||||
PKCS7 *new;
|
||||
VALUE obj = NewPKCS7(cPKCS7);
|
||||
|
||||
new = PKCS7_dup(p7);
|
||||
if (!new)
|
||||
ossl_raise(ePKCS7Error, "PKCS7_dup");
|
||||
SetPKCS7(obj, new);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void
|
||||
ossl_pkcs7_signer_info_free(void *ptr)
|
||||
{
|
||||
|
@ -10,27 +10,7 @@
|
||||
#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;
|
||||
extern VALUE ePKCS7Error;
|
||||
|
||||
VALUE ossl_pkcs7_new(PKCS7 *p7);
|
||||
void Init_ossl_pkcs7(void);
|
||||
|
||||
#endif /* _OSSL_PKCS7_H_ */
|
||||
|
@ -691,21 +691,12 @@ static VALUE
|
||||
ossl_ts_resp_get_token(VALUE self)
|
||||
{
|
||||
TS_RESP *resp;
|
||||
PKCS7 *p7, *copy;
|
||||
VALUE obj;
|
||||
PKCS7 *p7;
|
||||
|
||||
GetTSResponse(self, resp);
|
||||
if (!(p7 = TS_RESP_get_token(resp)))
|
||||
return Qnil;
|
||||
|
||||
obj = NewPKCS7(cPKCS7);
|
||||
|
||||
if (!(copy = PKCS7_dup(p7)))
|
||||
ossl_raise(eTimestampError, NULL);
|
||||
|
||||
SetPKCS7(obj, copy);
|
||||
|
||||
return obj;
|
||||
return ossl_pkcs7_new(p7);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user