Class: R509::ASN1::GeneralNames

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ GeneralNames

Returns a new instance of GeneralNames

Parameters:

  • data (Array, R509::ASN1::GeneralNames) (defaults to: nil)

    Pass an array of hashes to create R509::ASN1::GeneralName objects or an existing R509::ASN1::GeneralNames object



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_namesObject (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

Parameters:

  • asn (OpenSSL::ASN1::ASN1Data)

    Takes ASN.1 data in for parsing GeneralName structures



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

Parameters:

  • hash (Hash)

    A hash with (:tag or :type) and :value keys. Allows you to build GeneralName objects and add them to the GeneralNames 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_namesArray Also known as: dir_names

Returns Array of directoryNames (R509::Subject objects)

Returns:

  • (Array)

    Array of directoryNames (R509::Subject objects)



332
333
334
# File 'lib/r509/asn1.rb', line 332

def directory_names
  @types[:directoryName]
end

#dns_namesArray

Returns Array of dnsName strings

Returns:

  • (Array)

    Array of dnsName strings



315
316
317
# File 'lib/r509/asn1.rb', line 315

def dns_names
  @types[:dNSName]
end

#ip_addressesArray Also known as: ips

Returns Array of IP address strings

Returns:

  • (Array)

    Array of IP address strings



326
327
328
# File 'lib/r509/asn1.rb', line 326

def ip_addresses
  @types[:iPAddress]
end

#rfc_822_namesArray Also known as: email_names

Returns Array of rfc822name strings

Returns:

  • (Array)

    Array of rfc822name strings



309
310
311
# File 'lib/r509/asn1.rb', line 309

def rfc_822_names
  @types[:rfc822Name]
end

#serialize_namesArray

Returns string of serialized names for OpenSSL extension creation

Returns:

  • (Array)

    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_hHash

Returns:

  • (Hash)


300
301
302
# File 'lib/r509/asn1.rb', line 300

def to_h
  self.names.map { |n| n.to_h }
end

#uniform_resource_identifiersArray Also known as: uris

Returns Array of uri strings

Returns:

  • (Array)

    Array of uri strings



320
321
322
# File 'lib/r509/asn1.rb', line 320

def uniform_resource_identifiers
  @types[:uniformResourceIdentifier]
end