@@ -50,20 +50,20 @@ def ==(other)
50
50
to_der == other . to_der
51
51
end
52
52
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
67
67
68
68
module Helpers
69
69
def find_extension ( oid )
@@ -187,17 +187,17 @@ def ocsp_uris
187
187
188
188
private
189
189
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?
198
193
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"
200
197
end
198
+
199
+ aia_asn1
200
+ end
201
201
end
202
202
end
203
203
@@ -265,7 +265,7 @@ def scan(dn)
265
265
next
266
266
elsif remain . length > 2 && remain [ 0 ] == ?+
267
267
raise OpenSSL ::X509 ::NameError ,
268
- "multi-valued RDN is not supported: #{ dn } "
268
+ "multi-valued RDN is not supported: #{ dn } "
269
269
elsif remain . empty?
270
270
break
271
271
end
@@ -279,11 +279,29 @@ def scan(dn)
279
279
end
280
280
281
281
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.
282
286
def parse_rfc2253 ( str , template = OBJECT_TYPE_TEMPLATE )
283
287
ary = OpenSSL ::X509 ::Name ::RFC2253DN . scan ( str )
284
288
self . new ( ary , template )
285
289
end
286
290
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.
287
305
def parse_openssl ( str , template = OBJECT_TYPE_TEMPLATE )
288
306
if str . start_with? ( "/" )
289
307
# /A=B/C=D format
@@ -338,6 +356,10 @@ def pretty_print(q)
338
356
q . text 'not_after=' ; q . pp self . not_after
339
357
}
340
358
end
359
+
360
+ def self . load_file ( path )
361
+ load ( File . binread ( path ) )
362
+ end
341
363
end
342
364
343
365
class CRL
0 commit comments