@@ -50,20 +50,20 @@ def ==(other)
5050 to_der == other . to_der
5151 end
5252
53- # def to_s # "oid = critical, value"
54- # str = self.oid
55- # str << " = "
56- # str << "critical, " if self.critical?
57- # str << self.value.gsub(/\n/, ", ")
58- # end
59- #
60- # def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
61- # {"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
62- # end
63- #
64- # def to_a
65- # [ self.oid, self.value, self.critical? ]
66- # end
53+ def to_s # "oid = critical, value"
54+ str = self . oid
55+ str << " = "
56+ str << "critical, " if self . critical?
57+ str << self . value . gsub ( /\n / , ", " )
58+ end
59+
60+ def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
61+ { "oid" => self . oid , "value" => self . value , "critical" => self . critical? }
62+ end
63+
64+ def to_a
65+ [ self . oid , self . value , self . critical? ]
66+ end
6767
6868 module Helpers
6969 def find_extension ( oid )
@@ -187,17 +187,17 @@ def ocsp_uris
187187
188188 private
189189
190- def parse_aia_asn1
191- ext = find_extension ( "authorityInfoAccess" )
192- return nil if ext . nil?
193-
194- aia_asn1 = ASN1 . decode ( ext . value_der )
195- if ext . critical? || aia_asn1 . tag_class != :UNIVERSAL || aia_asn1 . tag != ASN1 ::SEQUENCE
196- raise ASN1 ::ASN1Error , "invalid extension"
197- end
190+ def parse_aia_asn1
191+ ext = find_extension ( "authorityInfoAccess" )
192+ return nil if ext . nil?
198193
199- aia_asn1
194+ aia_asn1 = ASN1 . decode ( ext . value_der )
195+ if ext . critical? || aia_asn1 . tag_class != :UNIVERSAL || aia_asn1 . tag != ASN1 ::SEQUENCE
196+ raise ASN1 ::ASN1Error , "invalid extension"
200197 end
198+
199+ aia_asn1
200+ end
201201 end
202202 end
203203
@@ -265,7 +265,7 @@ def scan(dn)
265265 next
266266 elsif remain . length > 2 && remain [ 0 ] == ?+
267267 raise OpenSSL ::X509 ::NameError ,
268- "multi-valued RDN is not supported: #{ dn } "
268+ "multi-valued RDN is not supported: #{ dn } "
269269 elsif remain . empty?
270270 break
271271 end
@@ -279,11 +279,29 @@ def scan(dn)
279279 end
280280
281281 class << self
282+ # Parses the UTF-8 string representation of a distinguished name,
283+ # according to RFC 2253.
284+ #
285+ # See also #to_utf8 for the opposite operation.
282286 def parse_rfc2253 ( str , template = OBJECT_TYPE_TEMPLATE )
283287 ary = OpenSSL ::X509 ::Name ::RFC2253DN . scan ( str )
284288 self . new ( ary , template )
285289 end
286290
291+ # Parses the string representation of a distinguished name. Two
292+ # different forms are supported:
293+ #
294+ # - \OpenSSL format (<tt>X509_NAME_oneline()</tt>) used by
295+ # <tt>#to_s</tt>. For example: <tt>/DC=com/DC=example/CN=nobody</tt>
296+ # - \OpenSSL format (<tt>X509_NAME_print()</tt>)
297+ # used by <tt>#to_s(OpenSSL::X509::Name::COMPAT)</tt>. For example:
298+ # <tt>DC=com, DC=example, CN=nobody</tt>
299+ #
300+ # Neither of them is standardized and has quirks and inconsistencies
301+ # in handling of escaped characters or multi-valued RDNs.
302+ #
303+ # Use of this method is discouraged in new applications. See
304+ # Name.parse_rfc2253 and #to_utf8 for the alternative.
287305 def parse_openssl ( str , template = OBJECT_TYPE_TEMPLATE )
288306 if str . start_with? ( "/" )
289307 # /A=B/C=D format
@@ -338,6 +356,10 @@ def pretty_print(q)
338356 q . text 'not_after=' ; q . pp self . not_after
339357 }
340358 end
359+
360+ def self . load_file ( path )
361+ load ( File . binread ( path ) )
362+ end
341363 end
342364
343365 class CRL
0 commit comments