Class: R509::ASN1::GeneralNames
- Inherits:
-
Object
- Object
- R509::ASN1::GeneralNames
- Includes:
- Cert::Extensions::ValidationMixin
- Defined in:
- lib/r509/asn1.rb
Overview
object to hold parsed sequences of generalnames these structures are used in SubjectAlternativeName, AuthorityInfoAccess, CRLDistributionPoints, etc
Instance Attribute Summary collapse
-
#ordered_names ⇒ Object
(also: #names)
readonly
Returns the value of attribute ordered_names.
Instance Method Summary collapse
- #add_item(asn) ⇒ Object
- #create_item(hash) ⇒ Object
-
#directory_names ⇒ Array
(also: #dir_names)
Array of directoryNames (R509::Subject objects).
-
#dns_names ⇒ Array
Array of dnsName strings.
-
#initialize(data = nil) ⇒ GeneralNames
constructor
A new instance of GeneralNames.
-
#ip_addresses ⇒ Array
(also: #ips)
Array of IP address strings.
-
#rfc_822_names ⇒ Array
(also: #email_names)
Array of rfc822name strings.
-
#serialize_names ⇒ Array
String of serialized names for OpenSSL extension creation.
- #to_h ⇒ Hash
-
#uniform_resource_identifiers ⇒ Array
(also: #uris)
Array of uri strings.
Constructor Details
#initialize(data = nil) ⇒ GeneralNames
Returns a new instance of GeneralNames
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/r509/asn1.rb', line 251 def initialize(data = nil) @types = { :otherName => [], # unimplemented :rfc822Name => [], :dNSName => [], :x400Address => [], # unimplemented :directoryName => [], :ediPartyName => [], # unimplemented :uniformResourceIdentifier => [], :iPAddress => [], :registeredID => [] # unimplemented } @ordered_names = [] unless data.nil? if data.is_a?(self.class) data.names.each { |n| add_item(n) } else validate_general_name_hash_array(data) data.each do |n| create_item(n) end end end end |
Instance Attribute Details
#ordered_names ⇒ Object (readonly) Also known as: names
Returns the value of attribute ordered_names
248 249 250 |
# File 'lib/r509/asn1.rb', line 248 def ordered_names @ordered_names end |
Instance Method Details
#add_item(asn) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/r509/asn1.rb', line 277 def add_item(asn) # map general names into our hash of arrays if asn.is_a?(R509::ASN1::GeneralName) @ordered_names << asn @types[asn.type] << asn.value else gn = R509::ASN1::GeneralName.new(asn) @ordered_names << gn @types[gn.type] << gn.value end end |
#create_item(hash) ⇒ Object
291 292 293 294 295 296 297 |
# File 'lib/r509/asn1.rb', line 291 def create_item(hash) if !hash.respond_to?(:has_key?) || (!hash.key?(:tag) && !hash.key?(:type)) || !hash.key?(:value) raise ArgumentError, "Must be a hash with (:tag or :type) and :value nodes" end gn = R509::ASN1::GeneralName.new(:tag => hash[:tag], :type => hash[:type], :value => hash[:value]) add_item(gn) end |
#directory_names ⇒ Array Also known as: dir_names
Returns Array of directoryNames (R509::Subject objects)
332 333 334 |
# File 'lib/r509/asn1.rb', line 332 def directory_names @types[:directoryName] end |
#dns_names ⇒ Array
Returns Array of dnsName strings
315 316 317 |
# File 'lib/r509/asn1.rb', line 315 def dns_names @types[:dNSName] end |
#ip_addresses ⇒ Array Also known as: ips
Returns Array of IP address strings
326 327 328 |
# File 'lib/r509/asn1.rb', line 326 def ip_addresses @types[:iPAddress] end |
#rfc_822_names ⇒ Array Also known as: email_names
Returns Array of rfc822name strings
309 310 311 |
# File 'lib/r509/asn1.rb', line 309 def rfc_822_names @types[:rfc822Name] end |
#serialize_names ⇒ Array
Returns string of serialized names for OpenSSL extension creation
338 339 340 341 342 343 344 345 346 347 |
# File 'lib/r509/asn1.rb', line 338 def serialize_names confs = [] extension_strings = [] @ordered_names.each do |item| data = item.serialize_name confs << data[:conf] extension_strings << data[:extension_string] end { :conf => confs.join("\n"), :extension_string => extension_strings.join(",") } end |
#to_h ⇒ Hash
300 301 302 |
# File 'lib/r509/asn1.rb', line 300 def to_h self.names.map { |n| n.to_h } end |
#uniform_resource_identifiers ⇒ Array Also known as: uris
Returns Array of uri strings
320 321 322 |
# File 'lib/r509/asn1.rb', line 320 def uniform_resource_identifiers @types[:uniformResourceIdentifier] end |