@@ -708,19 +708,22 @@ public static void createASN1(final Ruby runtime, final RubyModule OpenSSL, fina
708
708
_ASN1Data .addReadWriteAttribute (context , "value" );
709
709
_ASN1Data .addReadWriteAttribute (context , "tag" );
710
710
_ASN1Data .addReadWriteAttribute (context , "tag_class" );
711
+ _ASN1Data .addReadWriteAttribute (context , "indefinite_length" );
712
+ _ASN1Data .defineAlias ( "infinite_length" , "indefinite_length" );
713
+ _ASN1Data .defineAlias ( "infinite_length=" , "indefinite_length=" );
711
714
_ASN1Data .defineAnnotatedMethods (ASN1Data .class );
712
715
713
716
final ObjectAllocator primitiveAllocator = Primitive .ALLOCATOR ;
714
717
RubyClass Primitive = ASN1 .defineClassUnder ("Primitive" , _ASN1Data , primitiveAllocator );
715
718
Primitive .addReadWriteAttribute (context , "tagging" );
716
- Primitive .addReadAttribute (context , "infinite_length" );
719
+ Primitive .undefineMethod ("infinite_length=" );
720
+ Primitive .undefineMethod ("indefinite_length=" );
717
721
Primitive .defineAnnotatedMethods (Primitive .class );
718
722
719
723
final ObjectAllocator constructiveAllocator = Constructive .ALLOCATOR ;
720
724
RubyClass Constructive = ASN1 .defineClassUnder ("Constructive" , _ASN1Data , constructiveAllocator );
721
725
Constructive .includeModule ( runtime .getModule ("Enumerable" ) );
722
726
Constructive .addReadWriteAttribute (context , "tagging" );
723
- Constructive .addReadWriteAttribute (context , "infinite_length" );
724
727
Constructive .defineAnnotatedMethods (Constructive .class );
725
728
726
729
ASN1 .defineClassUnder ("Boolean" , Primitive , primitiveAllocator ); // OpenSSL::ASN1::Boolean <=> value is a Boolean
@@ -747,10 +750,11 @@ public static void createASN1(final Ruby runtime, final RubyModule OpenSSL, fina
747
750
ASN1 .defineClassUnder ("UTCTime" , Primitive , primitiveAllocator ); // OpenSSL::ASN1::UTCTime <=> value is a Time
748
751
ASN1 .defineClassUnder ("GeneralizedTime" , Primitive , primitiveAllocator ); // OpenSSL::ASN1::GeneralizedTime <=> value is a Time
749
752
750
- ASN1 .defineClassUnder ("EndOfContent" , Primitive , primitiveAllocator ); // OpenSSL::ASN1::EndOfContent <=> value is always nil
753
+ ASN1 .defineClassUnder ("EndOfContent" , _ASN1Data , asn1DataAllocator ). // OpenSSL::ASN1::EndOfContent <=> value is always nil
754
+ defineAnnotatedMethods (EndOfContent .class );
751
755
752
- RubyClass ObjectId = ASN1 .defineClassUnder ("ObjectId" , Primitive , primitiveAllocator );
753
- ObjectId . defineAnnotatedMethods (ObjectId .class );
756
+ ASN1 .defineClassUnder ("ObjectId" , Primitive , primitiveAllocator ).
757
+ defineAnnotatedMethods (ObjectId .class );
754
758
755
759
ASN1 .defineClassUnder ("Sequence" , Constructive , Constructive .getAllocator ());
756
760
ASN1 .defineClassUnder ("Set" , Constructive , Constructive .getAllocator ());
@@ -1361,7 +1365,9 @@ private void checkTag(final Ruby runtime, final IRubyObject tag,
1361
1365
}
1362
1366
}
1363
1367
1364
- boolean isEOC () { return false ; }
1368
+ boolean isEOC () {
1369
+ return "EndOfContent" .equals ( getClassBaseName () );
1370
+ }
1365
1371
1366
1372
boolean isExplicitTagging () { return ! isImplicitTagging (); }
1367
1373
@@ -1412,6 +1418,7 @@ public IRubyObject to_der(final ThreadContext context) {
1412
1418
}
1413
1419
1414
1420
byte [] toDER (final ThreadContext context ) throws IOException {
1421
+ if ( isEOC () ) return new byte [] { 0x00 , 0x00 };
1415
1422
return toASN1 (context ).toASN1Primitive ().getEncoded (ASN1Encoding .DER );
1416
1423
}
1417
1424
@@ -1464,6 +1471,26 @@ static void printArray(final PrintStream out, final int indent, final RubyArray
1464
1471
1465
1472
}
1466
1473
1474
+ public static class EndOfContent {
1475
+
1476
+ private EndOfContent () {}
1477
+
1478
+ @ JRubyMethod (visibility = Visibility .PRIVATE )
1479
+ public static IRubyObject initialize (final ThreadContext context , final IRubyObject self ) {
1480
+ final Ruby runtime = context .runtime ;
1481
+ self .getInstanceVariables ().setInstanceVariable ("@tag" , runtime .newFixnum (0 ));
1482
+ self .getInstanceVariables ().setInstanceVariable ("@value" , RubyString .newEmptyString (context .runtime ));
1483
+ self .getInstanceVariables ().setInstanceVariable ("@tag_class" , runtime .newSymbol ("UNIVERSAL" ));
1484
+ return self ;
1485
+ }
1486
+
1487
+ static IRubyObject newInstance (final ThreadContext context ) {
1488
+ RubyClass klass = _ASN1 (context .runtime ).getClass ("EndOfContent" );
1489
+ return klass .newInstance (context , Block .NULL_BLOCK );
1490
+ }
1491
+
1492
+ }
1493
+
1467
1494
public static class Primitive extends ASN1Data {
1468
1495
private static final long serialVersionUID = 8489625559339190259L ;
1469
1496
@@ -1556,7 +1583,7 @@ static void initializeImpl(final ThreadContext context,
1556
1583
self .setInstanceVariable ("@value" , value );
1557
1584
self .setInstanceVariable ("@tag_class" , tag_class );
1558
1585
self .setInstanceVariable ("@tagging" , tagging );
1559
- self .setInstanceVariable ("@infinite_length " , runtime .getFalse ());
1586
+ self .setInstanceVariable ("@indefinite_length " , runtime .getFalse ());
1560
1587
}
1561
1588
1562
1589
@ Override
@@ -1573,27 +1600,14 @@ boolean isImplicitTagging() {
1573
1600
1574
1601
@ Override
1575
1602
boolean isEOC () {
1576
- return "EndOfContent" . equals ( getClassBaseName () ) ;
1603
+ return false ;
1577
1604
}
1578
1605
1579
1606
@ Override
1580
1607
byte [] toDER (final ThreadContext context ) throws IOException {
1581
- if ( isEOC () ) return new byte [] { 0x00 , 0x00 };
1582
1608
return toASN1 (context ).toASN1Primitive ().getEncoded (ASN1Encoding .DER );
1583
1609
}
1584
1610
1585
- static Primitive newInstance (final ThreadContext context , final String type ,
1586
- final IRubyObject value ) {
1587
- RubyClass klass = _ASN1 (context .runtime ).getClass (type );
1588
- final Primitive self = new Primitive (context .runtime , klass );
1589
- if ( value != null ) self .setInstanceVariable ("@value" , value );
1590
- return self ;
1591
- }
1592
-
1593
- static Primitive newEndOfContent (final ThreadContext context ) {
1594
- return newInstance (context , "EndOfContent" , null );
1595
- }
1596
-
1597
1611
/*
1598
1612
private static final Class DERBooleanClass;
1599
1613
static {
@@ -1756,7 +1770,7 @@ static Constructive newInfiniteConstructive(final ThreadContext context,
1756
1770
1757
1771
final RubyArray values = runtime .newArray (value .size ());
1758
1772
for ( final IRubyObject val : value ) values .append (val );
1759
- // values.append( Primitive.newEndOfContent (context) );
1773
+ // values.append( EndOfContent.newInstance (context) );
1760
1774
1761
1775
self .setInstanceVariable ("@tag" , runtime .newFixnum (defaultTag ));
1762
1776
self .setInstanceVariable ("@value" , values );
@@ -1768,11 +1782,9 @@ static Constructive newInfiniteConstructive(final ThreadContext context,
1768
1782
1769
1783
static Constructive setInfiniteLength (final ThreadContext context , final IRubyObject constructive ) {
1770
1784
final Constructive instance = ((Constructive ) constructive );
1771
- final IRubyObject eoc = Primitive .newEndOfContent (context );
1772
1785
final IRubyObject value = instance .value (context );
1773
- if ( value instanceof RubyArray ) ((RubyArray ) value ).append (eoc );
1774
- else value .callMethod (context , "<<" , eoc );
1775
- instance .setInstanceVariable ("@infinite_length" , context .runtime .getTrue ());
1786
+ value .callMethod (context , "<<" , EndOfContent .newInstance (context ));
1787
+ instance .setInstanceVariable ("@indefinite_length" , context .runtime .getTrue ());
1776
1788
return instance ;
1777
1789
}
1778
1790
@@ -1789,7 +1801,7 @@ private boolean isSet() {
1789
1801
}
1790
1802
1791
1803
private boolean isInfiniteLength () {
1792
- return getInstanceVariable ("@infinite_length " ).isTrue ();
1804
+ return getInstanceVariable ("@indefinite_length " ).isTrue ();
1793
1805
}
1794
1806
1795
1807
@ Override
@@ -1838,8 +1850,7 @@ public IRubyObject to_der(final ThreadContext context) {
1838
1850
if ( rawConstructive () ) { // MRI compatibility
1839
1851
if ( ! isInfiniteLength () && ! super .value (context ).isNil () ) {
1840
1852
final Ruby runtime = context .runtime ;
1841
- throw newASN1Error (runtime , "Constructive shall only be used"
1842
- + " with infinite length" );
1853
+ throw newASN1Error (runtime , "Constructive shall only be used with indefinite length" );
1843
1854
}
1844
1855
}
1845
1856
return super .to_der (context );
0 commit comments