Project

General

Profile

Bug #4374 ยป fix_asn1.diff

MartinBosslet (Martin Bosslet), 02/07/2011 02:52 AM

View differences:

ruby/ext/openssl/ossl_asn1.c (Arbeitskopie)
ary = rb_ary_new();
p = *pp;
while(length > 0){
p0 = p;
infinite = 0;
j = ASN1_get_object(&p0, &len, &tag, &tc, length);
p = (unsigned char *)p0;
if(j & 0x80) ossl_raise(eASN1Error, NULL);
......
asn1data = rb_funcall(cASN1EndOfContent,
rb_intern("new"),
0);
once = 1;
}
else{
asn1data = rb_funcall(klass, rb_intern("new"), 1, value);
......
if(argc > 1){
if(NIL_P(tag))
ossl_raise(eASN1Error, "must specify tag number");
if(NIL_P(tagging))
tagging = ID2SYM(sEXPLICIT);
if(!SYMBOL_P(tagging))
ossl_raise(eASN1Error, "invalid tag default");
if(NIL_P(tag_class))
tag_class = ID2SYM(sCONTEXT_SPECIFIC);
if(!NIL_P(tagging) && !SYMBOL_P(tagging))
ossl_raise(eASN1Error, "invalid tagging method");
if(NIL_P(tag_class)) {
if (NIL_P(tagging))
tag_class = ID2SYM(sUNIVERSAL);
else
tag_class = ID2SYM(sCONTEXT_SPECIFIC);
}
if(!SYMBOL_P(tag_class))
ossl_raise(eASN1Error, "invalid tag class");
if(SYM2ID(tagging) == sIMPLICIT && NUM2INT(tag) > 31)
ruby/test/openssl/test_asn1.rb (Arbeitskopie)
OpenSSL::ASN1.decode_all(raw)
end
end
def test_recursive_octet_string_parse
test = %w{ 24 80 24 80 04 01 01 00 00 24 80 04 01 02 00 00 04 01 03 00 00 }
raw = [test.join('')].pack('H*')
asn1 = OpenSSL::ASN1.decode(raw)
assert_equal(OpenSSL::ASN1::Constructive, asn1.class)
assert_universal(OpenSSL::ASN1::OCTET_STRING, asn1)
assert_equal(true, asn1.infinite_length)
assert_equal(4, asn1.value.size)
nested1 = asn1.value[0]
assert_equal(OpenSSL::ASN1::Constructive, nested1.class)
assert_universal(OpenSSL::ASN1::OCTET_STRING, nested1)
assert_equal(true, nested1.infinite_length)
assert_equal(2, nested1.value.size)
oct1 = nested1.value[0]
assert_universal(OpenSSL::ASN1::OCTET_STRING, oct1)
assert_equal(false, oct1.infinite_length)
assert_universal(OpenSSL::ASN1::EOC, nested1.value[1])
assert_equal(false, nested1.value[1].infinite_length)
nested2 = asn1.value[1]
assert_equal(OpenSSL::ASN1::Constructive, nested2.class)
assert_universal(OpenSSL::ASN1::OCTET_STRING, nested2)
assert_equal(true, nested2.infinite_length)
assert_equal(2, nested2.value.size)
oct2 = nested2.value[0]
assert_universal(OpenSSL::ASN1::OCTET_STRING, oct2)
assert_equal(false, oct2.infinite_length)
assert_universal(OpenSSL::ASN1::EOC, nested2.value[1])
assert_equal(false, nested2.value[1].infinite_length)
oct3 = asn1.value[2]
assert_universal(OpenSSL::ASN1::OCTET_STRING, oct3)
assert_equal(false, oct3.infinite_length)
assert_universal(OpenSSL::ASN1::EOC, asn1.value[3])
assert_equal(false, asn1.value[3].infinite_length)
end
private
def assert_universal(tag, asn1)
assert_equal(tag, asn1.tag)
if asn1.respond_to?(:tagging)
assert_nil(asn1.tagging)
end
assert_equal(:UNIVERSAL, asn1.tag_class)
end
end if defined?(OpenSSL)
    (1-1/1)