@@ -198,7 +198,7 @@ ossl_x509name_initialize_copy(VALUE self, VALUE other)
198198
199199/*
200200 * call-seq:
201- * name.add_entry(oid, value [, type]) => self
201+ * name.add_entry(oid, value [, type], loc: -1, set: 0 ) => self
202202 *
203203 * Adds a new entry with the given _oid_ and _value_ to this name. The _oid_
204204 * is an object identifier defined in ASN.1. Some common OIDs are:
@@ -209,24 +209,39 @@ ossl_x509name_initialize_copy(VALUE self, VALUE other)
209209 * O:: Organization Name
210210 * OU:: Organizational Unit Name
211211 * ST:: State or Province Name
212+ *
213+ * The optional keyword parameters _loc_ and _set_ specify where to insert the
214+ * new attribute. Refer to the manpage of X509_NAME_add_entry(3) for details.
215+ * _loc_ defaults to -1 and _set_ defaults to 0. This appends a single-valued
216+ * RDN to the end.
212217 */
213218static
214219VALUE ossl_x509name_add_entry (int argc , VALUE * argv , VALUE self )
215220{
216221 X509_NAME * name ;
217- VALUE oid , value , type ;
222+ VALUE oid , value , type , opts , kwargs [2 ];
223+ static ID kwargs_ids [2 ];
218224 const char * oid_name ;
225+ int loc = -1 , set = 0 ;
219226
220- rb_scan_args (argc , argv , "21" , & oid , & value , & type );
227+ if (!kwargs_ids [0 ]) {
228+ kwargs_ids [0 ] = rb_intern_const ("loc" );
229+ kwargs_ids [1 ] = rb_intern_const ("set" );
230+ }
231+ rb_scan_args (argc , argv , "21:" , & oid , & value , & type , & opts );
232+ rb_get_kwargs (opts , kwargs_ids , 0 , 2 , kwargs );
221233 oid_name = StringValueCStr (oid );
222234 StringValue (value );
223235 if (NIL_P (type )) type = rb_aref (OBJECT_TYPE_TEMPLATE , oid );
236+ if (kwargs [0 ] != Qundef )
237+ loc = NUM2INT (kwargs [0 ]);
238+ if (kwargs [1 ] != Qundef )
239+ set = NUM2INT (kwargs [1 ]);
224240 GetX509Name (self , name );
225241 if (!X509_NAME_add_entry_by_txt (name , oid_name , NUM2INT (type ),
226- (const unsigned char * )RSTRING_PTR (value ), RSTRING_LENINT (value ), -1 , 0 )) {
227- ossl_raise (eX509NameError , NULL );
228- }
229-
242+ (unsigned char * )RSTRING_PTR (value ),
243+ RSTRING_LENINT (value ), loc , set ))
244+ ossl_raise (eX509NameError , "X509_NAME_add_entry_by_txt" );
230245 return self ;
231246}
232247
0 commit comments