Class: CertificateAuthority::DistinguishedName
- Inherits:
-
Object
- Object
- CertificateAuthority::DistinguishedName
- Includes:
- Validations
- Defined in:
- lib/certificate_authority/distinguished_name.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#common_name ⇒ Object
(also: #cn)
Returns the value of attribute common_name.
-
#country ⇒ Object
(also: #c)
Returns the value of attribute country.
-
#email_address ⇒ Object
(also: #emailAddress)
Returns the value of attribute email_address.
-
#locality ⇒ Object
(also: #l)
Returns the value of attribute locality.
-
#organization ⇒ Object
(also: #o)
Returns the value of attribute organization.
-
#organizational_unit ⇒ Object
(also: #ou)
Returns the value of attribute organizational_unit.
-
#serial_number ⇒ Object
(also: #serialNumber)
Returns the value of attribute serial_number.
-
#state ⇒ Object
(also: #s)
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Validations
Instance Attribute Details
#common_name ⇒ Object Also known as: cn
Returns the value of attribute common_name.
11 12 13 |
# File 'lib/certificate_authority/distinguished_name.rb', line 11 def common_name @common_name end |
#country ⇒ Object Also known as: c
Returns the value of attribute country.
23 24 25 |
# File 'lib/certificate_authority/distinguished_name.rb', line 23 def country @country end |
#email_address ⇒ Object Also known as: emailAddress
Returns the value of attribute email_address.
35 36 37 |
# File 'lib/certificate_authority/distinguished_name.rb', line 35 def email_address @email_address end |
#locality ⇒ Object Also known as: l
Returns the value of attribute locality.
15 16 17 |
# File 'lib/certificate_authority/distinguished_name.rb', line 15 def locality @locality end |
#organization ⇒ Object Also known as: o
Returns the value of attribute organization.
27 28 29 |
# File 'lib/certificate_authority/distinguished_name.rb', line 27 def organization @organization end |
#organizational_unit ⇒ Object Also known as: ou
Returns the value of attribute organizational_unit.
31 32 33 |
# File 'lib/certificate_authority/distinguished_name.rb', line 31 def organizational_unit @organizational_unit end |
#serial_number ⇒ Object Also known as: serialNumber
Returns the value of attribute serial_number.
39 40 41 |
# File 'lib/certificate_authority/distinguished_name.rb', line 39 def serial_number @serial_number end |
#state ⇒ Object Also known as: s
Returns the value of attribute state.
19 20 21 |
# File 'lib/certificate_authority/distinguished_name.rb', line 19 def state @state end |
Class Method Details
.from_openssl(openssl_name) ⇒ Object
64 65 66 67 68 69 70 |
# File '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 |
Instance Method Details
#==(other) ⇒ Object
59 60 61 62 |
# File '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 ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File '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 ⇒ Object
5 6 7 8 9 |
# File '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 |