Class: CertificateAuthority::DistinguishedName
- Inherits:
-
Object
- Object
- CertificateAuthority::DistinguishedName
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/certificate_authority/distinguished_name.rb
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.
-
#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.
-
#state ⇒ Object
(also: #s)
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#common_name ⇒ Object Also known as: cn
Returns the value of attribute common_name.
7 8 9 |
# File 'lib/certificate_authority/distinguished_name.rb', line 7 def common_name @common_name end |
#country ⇒ Object Also known as: c
Returns the value of attribute country.
16 17 18 |
# File 'lib/certificate_authority/distinguished_name.rb', line 16 def country @country end |
#locality ⇒ Object Also known as: l
Returns the value of attribute locality.
10 11 12 |
# File 'lib/certificate_authority/distinguished_name.rb', line 10 def locality @locality end |
#organization ⇒ Object Also known as: o
Returns the value of attribute organization.
19 20 21 |
# File 'lib/certificate_authority/distinguished_name.rb', line 19 def organization @organization end |
#organizational_unit ⇒ Object Also known as: ou
Returns the value of attribute organizational_unit.
22 23 24 |
# File 'lib/certificate_authority/distinguished_name.rb', line 22 def organizational_unit @organizational_unit end |
#state ⇒ Object Also known as: s
Returns the value of attribute state.
13 14 15 |
# File 'lib/certificate_authority/distinguished_name.rb', line 13 def state @state end |
Class Method Details
.from_openssl(openssl_name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/certificate_authority/distinguished_name.rb', line 39 def self.from_openssl openssl_name unless openssl_name.is_a? OpenSSL::X509::Name raise "Argument must be a OpenSSL::X509::Name" end name = DistinguishedName.new openssl_name.to_a.each do |k,v| case k when "CN" then name.common_name = v when "L" then name.locality = v when "ST" then name.state = v when "C" then name.country = v when "O" then name.organization = v when "OU" then name.organizational_unit = v end end name end |
Instance Method Details
#to_x509_name ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/certificate_authority/distinguished_name.rb', line 25 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("CN", common_name) name.add_entry("O", organization) unless organization.blank? name.add_entry("OU", organizational_unit) unless organizational_unit.blank? name.add_entry("ST", state) unless state.blank? name.add_entry("L", locality) unless locality.blank? name.add_entry("C", country) unless country.blank? name end |