Class: OpenSSL::X509::Extension
- Inherits:
-
Object
- Object
- OpenSSL::X509::Extension
- Defined in:
- lib/openssl/x509.rb,
ossl_x509ext.c
Instance Method Summary collapse
- #critical=(flag) ⇒ Object
- #critical? ⇒ Boolean
- #initialize(*args) ⇒ Object constructor
- #oid ⇒ Object
- #oid=(oid) ⇒ Object
- #to_a ⇒ Object
- #to_der ⇒ Object
-
#to_h ⇒ Object
“value”=>value, “critical”=>true|false.
-
#to_s ⇒ Object
“oid = critical, value”.
- #value ⇒ Object
- #value=(data) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'ossl_x509ext.c', line 272 static VALUE ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self) { VALUE oid, value, critical; unsigned char *p; X509_EXTENSION *ext; GetX509Ext(self, ext); if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){ oid = ossl_to_der_if_possible(oid); StringValue(oid); p = RSTRING(oid)->ptr; if(!d2i_X509_EXTENSION((X509_EXTENSION**)&DATA_PTR(self), &p, RSTRING(oid)->len)) ossl_raise(eX509ExtError, NULL); return self; } rb_funcall(self, rb_intern("oid="), 1, oid); rb_funcall(self, rb_intern("value="), 1, value); if(argc > 2) rb_funcall(self, rb_intern("critical="), 1, critical); return self; } |
Instance Method Details
#critical=(flag) ⇒ Object
340 341 342 343 344 345 346 347 348 349 |
# File 'ossl_x509ext.c', line 340 static VALUE ossl_x509ext_set_critical(VALUE self, VALUE flag) { X509_EXTENSION *ext; GetX509Ext(self, ext); X509_EXTENSION_set_critical(ext, RTEST(flag) ? 1 : 0); return flag; } |
#critical? ⇒ Boolean
391 392 393 394 395 396 397 398 |
# File 'ossl_x509ext.c', line 391 static VALUE ossl_x509ext_get_critical(VALUE obj) { X509_EXTENSION *ext; GetX509Ext(obj, ext); return X509_EXTENSION_get_critical(ext) ? Qtrue : Qfalse; } |
#oid ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'ossl_x509ext.c', line 351 static VALUE ossl_x509ext_get_oid(VALUE obj) { X509_EXTENSION *ext; ASN1_OBJECT *extobj; BIO *out; VALUE ret; int nid; GetX509Ext(obj, ext); extobj = X509_EXTENSION_get_object(ext); if ((nid = OBJ_obj2nid(extobj)) != NID_undef) ret = rb_str_new2(OBJ_nid2sn(nid)); else{ if (!(out = BIO_new(BIO_s_mem()))) ossl_raise(eX509ExtError, NULL); i2a_ASN1_OBJECT(out, extobj); ret = ossl_membio2str(out); } return ret; } |
#oid=(oid) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'ossl_x509ext.c', line 296 static VALUE ossl_x509ext_set_oid(VALUE self, VALUE oid) { X509_EXTENSION *ext; ASN1_OBJECT *obj; char *s; s = StringValuePtr(oid); obj = OBJ_txt2obj(s, 0); if(!obj) obj = OBJ_txt2obj(s, 1); if(!obj) ossl_raise(eX509ExtError, NULL); GetX509Ext(self, ext); X509_EXTENSION_set_object(ext, obj); return oid; } |
#to_a ⇒ Object
59 60 61 |
# File 'lib/openssl/x509.rb', line 59 def to_a [ self.oid, self.value, self.critical? ] end |
#to_der ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'ossl_x509ext.c', line 400 static VALUE ossl_x509ext_to_der(VALUE obj) { X509_EXTENSION *ext; unsigned char *p; long len; VALUE str; GetX509Ext(obj, ext); if((len = i2d_X509_EXTENSION(ext, NULL)) <= 0) ossl_raise(eX509ExtError, NULL); str = rb_str_new(0, len); p = RSTRING(str)->ptr; if(i2d_X509_EXTENSION(ext, &p) < 0) ossl_raise(eX509ExtError, NULL); ossl_str_adjust(str, p); return str; } |
#to_h ⇒ Object
“value”=>value, “critical”=>true|false
55 56 57 |
# File 'lib/openssl/x509.rb', line 55 def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false} {"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?} end |
#to_s ⇒ Object
“oid = critical, value”
48 49 50 51 52 53 |
# File 'lib/openssl/x509.rb', line 48 def to_s # "oid = critical, value" str = self.oid str << " = " str << "critical, " if self.critical? str << self.value.gsub(/\n/, ", ") end |
#value ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'ossl_x509ext.c', line 374 static VALUE ossl_x509ext_get_value(VALUE obj) { X509_EXTENSION *ext; BIO *out; VALUE ret; GetX509Ext(obj, ext); if (!(out = BIO_new(BIO_s_mem()))) ossl_raise(eX509ExtError, NULL); if (!X509V3_EXT_print(out, ext, 0, 0)) M_ASN1_OCTET_STRING_print(out, ext->value); ret = ossl_membio2str(out); return ret; } |
#value=(data) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'ossl_x509ext.c', line 313 static VALUE ossl_x509ext_set_value(VALUE self, VALUE data) { X509_EXTENSION *ext; ASN1_OCTET_STRING *asn1s; char *s; data = ossl_to_der_if_possible(data); StringValue(data); if(!(s = OPENSSL_malloc(RSTRING(data)->len))) ossl_raise(eX509ExtError, "malloc error"); memcpy(s, RSTRING(data)->ptr, RSTRING(data)->len); if(!(asn1s = ASN1_OCTET_STRING_new())){ free(s); ossl_raise(eX509ExtError, NULL); } if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING(data)->len)){ free(s); ASN1_OCTET_STRING_free(asn1s); ossl_raise(eX509ExtError, NULL); } GetX509Ext(self, ext); X509_EXTENSION_set_data(ext, asn1s); return data; } |