class R509::ASN1::GeneralNames

object to hold parsed sequences of generalnames these structures are used in SubjectAlternativeName, AuthorityInfoAccess, CRLDistributionPoints, etc

Attributes

names[R]
ordered_names[R]

Public Class Methods

new(data = nil) click to toggle source

@param data [Array,R509::ASN1::GeneralNames] Pass an array of hashes to create R509::ASN1::GeneralName objects or an existing R509::ASN1::GeneralNames object

# 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

Public Instance Methods

add_item(asn) click to toggle source

@param [OpenSSL::ASN1::ASN1Data] asn Takes ASN.1 data in for parsing GeneralName structures

# 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) click to toggle source

@param [Hash] hash A hash with (:tag or :type) and :value keys. Allows you to build GeneralName objects and add

them to the GeneralNames object
# 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
dir_names()
Alias for: directory_names
directory_names() click to toggle source

@return [Array] Array of directoryNames (R509::Subject objects)

# File lib/r509/asn1.rb, line 332
def directory_names
  @types[:directoryName]
end
Also aliased as: dir_names
dns_names() click to toggle source

@return [Array] Array of dnsName strings

# File lib/r509/asn1.rb, line 315
def dns_names
  @types[:dNSName]
end
email_names()
Alias for: rfc_822_names
ip_addresses() click to toggle source

@return [Array] Array of IP address strings

# File lib/r509/asn1.rb, line 326
def ip_addresses
  @types[:iPAddress]
end
Also aliased as: ips
ips()
Alias for: ip_addresses
rfc_822_names() click to toggle source

@return [Array] Array of rfc822name strings

# File lib/r509/asn1.rb, line 309
def rfc_822_names
  @types[:rfc822Name]
end
Also aliased as: email_names
serialize_names() click to toggle source

@return [Array] string of serialized names for OpenSSL extension creation

# 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() click to toggle source

@return [Hash]

# File lib/r509/asn1.rb, line 300
def to_h
  self.names.map { |n| n.to_h }
end
uniform_resource_identifiers() click to toggle source

@return [Array] Array of uri strings

# File lib/r509/asn1.rb, line 320
def uniform_resource_identifiers
  @types[:uniformResourceIdentifier]
end
Also aliased as: uris
uris()