4444import org .bouncycastle .asn1 .ASN1ObjectIdentifier ;
4545import org .bouncycastle .asn1 .pkcs .Attribute ;
4646import org .bouncycastle .asn1 .x500 .X500Name ;
47+ import org .bouncycastle .asn1 .x509 .AlgorithmIdentifier ;
48+ import org .bouncycastle .operator .DefaultSignatureNameFinder ;
4749
4850import org .jruby .Ruby ;
4951import org .jruby .RubyArray ;
5355import org .jruby .RubyString ;
5456import org .jruby .anno .JRubyMethod ;
5557import org .jruby .exceptions .RaiseException ;
58+ import org .jruby .ext .openssl .impl .ASN1Registry ;
5659import org .jruby .ext .openssl .x509store .PEMInputOutput ;
5760import org .jruby .runtime .Arity ;
5861import org .jruby .runtime .ThreadContext ;
@@ -91,7 +94,7 @@ static RubyClass _RequestError(final Ruby runtime) {
9194
9295 public X509Request (Ruby runtime , RubyClass type ) {
9396 super (runtime , type );
94- attributes = new ArrayList <X509Attribute >(4 );
97+ attributes = new ArrayList <>(4 );
9598 }
9699
97100 @ JRubyMethod (name = "initialize" , rest = true , visibility = Visibility .PRIVATE )
@@ -286,8 +289,10 @@ public IRubyObject set_subject(final IRubyObject val) {
286289
287290 @ JRubyMethod
288291 public IRubyObject signature_algorithm (final ThreadContext context ) {
289- warn (context , "WARNING: unimplemented method called: OpenSSL::X509::Request#signature_algorithm" );
290- return context .runtime .getNil ();
292+ AlgorithmIdentifier signatureAlgId = request == null ? null : request .getSignatureAlgorithm ();
293+ if (signatureAlgId == null ) return context .runtime .newString ("NULL" );
294+ final String name = ASN1Registry .o2a (signatureAlgId .getAlgorithm ());
295+ return context .runtime .newString (name == null ? "" : name );
291296 }
292297
293298 @ JRubyMethod
@@ -316,7 +321,8 @@ public IRubyObject sign(final ThreadContext context,
316321
317322 final String digAlg = ((Digest ) digest ).getShortAlgorithm ();
318323 try {
319- request = null ; getRequest ().sign ( privateKey , digAlg );
324+ request = null ;
325+ getRequest ().sign ( privateKey , digAlg );
320326 }
321327 catch (InvalidKeyException e ) {
322328 debug (runtime , "X509Request#sign invalid key:" , e );
@@ -330,15 +336,14 @@ public IRubyObject sign(final ThreadContext context,
330336 }
331337
332338 private List <Attribute > newAttributesImpl (final ThreadContext context ) {
333- ArrayList <Attribute > attrs = new ArrayList <Attribute >(attributes .size ());
339+ ArrayList <Attribute > attrs = new ArrayList <>(attributes .size ());
334340 for ( X509Attribute attribute : attributes ) {
335341 attrs .add ( newAttributeImpl (context , attribute ) );
336342 }
337343 return attrs ;
338344 }
339345
340- private Attribute newAttributeImpl (final ThreadContext context ,
341- final X509Attribute attribute ) {
346+ private static Attribute newAttributeImpl (final ThreadContext context , final X509Attribute attribute ) {
342347 return Attribute .getInstance ( attribute .toASN1 ( context ) );
343348 }
344349
@@ -372,7 +377,7 @@ public IRubyObject attributes() {
372377 return getRuntime ().newArray (attributes );
373378 }
374379
375- @ JRubyMethod (name = "attributes=" )
380+ @ JRubyMethod (name = "attributes=" )
376381 public IRubyObject set_attributes (final ThreadContext context ,final IRubyObject attributes ) {
377382 this .attributes .clear ();
378383 final RubyArray attrs = (RubyArray ) attributes ;
0 commit comments