class OpenSSL::X509::Extension - Documentation for Ruby 4.0
Description: Documentation for the OpenSSL::X509::Extension class
Keywords: ruby,class,OpenSSL::X509::Extension

🔍

No recent searches

# class OpenSSL::X509::Extension

### Public Class Methods

OpenSSL::X509::Extension.new(der)
OpenSSL::X509::Extension.new(oid, value)
OpenSSL::X509::Extension.new(oid, value, critical)
Source

    static VALUE
    ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
    {
        VALUE oid, value, critical;
        const unsigned char *p;
        X509_EXTENSION *ext, *x;

        GetX509Ext(self, ext);
        if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){
            oid = ossl_to_der_if_possible(oid);
            StringValue(oid);
            p = (unsigned char *)RSTRING_PTR(oid);
            x = d2i_X509_EXTENSION(&ext, &p, RSTRING_LEN(oid));
            DATA_PTR(self) = ext;
            if(!x)
                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;
    }

Creates an `X509` extension.

The extension may be created from der data or from an extension oid and value. The oid may be either an OID or an extension name. If critical is `true` the extension is marked critical.

### Public Instance Methods

== (other)
Source

    # File ext/openssl/lib/openssl/x509.rb, line 48
    def ==(other)
      return false unless Extension === other
      to_der == other.to_der
    end

critical= (p1)
Source

    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? ()
Source

    static VALUE
    ossl_x509ext_get_critical(VALUE obj)
    {
        X509_EXTENSION *ext;

        GetX509Ext(obj, ext);
        return X509_EXTENSION_get_critical(ext) ? Qtrue : Qfalse;
    }

oid → string
Source

    static VALUE
    ossl_x509ext_get_oid(VALUE obj)
    {
        X509_EXTENSION *ext;

        GetX509Ext(obj, ext);
        return ossl_asn1obj_to_string(X509_EXTENSION_get_object(ext));
    }

Returns the OID of the extension. Returns the short name or the dotted decimal notation.

oid= (p1)
Source

    static VALUE
    ossl_x509ext_set_oid(VALUE self, VALUE oid)
    {
        X509_EXTENSION *ext;
        ASN1_OBJECT *obj;

        GetX509Ext(self, ext);
        obj = OBJ_txt2obj(StringValueCStr(oid), 0);
        if (!obj)
            ossl_raise(eX509ExtError, "OBJ_txt2obj");
        if (!X509_EXTENSION_set_object(ext, obj)) {
            ASN1_OBJECT_free(obj);
            ossl_raise(eX509ExtError, "X509_EXTENSION_set_object");
        }
        ASN1_OBJECT_free(obj);

        return oid;
    }

to_a ()
Source

    # File ext/openssl/lib/openssl/x509.rb, line 64
    def to_a
      [ self.oid, self.value, self.critical? ]
    end

to_der ()
Source

    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 = (unsigned char *)RSTRING_PTR(str);
        if(i2d_X509_EXTENSION(ext, &p) < 0)
            ossl_raise(eX509ExtError, NULL);
        ossl_str_adjust(str, p);

        return str;
    }

to_h ()
Source

    # File ext/openssl/lib/openssl/x509.rb, line 60
    def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
      {"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
    end

to_s ()
Source

    # File ext/openssl/lib/openssl/x509.rb, line 53
    def to_s # "oid = critical, value"
      str = self.oid
      str << " = "
      str << "critical, " if self.critical?
      str << self.value.gsub(/\n/, ", ")
    end

value ()
Source

    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))
            ASN1_STRING_print(out, (ASN1_STRING *)X509_EXTENSION_get_data(ext));
        ret = ossl_membio2str(out);

        return ret;
    }

value= (p1)
Source

    static VALUE
    ossl_x509ext_set_value(VALUE self, VALUE data)
    {
        X509_EXTENSION *ext;
        ASN1_OCTET_STRING *asn1s;

        GetX509Ext(self, ext);
        data = ossl_to_der_if_possible(data);
        StringValue(data);
        asn1s = X509_EXTENSION_get_data(ext);

        if (!ASN1_OCTET_STRING_set(asn1s, (unsigned char *)RSTRING_PTR(data),
                                   RSTRING_LENINT(data))) {
            ossl_raise(eX509ExtError, "ASN1_OCTET_STRING_set");
        }

        return data;
    }

value_der ()
Source

    static VALUE
    ossl_x509ext_get_value_der(VALUE obj)
    {
        X509_EXTENSION *ext;
        ASN1_OCTET_STRING *value;

        GetX509Ext(obj, ext);
        if ((value = X509_EXTENSION_get_data(ext)) == NULL)
            ossl_raise(eX509ExtError, NULL);

        return asn1str_to_str(value);
    }