Class: OpenSSL::ASN1::ASN1Data

Inherits:
Object
  • Object
show all
Defined in:
ossl_asn1.c

Direct Known Subclasses

Constructive, Primitive

Instance Method Summary collapse

Constructor Details

#initialize(value, tag, tag_class) ⇒ Object



654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'ossl_asn1.c', line 654

static VALUE
ossl_asn1data_initialize(VALUE self, VALUE value, VALUE tag, VALUE tag_class)
{
    if(!SYMBOL_P(tag_class))
	ossl_raise(eASN1Error, "invalid tag class");
    if((SYM2ID(tag_class) == sUNIVERSAL) && NUM2INT(tag) > 31)
	ossl_raise(eASN1Error, "tag number for Universal too large");
    ossl_asn1_set_tag(self, tag);
    ossl_asn1_set_value(self, value);
    ossl_asn1_set_tag_class(self, tag_class);

    return self;
}

Instance Method Details

#to_derObject



685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'ossl_asn1.c', line 685

static VALUE
ossl_asn1data_to_der(VALUE self)
{
    VALUE value, der;
    int tag, tag_class, is_cons = 0;
    long length;
    unsigned char *p;

    value = ossl_asn1_get_value(self);
    if(rb_obj_is_kind_of(value, rb_cArray)){
	is_cons = 1;
	value = join_der(value);
    }
    StringValue(value);

    tag = ossl_asn1_tag(self);
    tag_class = ossl_asn1_tag_class(self);
    if((length = ASN1_object_size(1, RSTRING(value)->len, tag)) <= 0)
	ossl_raise(eASN1Error, NULL);
    der = rb_str_new(0, length);
    p = RSTRING(der)->ptr;
    ASN1_put_object(&p, is_cons, RSTRING(value)->len, tag, tag_class);
    memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len);
    p += RSTRING(value)->len;
    ossl_str_adjust(der, p);

    return der;
}