74
74
import static org .jruby .ext .openssl .OpenSSLReal .debug ;
75
75
import static org .jruby .ext .openssl .OpenSSLReal .debugStackTrace ;
76
76
import static org .jruby .ext .openssl .OpenSSLReal .isDebug ;
77
- import static org .jruby .ext .openssl .OpenSSLReal .warn ;
78
77
79
78
/**
80
79
* @author <a href="mailto:[email protected] ">Ola Bini</a>
@@ -254,7 +253,7 @@ else if ( id.equals("2.5.29.37") ) { //extendedKeyUsage
254
253
255
254
ext .setRealOid (objectId );
256
255
ext .setRealValue (value );
257
- ext .setRealCritical (critical .isTrue ());
256
+ ext .setRealCritical (critical .isNil () ? null : critical . isTrue ());
258
257
259
258
return ext ;
260
259
}
@@ -514,28 +513,24 @@ public Extension(Ruby runtime, RubyClass type) {
514
513
515
514
private ASN1ObjectIdentifier oid ;
516
515
private Object value ;
517
- private boolean critical ;
518
-
519
- void setRealOid (ASN1ObjectIdentifier oid ) {
520
- this .oid = oid ;
521
- }
522
-
523
- void setRealValue (Object value ) {
524
- this .value = value ;
525
- }
526
-
527
- void setRealCritical (boolean critical ) {
528
- this .critical = critical ;
529
- }
516
+ private Boolean critical ;
530
517
531
518
ASN1ObjectIdentifier getRealOid () {
532
519
return oid ;
533
520
}
534
521
522
+ void setRealOid (ASN1ObjectIdentifier oid ) {
523
+ this .oid = oid ;
524
+ }
525
+
535
526
Object getRealValue () {
536
527
return value ;
537
528
}
538
529
530
+ void setRealValue (Object value ) {
531
+ this .value = value ;
532
+ }
533
+
539
534
byte [] getRealValueBytes () throws IOException {
540
535
if ( value instanceof RubyString ) {
541
536
return ((RubyString ) value ).getBytes ();
@@ -551,8 +546,20 @@ byte[] getRealValueBytes() throws IOException {
551
546
}
552
547
}
553
548
554
- boolean getRealCritical () {
555
- return critical ;
549
+ boolean isRealCritical () {
550
+ return critical == null ? Boolean .FALSE : critical .booleanValue ();
551
+ }
552
+
553
+ //Boolean getRealCritical() {
554
+ // return critical;
555
+ //}
556
+
557
+ void setRealCritical (boolean critical ) {
558
+ this .critical = Boolean .valueOf (critical );
559
+ }
560
+
561
+ private void setRealCritical (Boolean critical ) {
562
+ this .critical = critical ;
556
563
}
557
564
558
565
@ JRubyMethod (name = "initialize" , rest = true , visibility = Visibility .PRIVATE )
@@ -594,8 +601,11 @@ public IRubyObject oid(final ThreadContext context) {
594
601
595
602
@ JRubyMethod (name ="oid=" )
596
603
public IRubyObject set_oid (final ThreadContext context , IRubyObject arg ) {
597
- warn (context , "WARNING: unimplemented method called: Extension#oid=" );
598
- return false ? arg : context .runtime .getNil ();
604
+ if ( arg instanceof RubyString ) {
605
+ setRealOid ( ASN1 .getObjectIdentifier ( context .runtime , arg .toString () ) );
606
+ return arg ;
607
+ }
608
+ throw context .runtime .newTypeError (arg , context .runtime .getString ());
599
609
}
600
610
601
611
private static final byte [] CA_ = { 'C' ,'A' ,':' };
@@ -807,30 +817,31 @@ else if ( name.getTagNo() == GeneralName.iPAddress ) {
807
817
808
818
@ JRubyMethod (name ="value=" )
809
819
public IRubyObject set_value (final ThreadContext context , IRubyObject arg ) {
810
- //warn(context, "WARNING: unimplemented method called: Extension#value=");
811
- //return false ? arg : context.runtime.getNil();
812
- setRealValue (arg ); return arg ;
820
+ if ( arg instanceof RubyString ) {
821
+ setRealValue (arg ); return arg ;
822
+ }
823
+ throw context .runtime .newTypeError (arg , context .runtime .getString ());
813
824
}
814
825
815
826
@ JRubyMethod (name ="critical?" )
816
827
public IRubyObject critical_p () {
817
- return getRuntime ().newBoolean (critical );
828
+ return getRuntime ().newBoolean ( isRealCritical () );
818
829
}
819
830
820
831
@ JRubyMethod (name ="critical=" )
821
832
public IRubyObject set_critical (final ThreadContext context , IRubyObject arg ) {
822
- //warn(context, "WARNING: unimplemented method called: Extension#critical=");
823
- //return false ? arg : context.runtime.getNil();
824
- setRealCritical (arg .isTrue ()); return arg ;
833
+ setRealCritical ( arg .isTrue () ); return arg ;
825
834
}
826
835
827
836
@ JRubyMethod
828
837
public IRubyObject to_der () {
829
838
final ASN1EncodableVector vec = new ASN1EncodableVector ();
830
839
try {
831
- vec .add (getRealOid ());
832
- vec .add (getRealCritical () ? DERBoolean .TRUE : DERBoolean .FALSE );
833
- vec .add (new DEROctetString (getRealValueBytes ()));
840
+ vec .add ( getRealOid () );
841
+ if ( critical != null ) { // NOTE: likely a hack Boolean.FALSE should also get skipped
842
+ vec .add (critical .booleanValue () ? DERBoolean .TRUE : DERBoolean .FALSE );
843
+ }
844
+ vec .add ( new DEROctetString (getRealValueBytes ()) );
834
845
return RubyString .newString (getRuntime (), new DLSequence (vec ).getEncoded (ASN1Encoding .DER ));
835
846
}
836
847
catch (IOException e ) {
0 commit comments