fix_asn1.diff

Martin Bosslet, 02/07/2011 02:52 AM

Download (3.62 KB)

View differences:

ruby/ext/openssl/ossl_asn1.c (Arbeitskopie)
734 734
    ary = rb_ary_new();
735 735
    p = *pp;
736 736
    while(length > 0){
737 737
	p0 = p;
738
       infinite = 0;
738 739
	j = ASN1_get_object(&p0, &len, &tag, &tc, length);
739 740
	p = (unsigned char *)p0;
740 741
	if(j & 0x80) ossl_raise(eASN1Error, NULL);
......
826 827
                    asn1data = rb_funcall(cASN1EndOfContent,
827 828
                                          rb_intern("new"),
828 829
                                          0);
830
                    once = 1;
829 831
                }
830 832
                else{
831 833
                    asn1data = rb_funcall(klass, rb_intern("new"), 1, value);
......
912 914
    if(argc > 1){
913 915
	if(NIL_P(tag))
914 916
	    ossl_raise(eASN1Error, "must specify tag number");
915
        if(NIL_P(tagging))
916
	    tagging = ID2SYM(sEXPLICIT);
917
	if(!SYMBOL_P(tagging))
918
	    ossl_raise(eASN1Error, "invalid tag default");
919
	if(NIL_P(tag_class))
920
	    tag_class = ID2SYM(sCONTEXT_SPECIFIC);
917
        if(!NIL_P(tagging) && !SYMBOL_P(tagging))
918
	    ossl_raise(eASN1Error, "invalid tagging method");
919
	if(NIL_P(tag_class)) {
920
            if (NIL_P(tagging))
921
                tag_class = ID2SYM(sUNIVERSAL);
922
            else
923
                tag_class = ID2SYM(sCONTEXT_SPECIFIC);
924
        }
921 925
	if(!SYMBOL_P(tag_class))
922 926
	    ossl_raise(eASN1Error, "invalid tag class");
923 927
	if(SYM2ID(tagging) == sIMPLICIT && NUM2INT(tag) > 31)
ruby/test/openssl/test_asn1.rb (Arbeitskopie)
438 438
      OpenSSL::ASN1.decode_all(raw)
439 439
    end
440 440
  end
441

  
442
  def test_recursive_octet_string_parse
443
    test = %w{ 24 80 24 80 04 01 01 00 00 24 80 04 01 02 00 00 04 01 03 00 00 }
444
    raw = [test.join('')].pack('H*')
445
    asn1 = OpenSSL::ASN1.decode(raw)
446
    assert_equal(OpenSSL::ASN1::Constructive, asn1.class)
447
    assert_universal(OpenSSL::ASN1::OCTET_STRING, asn1)
448
    assert_equal(true, asn1.infinite_length)
449
    assert_equal(4, asn1.value.size)
450
    nested1 = asn1.value[0]
451
    assert_equal(OpenSSL::ASN1::Constructive, nested1.class)
452
    assert_universal(OpenSSL::ASN1::OCTET_STRING, nested1)
453
    assert_equal(true, nested1.infinite_length)
454
    assert_equal(2, nested1.value.size)
455
    oct1 = nested1.value[0]
456
    assert_universal(OpenSSL::ASN1::OCTET_STRING, oct1)
457
    assert_equal(false, oct1.infinite_length)
458
    assert_universal(OpenSSL::ASN1::EOC, nested1.value[1])
459
    assert_equal(false, nested1.value[1].infinite_length)
460
    nested2 = asn1.value[1]
461
    assert_equal(OpenSSL::ASN1::Constructive, nested2.class)
462
    assert_universal(OpenSSL::ASN1::OCTET_STRING, nested2)
463
    assert_equal(true, nested2.infinite_length)
464
    assert_equal(2, nested2.value.size)
465
    oct2 = nested2.value[0]
466
    assert_universal(OpenSSL::ASN1::OCTET_STRING, oct2)
467
    assert_equal(false, oct2.infinite_length)
468
    assert_universal(OpenSSL::ASN1::EOC, nested2.value[1])
469
    assert_equal(false, nested2.value[1].infinite_length)
470
    oct3 = asn1.value[2]
471
    assert_universal(OpenSSL::ASN1::OCTET_STRING, oct3)
472
    assert_equal(false, oct3.infinite_length)
473
    assert_universal(OpenSSL::ASN1::EOC, asn1.value[3])
474
    assert_equal(false, asn1.value[3].infinite_length)
475
  end
476

  
477
  private
441 478
  
479
  def assert_universal(tag, asn1)
480
    assert_equal(tag, asn1.tag)
481
    if asn1.respond_to?(:tagging)
482
      assert_nil(asn1.tagging)
483
    end
484
    assert_equal(:UNIVERSAL, asn1.tag_class)
485
  end
486
  
442 487
end if defined?(OpenSSL)
443 488