class CertificateAuthority::DistinguishedName

Attributes

c[RW]
c=[RW]
cn[RW]
cn=[RW]
common_name[RW]
country[RW]
emailAddress[RW]
emailAddress=[RW]
email_address[RW]
l[RW]
l=[RW]
locality[RW]
o[RW]
o=[RW]
organization[RW]
organizational_unit[RW]
ou[RW]
ou=[RW]
s[RW]
serialNumber[RW]
serialNumber=[RW]
serial_number[RW]
st=[RW]
state[RW]

Public Class Methods

from_openssl(openssl_name) click to toggle source
# File vendor/certificate_authority/lib/certificate_authority/distinguished_name.rb, line 64
def self.from_openssl openssl_name
  unless openssl_name.is_a? OpenSSL::X509::Name
    raise "Argument must be a OpenSSL::X509::Name"
  end

  WrappedDistinguishedName.new(openssl_name)
end

Public Instance Methods

==(other) click to toggle source
# File vendor/certificate_authority/lib/certificate_authority/distinguished_name.rb, line 59
def ==(other)
  # Use the established OpenSSL comparison
  self.to_x509_name() == other.to_x509_name()
end
to_x509_name() click to toggle source
# File vendor/certificate_authority/lib/certificate_authority/distinguished_name.rb, line 43
def to_x509_name
  raise "Invalid Distinguished Name" unless valid?

  # NB: the capitalization in the strings counts
  name = OpenSSL::X509::Name.new
  name.add_entry("serialNumber", serial_number) unless serial_number.blank?
  name.add_entry("C", country) unless country.blank?
  name.add_entry("ST", state) unless state.blank?
  name.add_entry("L", locality) unless locality.blank?
  name.add_entry("O", organization) unless organization.blank?
  name.add_entry("OU", organizational_unit) unless organizational_unit.blank?
  name.add_entry("CN", common_name)
  name.add_entry("emailAddress", email_address) unless email_address.blank?
  name
end
validate() click to toggle source
# File vendor/certificate_authority/lib/certificate_authority/distinguished_name.rb, line 5
def validate
  if self.common_name.nil? || self.common_name.empty?
    errors.add :common_name, 'cannot be blank'
  end
end