12 #define NewX509Req(klass) \ 13 TypedData_Wrap_Struct((klass), &ossl_x509req_type, 0) 14 #define SetX509Req(obj, req) do { \ 16 ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \ 18 RTYPEDDATA_DATA(obj) = (req); \ 20 #define GetX509Req(obj, req) do { \ 21 TypedData_Get_Struct((obj), X509_REQ, &ossl_x509req_type, (req)); \ 23 ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \ 34 ossl_x509req_free(
void *ptr)
64 ossl_x509req_alloc(
VALUE klass)
70 if (!(req = X509_REQ_new())) {
90 req = PEM_read_bio_X509_REQ(in, &x,
NULL,
NULL);
94 req = d2i_X509_REQ_bio(in, &x);
106 X509_REQ *a, *b, *req;
109 if (
self == other)
return self;
112 if (!(req = X509_REQ_dup(b))) {
122 ossl_x509req_to_pem(
VALUE self)
128 if (!(out = BIO_new(BIO_s_mem()))) {
131 if (!PEM_write_bio_X509_REQ(out, req)) {
140 ossl_x509req_to_der(
VALUE self)
148 if ((len = i2d_X509_REQ(req,
NULL)) <= 0)
152 if (i2d_X509_REQ(req, &p) <= 0)
160 ossl_x509req_to_text(
VALUE self)
166 if (!(out = BIO_new(BIO_s_mem()))) {
169 if (!X509_REQ_print(out, req)) {
189 if (!(x509 = X509_REQ_to_X509(req, d, pkey))) {
198 ossl_x509req_get_version(
VALUE self)
204 version = X509_REQ_get_version(req);
210 ossl_x509req_set_version(
VALUE self,
VALUE version)
215 if ((ver =
NUM2LONG(version)) < 0) {
219 if (!X509_REQ_set_version(req, ver)) {
227 ossl_x509req_get_subject(
VALUE self)
233 if (!(name = X509_REQ_get_subject_name(req))) {
241 ossl_x509req_set_subject(
VALUE self,
VALUE subject)
255 ossl_x509req_get_signature_algorithm(
VALUE self)
258 const X509_ALGOR *alg;
263 if (!(out = BIO_new(BIO_s_mem()))) {
267 if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
276 ossl_x509req_get_public_key(
VALUE self)
282 if (!(pkey = X509_REQ_get_pubkey(req))) {
297 if (!X509_REQ_set_pubkey(req, pkey)) {
314 if (!X509_REQ_sign(req, pkey, md)) {
332 switch (X509_REQ_verify(req, pkey)) {
344 ossl_x509req_get_attributes(
VALUE self)
348 X509_ATTRIBUTE *attr;
353 count = X509_REQ_get_attr_count(req);
359 for (i=0; i<
count; i++) {
360 attr = X509_REQ_get_attr(req, i);
368 ossl_x509req_set_attributes(
VALUE self,
VALUE ary)
371 X509_ATTRIBUTE *attr;
380 while ((attr = X509_REQ_delete_attr(req, 0)))
381 X509_ATTRIBUTE_free(attr);
385 if (!X509_REQ_add1_attr(req, attr)) {
393 ossl_x509req_add_attribute(
VALUE self,
VALUE attr)
#define RUBY_TYPED_FREE_IMMEDIATELY
void Init_ossl_x509req(void)
EVP_PKEY * GetPrivPKeyPtr(VALUE obj)
#define ossl_str_adjust(str, p)
VALUE rb_ary_push(VALUE ary, VALUE item)
BIO * ossl_obj2bio(volatile VALUE *pobj)
X509_ATTRIBUTE * GetX509AttrPtr(VALUE)
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)
VALUE ossl_membio2str(BIO *bio)
VALUE ossl_pkey_new(EVP_PKEY *pkey)
X509_NAME * GetX509NamePtr(VALUE)
VALUE ossl_to_der_if_possible(VALUE obj)
#define X509_REQ_get0_signature
void ossl_clear_error(void)
RUBY_EXTERN VALUE rb_cObject
#define OSSL_BIO_reset(bio)
VALUE ossl_x509_new(X509 *)
#define NewX509Req(klass)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
const EVP_MD * ossl_evp_get_digestbyname(VALUE obj)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
VALUE ossl_x509attr_new(X509_ATTRIBUTE *)
#define RARRAY_AREF(a, i)
#define OSSL_Check_Kind(obj, klass)
#define GetX509Req(obj, req)
X509_REQ * GetX509ReqPtr(VALUE obj)
void ossl_raise(VALUE exc, const char *fmt,...)
EVP_PKEY * GetPKeyPtr(VALUE obj)
VALUE ossl_x509name_new(X509_NAME *)
#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)
#define SetX509Req(obj, req)
VALUE rb_str_new(const char *, long)