7 #define NewPKCS12(klass) \ 8 TypedData_Wrap_Struct((klass), &ossl_pkcs12_type, 0) 10 #define SetPKCS12(obj, p12) do { \ 11 if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ 12 RTYPEDDATA_DATA(obj) = (p12); \ 15 #define GetPKCS12(obj, p12) do { \ 16 TypedData_Get_Struct((obj), PKCS12, &ossl_pkcs12_type, (p12)); \ 17 if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \ 20 #define SafeGetPKCS12(obj, p12) do { \ 21 OSSL_Check_Kind((obj), cPKCS12); \ 22 GetPKCS12((obj), (p12)); \ 25 #define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v)) 26 #define ossl_pkcs12_set_cert(o,v) rb_iv_set((o), "@certificate", (v)) 27 #define ossl_pkcs12_set_ca_certs(o,v) rb_iv_set((o), "@ca_certs", (v)) 28 #define ossl_pkcs12_get_key(o) rb_iv_get((o), "@key") 29 #define ossl_pkcs12_get_cert(o) rb_iv_get((o), "@certificate") 30 #define ossl_pkcs12_get_ca_certs(o) rb_iv_get((o), "@ca_certs") 71 PKCS12 *p12, *p12_old, *p12_new;
77 p12_new = ASN1_dup((i2d_of_void *)i2d_PKCS12, (d2i_of_void *)d2i_PKCS12, (
char *)p12);
112 VALUE pass,
name, pkey, cert, ca, key_nid, cert_nid, key_iter, mac_iter, keytype;
114 char *passphrase, *friendlyname;
118 int nkey = 0, ncert = 0, kiter = 0, miter = 0, ktype = 0;
121 rb_scan_args(argc, argv,
"46", &pass, &name, &pkey, &cert, &ca, &key_nid, &cert_nid, &key_iter, &mac_iter, &keytype);
127 if (!
NIL_P(key_nid)) {
131 if (!
NIL_P(cert_nid)) {
135 if (!
NIL_P(key_iter))
137 if (!
NIL_P(mac_iter))
143 x509s =
NIL_P(ca) ?
NULL : ossl_x509_ary2sk(ca);
144 p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
145 nkey, ncert, kiter, miter, ktype);
146 sk_X509_pop_free(x509s, X509_free);
171 VALUE arg, pass, pkey, cert, ca;
179 if(
rb_scan_args(argc, argv,
"02", &arg, &pass) == 0)
return self;
182 d2i_PKCS12_bio(in, &pkcs);
186 pkey = cert = ca =
Qnil;
190 if(!PKCS12_parse(pkcs, passphrase, &key, &x509, &x509s))
208 sk_X509_pop_free(x509s, X509_free);
226 if((len = i2d_PKCS12(p12,
NULL)) <= 0)
230 if(i2d_PKCS12(p12, &p) <= 0)
static const rb_data_type_t ossl_pkcs12_type
int *VALUE ossl_x509_sk2ary(const STACK_OF(X509) *certs)
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE ossl_pkcs12_initialize_copy(VALUE self, VALUE other)
#define ossl_str_adjust(str, p)
static VALUE ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
BIO * ossl_obj2bio(volatile VALUE *pobj)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#define SafeGetPKCS12(obj, p12)
STACK_OF(X509) *ossl_x509_ary2sk0(VALUE)
VALUE ossl_pkey_new(EVP_PKEY *pkey)
#define rb_define_copy_func(klass, func)
X509 * GetX509CertPtr(VALUE)
RUBY_EXTERN VALUE rb_cObject
void rb_attr(VALUE, ID, int, int, int)
#define GetPKCS12(obj, p12)
VALUE ossl_x509_new(X509 *)
#define ossl_pkcs12_set_cert(o, v)
static VALUE ossl_pkcs12_s_allocate(VALUE klass)
void Init_ossl_pkcs12(void)
#define ossl_pkcs12_set_key(o, v)
#define ossl_pkcs12_set_ca_certs(o, v)
static void ossl_pkcs12_free(void *ptr)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define SetPKCS12(obj, p12)
void rb_jump_tag(int tag)
register unsigned int len
#define StringValueCStr(v)
static VALUE ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
static VALUE ossl_pkcs12_to_der(VALUE self)
void ossl_raise(VALUE exc, const char *fmt,...)
EVP_PKEY * GetPKeyPtr(VALUE obj)
#define rb_check_frozen(obj)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)