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 Method Summary (collapse)

Constructor Details

- (GeneralNames) initialize(data = nil)

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



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/r509/asn1.rb', line 235

def initialize(data=nil)
  @types = {
    :otherName => [], # unimplemented
    :rfc822Name => [],
    :dNSName => [],
    :x400Address => [], # unimplemented
    :directoryName => [],
    :ediPartyName => [], # unimplemented
    :uniformResourceIdentifier => [],
    :iPAddress => [],
    :registeredID => [] # unimplemented
  }
  @ordered_names = []
  if not data.nil?
    if data.kind_of?(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 Method Details

- (Object) add_item(asn)

Parameters:

  • asn (OpenSSL::ASN1::ASN1Data)

    Takes ASN.1 data in for parsing GeneralName structures



261
262
263
264
265
266
267
268
269
270
271
# File 'lib/r509/asn1.rb', line 261

def add_item(asn)
  # map general names into our hash of arrays
  if asn.kind_of?(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

- (Object) create_item(hash)

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



275
276
277
278
279
280
281
# File 'lib/r509/asn1.rb', line 275

def create_item(hash)
  if not hash.respond_to?(:has_key?) or (not hash.has_key?(:tag) and not hash.has_key?(:type)) or not hash.has_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

- (Array) directory_names Also known as: dir_names

Array of directoryNames (R509::Subject objects)

Returns:

  • (Array)

    Array of directoryNames (R509::Subject objects)



318
319
320
# File 'lib/r509/asn1.rb', line 318

def directory_names
  @types[:directoryName]
end

- (Array) dns_names

Array of dnsName strings

Returns:

  • (Array)

    Array of dnsName strings



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

def dns_names
  @types[:dNSName]
end

- (Array) ip_addresses Also known as: ips

Array of IP address strings

Returns:

  • (Array)

    Array of IP address strings



312
313
314
# File 'lib/r509/asn1.rb', line 312

def ip_addresses
  @types[:iPAddress]
end

- (Array) names

order found in the extension

Returns:

  • (Array)

    array of GeneralName objects



290
291
292
# File 'lib/r509/asn1.rb', line 290

def names
  @ordered_names
end

- (Array) rfc_822_names Also known as: email_names

Array of rfc822name strings

Returns:

  • (Array)

    Array of rfc822name strings



295
296
297
# File 'lib/r509/asn1.rb', line 295

def rfc_822_names
  @types[:rfc822Name]
end

- (Array) serialize_names

String of serialized names for OpenSSL extension creation

Returns:

  • (Array)

    string of serialized names for OpenSSL extension creation



324
325
326
327
328
329
330
331
332
333
# File 'lib/r509/asn1.rb', line 324

def serialize_names
  confs = []
  extension_strings = []
  @ordered_names.each { |item|
    data = item.serialize_name
    confs << data[:conf]
    extension_strings << data[:extension_string]
  }
  { :conf => confs.join("\n"), :extension_string => extension_strings.join(",") }
end

- (Hash) to_h

Returns:

  • (Hash)


284
285
286
# File 'lib/r509/asn1.rb', line 284

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

- (Array) uniform_resource_identifiers Also known as: uris

Array of uri strings

Returns:

  • (Array)

    Array of uri strings



306
307
308
# File 'lib/r509/asn1.rb', line 306

def uniform_resource_identifiers
  @types[:uniformResourceIdentifier]
end