|
9 | 9 | */
|
10 | 10 | #include "ossl.h"
|
11 | 11 |
|
| 12 | +#define NewPKCS7(klass) \ |
| 13 | + TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0) |
| 14 | +#define SetPKCS7(obj, pkcs7) do { \ |
| 15 | + if (!(pkcs7)) { \ |
| 16 | + ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ |
| 17 | + } \ |
| 18 | + RTYPEDDATA_DATA(obj) = (pkcs7); \ |
| 19 | +} while (0) |
| 20 | +#define GetPKCS7(obj, pkcs7) do { \ |
| 21 | + TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \ |
| 22 | + if (!(pkcs7)) { \ |
| 23 | + ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \ |
| 24 | + } \ |
| 25 | +} while (0) |
| 26 | + |
12 | 27 | #define NewPKCS7si(klass) \
|
13 | 28 | TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
|
14 | 29 | #define SetPKCS7si(obj, p7si) do { \
|
|
49 | 64 | /*
|
50 | 65 | * Classes
|
51 | 66 | */
|
52 |
| -VALUE cPKCS7; |
53 |
| -VALUE cPKCS7Signer; |
54 |
| -VALUE cPKCS7Recipient; |
55 |
| -VALUE ePKCS7Error; |
| 67 | +static VALUE cPKCS7; |
| 68 | +static VALUE cPKCS7Signer; |
| 69 | +static VALUE cPKCS7Recipient; |
| 70 | +static VALUE ePKCS7Error; |
56 | 71 |
|
57 | 72 | static void
|
58 | 73 | ossl_pkcs7_free(void *ptr)
|
59 | 74 | {
|
60 | 75 | PKCS7_free(ptr);
|
61 | 76 | }
|
62 | 77 |
|
63 |
| -const rb_data_type_t ossl_pkcs7_type = { |
| 78 | +static const rb_data_type_t ossl_pkcs7_type = { |
64 | 79 | "OpenSSL/PKCS7",
|
65 | 80 | {
|
66 | 81 | 0, ossl_pkcs7_free,
|
67 | 82 | },
|
68 | 83 | 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
69 | 84 | };
|
70 | 85 |
|
| 86 | +VALUE |
| 87 | +ossl_pkcs7_new(PKCS7 *p7) |
| 88 | +{ |
| 89 | + PKCS7 *new; |
| 90 | + VALUE obj = NewPKCS7(cPKCS7); |
| 91 | + |
| 92 | + new = PKCS7_dup(p7); |
| 93 | + if (!new) |
| 94 | + ossl_raise(ePKCS7Error, "PKCS7_dup"); |
| 95 | + SetPKCS7(obj, new); |
| 96 | + |
| 97 | + return obj; |
| 98 | +} |
| 99 | + |
71 | 100 | static void
|
72 | 101 | ossl_pkcs7_signer_info_free(void *ptr)
|
73 | 102 | {
|
|
0 commit comments